Skip to content

Commit

Permalink
Update chart versions automatically (#259)
Browse files Browse the repository at this point in the history
* Update chart versions automatically

* auto patch increment

Co-authored-by: ras-rm-pr-bot <[email protected]>
  • Loading branch information
mfcrocker and ras-rm-pr-bot authored Jul 22, 2021
1 parent 604edd5 commit 19bb97b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
63 changes: 38 additions & 25 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,13 @@ jobs:
- name: template helm
run: |
helm template $CHART_DIRECTORY
- name: package helm
run: |
echo HELM_VERSION=$(grep -E "version:\s+" $CHART_DIRECTORY/Chart.yaml | cut -d" " -f2 | sed -r 's/"//g') >> $GITHUB_ENV
helm dep up $CHART_DIRECTORY
helm package $CHART_DIRECTORY
- name: Publish dev Chart
if: github.ref != 'refs/heads/main'
run: |
mv $IMAGE-${{ env.HELM_VERSION }}.tgz $IMAGE-latest.tgz
gsutil cp $IMAGE-*.tgz gs://$ARTIFACT_BUCKET/$IMAGE/
- name: Set current tag
if: github.ref != 'refs/heads/main'
id: vars
run: |
git fetch --tags
echo ::set-output name=tag::$(git describe --tags --abbrev=0)
- name: update version
- name: update versions
if: github.ref != 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
Expand All @@ -108,32 +94,47 @@ jobs:
run: |
echo "Current git version: ${{ steps.vars.outputs.tag }}"
export APP_VERSION=$(grep -E "appVersion:\s+" $CHART_DIRECTORY/Chart.yaml | cut -d" " -f2 | sed -r 's/"//g')
export CHART_VERSION=$(grep -E "version:\s+" $CHART_DIRECTORY/Chart.yaml | cut -d" " -f2 | sed -r 's/"//g')
echo "appVersion: $APP_VERSION"
echo "chartVersion: $CHART_VERSION"
if [ ${{ steps.vars.outputs.tag }} = $APP_VERSION ]; then
echo "versions match, incrementing patch"
OLD_PATCH=$(echo ${{ steps.vars.outputs.tag }} | cut -d '.' -f3)
echo "OLD patch: $OLD_PATCH"
NEW_PATCH=$(($OLD_PATCH + 1))
echo "New patch version: $NEW_PATCH"
NEW_VERSION="appVersion: $(echo ${{ steps.vars.outputs.tag }} | sed -e "s/[0-9]\{1,3\}/$NEW_PATCH/3")"
echo "new version: $NEW_VERSION"
sed -i -e "s/appVersion: .*/$NEW_VERSION/g" $CHART_DIRECTORY/Chart.yaml
NEW_APP_VERSION="appVersion: $(echo ${{ steps.vars.outputs.tag }} | sed -e "s/[0-9]\{1,3\}/$NEW_PATCH/3")"
NEW_CHART_VERSION="version: $(echo ${{ steps.vars.outputs.tag }} | sed -e "s/[0-9]\{1,3\}/$NEW_PATCH/3")"
sed -i -e "s/appVersion: .*/$NEW_APP_VERSION/g" $CHART_DIRECTORY/Chart.yaml
sed -i -e "s/version: .*/$NEW_CHART_VERSION/g" $CHART_DIRECTORY/Chart.yaml
git config user.name "ras-rm-pr-bot"
git config user.email "${{ secrets.BOT_EMAIL }}"
git remote set-url origin https://ras-rm-pr-bot:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
git remote update
git fetch
git checkout ${{ github.head_ref }}
git add $CHART_DIRECTORY/Chart.yaml
git commit -m "$COMMIT_MSG"
git push
git push
else
echo "git version and appVersion do not not match"
echo "Using current appVersion: $APP_VERSION"
if [ $APP_VERSION != $CHART_VERSION ]; then
echo "app version manually updated without updating chart version"
NEW_CHART_VERSION="version: $APP_VERSION"
echo "replacing version with $NEW_CHART_VERSION"
sed -i -e "s/version: .*/$NEW_CHART_VERSION/g" $CHART_DIRECTORY/Chart.yaml
git config user.name "ras-rm-pr-bot"
git config user.email "${{ secrets.BOT_EMAIL }}"
git remote set-url origin https://ras-rm-pr-bot:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
git remote update
git fetch
git checkout ${{ github.head_ref }}
git add $CHART_DIRECTORY/Chart.yaml
git commit -m "$COMMIT_MSG"
git push
else
echo "git version different to chart/app versions and chart/app versions match"
echo "Using current version: $APP_VERSION"
fi
fi
- name: output new version
Expand All @@ -142,6 +143,18 @@ jobs:
shell: bash
run: |
echo ::set-output name=version::$(grep -E "appVersion:\s+" $CHART_DIRECTORY/Chart.yaml | cut -d" " -f2 | sed -r 's/"//g')
- name: package helm
run: |
echo HELM_VERSION=$(grep -E "version:\s+" $CHART_DIRECTORY/Chart.yaml | cut -d" " -f2 | sed -r 's/"//g') >> $GITHUB_ENV
helm dep up $CHART_DIRECTORY
helm package $CHART_DIRECTORY
- name: Publish dev Chart
if: github.ref != 'refs/heads/main'
run: |
mv $IMAGE-${{ env.HELM_VERSION }}.tgz $IMAGE-latest.tgz
gsutil cp $IMAGE-*.tgz gs://$ARTIFACT_BUCKET/$IMAGE/
- name: Build Release Image
if: github.ref == 'refs/heads/main'
Expand Down
4 changes: 2 additions & 2 deletions _infra/helm/collection-exercise/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 1.4.0
version: 11.1.8

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.

appVersion: 11.1.7
appVersion: 11.1.8

0 comments on commit 19bb97b

Please sign in to comment.