Skip to content

Commit

Permalink
gh actions: add automated version bumper
Browse files Browse the repository at this point in the history
  • Loading branch information
sonroyaalmerol authored May 16, 2024
1 parent 288b619 commit 7ba65a1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/helm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,49 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Update Chart AppVersion
env:
ACTION_TRIGGER: ${{github.event_name}}
run: |
CHART_PATH="charts/sogo/Chart.yaml"
# Update chart version
# Extract the current version from the file
CURRENT_VERSION=$(grep -Eo 'version: [0-9]+\.[0-9]+\.[0-9]+' "$CHART_PATH" | awk '{print $2}')
# If no version is found, exit with an error
if [ -z "$CURRENT_VERSION" ]; then
echo "No version found in the file!"
exit 0
fi
# Split the version into major, minor, and patch
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR=${VERSION_PARTS[0]}
MINOR=${VERSION_PARTS[1]}
PATCH=${VERSION_PARTS[2]}
if [ "$ACTION_TRIGGER" = "workflow_dispatch" ]; then
# Increment the version
PATCH=$((PATCH + 1))
else
MINOR=$((MINOR + 1))
fi
# Form the new version
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
# Update the file with the new version
sed -i 's/version: '"$CURRENT_VERSION"'/version: '"$NEW_VERSION"'/' "$CHART_PATH"
- name: Commit files and push it
run: |
git add .
git commit -m "chore: bump chart version"
git push
# See https://github.com/helm/chart-releaser-action/issues/6
- name: Set up Helm
uses: azure/[email protected]
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Docker - GHCR Login
uses: docker/login-action@v3
with:
Expand Down Expand Up @@ -115,6 +120,22 @@ jobs:
generate_release_notes: true
body: |
SOGo Update: https://github.com/Alinto/sogo/releases/tag/SOGo-${{ needs.check_versions.outputs.base_version }}
- name: Update Chart AppVersion
env:
APP_VERSION: ${{needs.check_versions.outputs.base_version}}
DOCKER_REVISION: ${{needs.check_versions.outputs.next_revision}}
run: |
CHART_PATH="charts/sogo/Chart.yaml"
sed -i 's|sonroyaalmerol/docker-sogo:[^ ]*|sonroyaalmerol/docker-sogo:'"$APP_VERSION"'-'"$DOCKER_REVISION"'|g' "$CHART_PATH"
sed -i 's/^appVersion:.*$/appVersion: '"$APP_VERSION"'/' "$CHART_PATH"
- name: Commit files and push it
run: |
git add .
git commit -m "chore: bump container versions in chart"
git push
release_helm:
needs: release
Expand Down

0 comments on commit 7ba65a1

Please sign in to comment.