diff --git a/.github/workflows/auto-update.yml b/.github/workflows/auto-update.yml index 14039c67a..93f5558f6 100644 --- a/.github/workflows/auto-update.yml +++ b/.github/workflows/auto-update.yml @@ -11,6 +11,7 @@ on: - cron: '0 0 * * *' jobs: + auto-bump-chart: runs-on: ubuntu-latest @@ -18,18 +19,34 @@ jobs: - uses: actions/checkout@v3 - - name: Update chart + - name: Compare Tags + run: | + chmod +x hack/update/get-latest-chart-version.sh + latest=$(hack/update/get-latest-chart-version.sh) + current=$(yq '.version' ./module-chart/chart/Chart.yaml) + if [[ $latest == $current ]]; then + echo "version are the same: $latest=$current" + echo "CONTINUE_JOB=false" >> $GITHUB_ENV + else + echo "version update from $current to $latest" + echo "CONTINUE_JOB=true" >> $GITHUB_ENV + echo "TAG=${latest}" >> $GITHUB_ENV + fi + + - name: Update chart + if: env.CONTINUE_JOB == 'true' run: | chmod +x hack/update/make-module-chart.sh - latest=$(sh hack/update/make-module-chart.sh) - echo "TAG=${latest}" >> $GITHUB_ENV + hack/update/make-module-chart.sh $TAG - name: Make templates + if: env.CONTINUE_JOB == 'true' run: | chmod +x hack/update/make-module-resources.sh - hack/update/make-module-resources.sh $TAG + hack/update/make-module-resources.sh $TAG - - name: Configure Git + - name: Configure Git + if: env.CONTINUE_JOB == 'true' run: | git config --global user.email $GIT_EMAIL git config --global user.name $GIT_NAME @@ -38,35 +55,36 @@ jobs: echo "MSG=Update module chart and resources to $TAG" >> $GITHUB_ENV - name: Check if there are changes + if: env.CONTINUE_JOB == 'true' shell: bash run: | prs=$(gh pr list -A $GIT_NAME --state open --json headRefName | jq -r '.[] | .headRefName') if echo $prs | tr " " '\n' | grep -F -q -x $BRANCH_NAME; then echo "open pr already exists, no need to create new one" - echo "CREATE_PR=false" >> $GITHUB_ENV + echo "CONTINUE_JOB=false" >> $GITHUB_ENV elif [ -z "$(git status --porcelain)" ]; then echo "nothing changed, exiting" - echo "CREATE_PR=false" >> $GITHUB_ENV + echo "CONTINUE_JOB=false" >> $GITHUB_ENV else - echo "CREATE_PR=true" >> $GITHUB_ENV + echo "CONTINUE_JOB=true" >> $GITHUB_ENV fi env: GH_TOKEN: ${{ secrets.BOT_TOKEN }} - name: Pass changes - if: env.CREATE_PR == 'true' + if: env.CONTINUE_JOB == 'true' run: | git add module-chart/* git add module-resources/* git stash push --staged - uses: actions/checkout@v3 - if: env.CREATE_PR == 'true' + if: env.CONTINUE_JOB == 'true' with: ref: main - name: Create PR - if: env.CREATE_PR == 'true' + if: env.CONTINUE_JOB == 'true' run: | git checkout -B $BRANCH_NAME git stash apply diff --git a/hack/update/get-latest-chart-version.sh b/hack/update/get-latest-chart-version.sh new file mode 100644 index 000000000..cf9fe2ac9 --- /dev/null +++ b/hack/update/get-latest-chart-version.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e +set -o pipefail + +cd "$(dirname "$0")" +latest=$(curl \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/SAP/sap-btp-service-operator/releases/latest | jq -r '.tag_name') +echo $latest \ No newline at end of file diff --git a/hack/update/make-module-chart.sh b/hack/update/make-module-chart.sh index 9d53bda5b..1e7af3ce2 100755 --- a/hack/update/make-module-chart.sh +++ b/hack/update/make-module-chart.sh @@ -1,16 +1,19 @@ #!/bin/bash +set -e +set -o pipefail + cd "$(dirname "$0")" readonly CHART_PATH="../../module-chart/chart" -latest=$(curl \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos/SAP/sap-btp-service-operator/releases/latest | jq -r '.tag_name') -curl -L https://github.com/SAP/sap-btp-service-operator/releases/download/$latest/sap-btp-operator-$latest.tgz > charts.tgz +tag=$1 +if [[ -z $tag ]]; then + tag=$(sh get-latest-chart-version.sh) +fi + +curl -L https://github.com/SAP/sap-btp-service-operator/releases/download/$tag/sap-btp-operator-$tag.tgz > charts.tgz tar zxf charts.tgz rm -r $CHART_PATH rsync -a sap-btp-operator/ $CHART_PATH rm -r sap-btp-operator rm charts.tgz -echo $latest \ No newline at end of file diff --git a/hack/update/make-module-resources.sh b/hack/update/make-module-resources.sh index 8593caee7..e2621fffd 100755 --- a/hack/update/make-module-resources.sh +++ b/hack/update/make-module-resources.sh @@ -1,4 +1,7 @@ #!/bin/bash +set -e +set -o pipefail + cd "$(dirname "$0")" readonly CHART_PATH="../../module-chart/chart" @@ -9,7 +12,8 @@ readonly EXISTING_RESOURCES_APPLY_PATH="../../module-resources/apply" readonly HELM_OUTPUT_PATH="rendered" readonly NEW_RESOURCES_PATH="rendered/sap-btp-operator/templates" -helm template $1 $CHART_PATH --output-dir $HELM_OUTPUT_PATH --values $CHART_OVERRIDES_PATH --namespace "kyma-system" +tag=$1 +helm template $tag $CHART_PATH --output-dir $HELM_OUTPUT_PATH --values $CHART_OVERRIDES_PATH --namespace "kyma-system" trap 'rm -rf -- "temp"' EXIT runActionForEachYaml() { @@ -45,7 +49,6 @@ actionForExistingResource() { } incoming_resources=() - runActionForEachYaml $NEW_RESOURCES_PATH actionForNewResource touch to-delete.yml