From f502579f7a390fa042dc1580e4a93c872375bb50 Mon Sep 17 00:00:00 2001 From: LJ Date: Thu, 2 Feb 2023 10:32:19 +0100 Subject: [PATCH 01/13] improvments --- .github/workflows/auto-update.yml | 41 +++++++++++++++++-------- hack/update/get-latest-chart-version.sh | 10 ++++++ hack/update/make-module-chart.sh | 17 +++++----- hack/update/make-module-resources.sh | 9 ++++-- 4 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 hack/update/get-latest-chart-version.sh diff --git a/.github/workflows/auto-update.yml b/.github/workflows/auto-update.yml index 14039c67a..21b158cdc 100644 --- a/.github/workflows/auto-update.yml +++ b/.github/workflows/auto-update.yml @@ -1,7 +1,7 @@ name: Auto update chart/resources env: - ORG: kyma-project + ORG: ukff BTP_MANAGER_REPO: btp-manager GIT_EMAIL: team-gopher+1@sap.com GIT_NAME: kyma-btp-manager-bot @@ -18,18 +18,34 @@ jobs: - uses: actions/checkout@v3 - - name: Update chart + - name: Check for new version + 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=false" >> $GITHUB_ENV + else + echo "version update from $current to $latest" + echo "CONTINUE=true" >> $GITHUB_ENV + echo "TAG=${latest}" >> $GITHUB_ENV + fi + + - name: Update chart + if: env.CONTINUE == '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 == '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 == 'true' run: | git config --global user.email $GIT_EMAIL git config --global user.name $GIT_NAME @@ -38,35 +54,36 @@ jobs: echo "MSG=Update module chart and resources to $TAG" >> $GITHUB_ENV - name: Check if there are changes + if: env.CONTINUE == '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=false" >> $GITHUB_ENV elif [ -z "$(git status --porcelain)" ]; then echo "nothing changed, exiting" - echo "CREATE_PR=false" >> $GITHUB_ENV + echo "CONTINUE=false" >> $GITHUB_ENV else - echo "CREATE_PR=true" >> $GITHUB_ENV + echo "CONTINUE=true" >> $GITHUB_ENV fi env: GH_TOKEN: ${{ secrets.BOT_TOKEN }} - name: Pass changes - if: env.CREATE_PR == 'true' + if: env.CONTINUE == '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 == 'true' with: ref: main - name: Create PR - if: env.CREATE_PR == 'true' + if: env.CONTINUE == '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..41a44e6ac 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 +rm charts.tgz \ No newline at end of file diff --git a/hack/update/make-module-resources.sh b/hack/update/make-module-resources.sh index 8593caee7..cd2a7785a 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 @@ -57,4 +60,4 @@ mkdir $EXISTING_RESOURCES_APPLY_PATH mkdir $EXISTING_RESOURCES_DELETE_PATH mv $NEW_RESOURCES_PATH/* $EXISTING_RESOURCES_APPLY_PATH mv to-delete.yml $EXISTING_RESOURCES_DELETE_PATH -rm -r $HELM_OUTPUT_PATH +rm -r $HELM_OUTPUT_PATH \ No newline at end of file From 68718783b1f29e97c292cf9a11002d36ffbaac6b Mon Sep 17 00:00:00 2001 From: LJ Date: Thu, 2 Feb 2023 10:37:03 +0100 Subject: [PATCH 02/13] improvments --- hack/update/make-module-chart.sh | 2 +- hack/update/make-module-resources.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hack/update/make-module-chart.sh b/hack/update/make-module-chart.sh index 41a44e6ac..1e7af3ce2 100755 --- a/hack/update/make-module-chart.sh +++ b/hack/update/make-module-chart.sh @@ -16,4 +16,4 @@ tar zxf charts.tgz rm -r $CHART_PATH rsync -a sap-btp-operator/ $CHART_PATH rm -r sap-btp-operator -rm charts.tgz \ No newline at end of file +rm charts.tgz diff --git a/hack/update/make-module-resources.sh b/hack/update/make-module-resources.sh index cd2a7785a..e2621fffd 100755 --- a/hack/update/make-module-resources.sh +++ b/hack/update/make-module-resources.sh @@ -60,4 +60,4 @@ mkdir $EXISTING_RESOURCES_APPLY_PATH mkdir $EXISTING_RESOURCES_DELETE_PATH mv $NEW_RESOURCES_PATH/* $EXISTING_RESOURCES_APPLY_PATH mv to-delete.yml $EXISTING_RESOURCES_DELETE_PATH -rm -r $HELM_OUTPUT_PATH \ No newline at end of file +rm -r $HELM_OUTPUT_PATH From 92ebbb4acbdac319d6b7533d4e3dc1f9f868a012 Mon Sep 17 00:00:00 2001 From: LJ Date: Thu, 2 Feb 2023 10:38:17 +0100 Subject: [PATCH 03/13] improvments --- hack/update/get-latest-chart-version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/update/get-latest-chart-version.sh b/hack/update/get-latest-chart-version.sh index cf9fe2ac9..ae6a63bb4 100644 --- a/hack/update/get-latest-chart-version.sh +++ b/hack/update/get-latest-chart-version.sh @@ -7,4 +7,4 @@ 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 +echo "v0.2.5" \ No newline at end of file From 2d5ddb8d92dcd06871ae77698abe96ed352c9545 Mon Sep 17 00:00:00 2001 From: LJ Date: Thu, 2 Feb 2023 10:56:26 +0100 Subject: [PATCH 04/13] improvments --- .github/workflows/auto-update.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/auto-update.yml b/.github/workflows/auto-update.yml index 21b158cdc..8cb90c90c 100644 --- a/.github/workflows/auto-update.yml +++ b/.github/workflows/auto-update.yml @@ -82,6 +82,15 @@ jobs: with: ref: main + - name: Remove branch protection + run: | + gh api \ + --method DELETE \ + -H "Accept: application/vnd.github+json" \ + /repos/$ORG/$BTP_MANAGER_REPO/branches/$BRANCH_NAME/protection + env: + GH_TOKEN: ${{ secrets.BOT_TOKEN }} + - name: Create PR if: env.CONTINUE == 'true' run: | From cf6143a8fd43f2cea7351f16411675016be84547 Mon Sep 17 00:00:00 2001 From: LJ Date: Thu, 2 Feb 2023 11:17:35 +0100 Subject: [PATCH 05/13] improvments --- .github/workflows/auto-update.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/auto-update.yml b/.github/workflows/auto-update.yml index 8cb90c90c..3d3f510ba 100644 --- a/.github/workflows/auto-update.yml +++ b/.github/workflows/auto-update.yml @@ -83,13 +83,14 @@ jobs: ref: main - name: Remove branch protection + if: env.CONTINUE == 'true' run: | gh api \ --method DELETE \ -H "Accept: application/vnd.github+json" \ /repos/$ORG/$BTP_MANAGER_REPO/branches/$BRANCH_NAME/protection env: - GH_TOKEN: ${{ secrets.BOT_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Create PR if: env.CONTINUE == 'true' From da9ef2f13a9595375b7ad067d541a619a58285e2 Mon Sep 17 00:00:00 2001 From: LJ Date: Thu, 2 Feb 2023 11:20:02 +0100 Subject: [PATCH 06/13] improvments --- .github/workflows/auto-update.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/auto-update.yml b/.github/workflows/auto-update.yml index 3d3f510ba..5cf18843c 100644 --- a/.github/workflows/auto-update.yml +++ b/.github/workflows/auto-update.yml @@ -11,8 +11,10 @@ on: - cron: '0 0 * * *' jobs: + auto-bump-chart: runs-on: ubuntu-latest + permissions: write-all steps: From 8a88ead06d86cba6423b912bd0b86d015fda0272 Mon Sep 17 00:00:00 2001 From: LJ Date: Thu, 2 Feb 2023 11:21:32 +0100 Subject: [PATCH 07/13] improvments --- .github/workflows/auto-update.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-update.yml b/.github/workflows/auto-update.yml index 5cf18843c..d4a51874a 100644 --- a/.github/workflows/auto-update.yml +++ b/.github/workflows/auto-update.yml @@ -92,7 +92,7 @@ jobs: -H "Accept: application/vnd.github+json" \ /repos/$ORG/$BTP_MANAGER_REPO/branches/$BRANCH_NAME/protection env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.BOT_TOKEN }} - name: Create PR if: env.CONTINUE == 'true' From 9306b0de4d873e2761cbcb5e4eeb03c6d1fad3ca Mon Sep 17 00:00:00 2001 From: LJ Date: Thu, 2 Feb 2023 11:27:10 +0100 Subject: [PATCH 08/13] improvments --- .github/workflows/auto-update.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/auto-update.yml b/.github/workflows/auto-update.yml index d4a51874a..dfabe188e 100644 --- a/.github/workflows/auto-update.yml +++ b/.github/workflows/auto-update.yml @@ -87,12 +87,12 @@ jobs: - name: Remove branch protection if: env.CONTINUE == 'true' run: | - gh api \ - --method DELETE \ + curl \ + -X DELETE \ -H "Accept: application/vnd.github+json" \ - /repos/$ORG/$BTP_MANAGER_REPO/branches/$BRANCH_NAME/protection - env: - GH_TOKEN: ${{ secrets.BOT_TOKEN }} + -H "Authorization: Bearer ${{ secrets.BOT_TOKEN }}"\ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/$OEG/$BTP_MANAGER_REPO/branches/$BRANCH_NAME/protection - name: Create PR if: env.CONTINUE == 'true' From 9ccf1a6d0feda06e15d20633592eccd0ab24da66 Mon Sep 17 00:00:00 2001 From: LJ Date: Thu, 2 Feb 2023 11:27:28 +0100 Subject: [PATCH 09/13] improvments --- .github/workflows/auto-update.yml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/auto-update.yml b/.github/workflows/auto-update.yml index dfabe188e..5f7f5c578 100644 --- a/.github/workflows/auto-update.yml +++ b/.github/workflows/auto-update.yml @@ -84,16 +84,6 @@ jobs: with: ref: main - - name: Remove branch protection - if: env.CONTINUE == 'true' - run: | - curl \ - -X DELETE \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${{ secrets.BOT_TOKEN }}"\ - -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos/$OEG/$BTP_MANAGER_REPO/branches/$BRANCH_NAME/protection - - name: Create PR if: env.CONTINUE == 'true' run: | @@ -103,7 +93,7 @@ jobs: git add module-resources/* git commit -m "$MSG" git remote set-url origin https://x-access-token:${{ secrets.BOT_TOKEN }}@github.com/$ORG/$BTP_MANAGER_REPO.git - git push --set-upstream origin $BRANCH_NAME -f + git push --set-upstream origin $BRANCH_NAME gh pr create -B main --title "$MSG" --body "" env: GH_TOKEN: ${{ secrets.BOT_TOKEN }} \ No newline at end of file From e7b10691f179cd6beac46565840288a218433d0d Mon Sep 17 00:00:00 2001 From: LJ Date: Thu, 2 Feb 2023 12:31:21 +0100 Subject: [PATCH 10/13] improvments --- .github/workflows/auto-update.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/auto-update.yml b/.github/workflows/auto-update.yml index 5f7f5c578..e29db2bde 100644 --- a/.github/workflows/auto-update.yml +++ b/.github/workflows/auto-update.yml @@ -1,7 +1,7 @@ name: Auto update chart/resources env: - ORG: ukff + ORG: kyma-project BTP_MANAGER_REPO: btp-manager GIT_EMAIL: team-gopher+1@sap.com GIT_NAME: kyma-btp-manager-bot @@ -14,7 +14,6 @@ jobs: auto-bump-chart: runs-on: ubuntu-latest - permissions: write-all steps: @@ -93,7 +92,7 @@ jobs: git add module-resources/* git commit -m "$MSG" git remote set-url origin https://x-access-token:${{ secrets.BOT_TOKEN }}@github.com/$ORG/$BTP_MANAGER_REPO.git - git push --set-upstream origin $BRANCH_NAME + git push --set-upstream origin $BRANCH_NAME -f gh pr create -B main --title "$MSG" --body "" env: GH_TOKEN: ${{ secrets.BOT_TOKEN }} \ No newline at end of file From 70ff091f75c0251045c6fa17a9390a52db614143 Mon Sep 17 00:00:00 2001 From: LJ Date: Thu, 2 Feb 2023 12:32:47 +0100 Subject: [PATCH 11/13] improvments --- hack/update/get-latest-chart-version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/update/get-latest-chart-version.sh b/hack/update/get-latest-chart-version.sh index ae6a63bb4..cf9fe2ac9 100644 --- a/hack/update/get-latest-chart-version.sh +++ b/hack/update/get-latest-chart-version.sh @@ -7,4 +7,4 @@ 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 "v0.2.5" \ No newline at end of file +echo $latest \ No newline at end of file From 6d605724b80549b0ca79a3b7237b048611a7bd41 Mon Sep 17 00:00:00 2001 From: LJ Date: Thu, 2 Feb 2023 12:33:43 +0100 Subject: [PATCH 12/13] improvments --- .github/workflows/auto-update.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-update.yml b/.github/workflows/auto-update.yml index e29db2bde..576d71857 100644 --- a/.github/workflows/auto-update.yml +++ b/.github/workflows/auto-update.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/checkout@v3 - - name: Check for new version + - name: Compare Tags run: | chmod +x hack/update/get-latest-chart-version.sh latest=$(hack/update/get-latest-chart-version.sh) From 9eedcb8048f895ed97debf26ce2d5c96c1fea2e9 Mon Sep 17 00:00:00 2001 From: LJ Date: Thu, 2 Feb 2023 12:53:52 +0100 Subject: [PATCH 13/13] improvments --- .github/workflows/auto-update.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/auto-update.yml b/.github/workflows/auto-update.yml index 576d71857..93f5558f6 100644 --- a/.github/workflows/auto-update.yml +++ b/.github/workflows/auto-update.yml @@ -26,27 +26,27 @@ jobs: current=$(yq '.version' ./module-chart/chart/Chart.yaml) if [[ $latest == $current ]]; then echo "version are the same: $latest=$current" - echo "CONTINUE=false" >> $GITHUB_ENV + echo "CONTINUE_JOB=false" >> $GITHUB_ENV else echo "version update from $current to $latest" - echo "CONTINUE=true" >> $GITHUB_ENV + echo "CONTINUE_JOB=true" >> $GITHUB_ENV echo "TAG=${latest}" >> $GITHUB_ENV fi - name: Update chart - if: env.CONTINUE == 'true' + if: env.CONTINUE_JOB == 'true' run: | chmod +x hack/update/make-module-chart.sh hack/update/make-module-chart.sh $TAG - name: Make templates - if: env.CONTINUE == 'true' + if: env.CONTINUE_JOB == 'true' run: | chmod +x hack/update/make-module-resources.sh hack/update/make-module-resources.sh $TAG - name: Configure Git - if: env.CONTINUE == 'true' + if: env.CONTINUE_JOB == 'true' run: | git config --global user.email $GIT_EMAIL git config --global user.name $GIT_NAME @@ -55,36 +55,36 @@ jobs: echo "MSG=Update module chart and resources to $TAG" >> $GITHUB_ENV - name: Check if there are changes - if: env.CONTINUE == 'true' + 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 "CONTINUE=false" >> $GITHUB_ENV + echo "CONTINUE_JOB=false" >> $GITHUB_ENV elif [ -z "$(git status --porcelain)" ]; then echo "nothing changed, exiting" - echo "CONTINUE=false" >> $GITHUB_ENV + echo "CONTINUE_JOB=false" >> $GITHUB_ENV else - echo "CONTINUE=true" >> $GITHUB_ENV + echo "CONTINUE_JOB=true" >> $GITHUB_ENV fi env: GH_TOKEN: ${{ secrets.BOT_TOKEN }} - name: Pass changes - if: env.CONTINUE == '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.CONTINUE == 'true' + if: env.CONTINUE_JOB == 'true' with: ref: main - name: Create PR - if: env.CONTINUE == 'true' + if: env.CONTINUE_JOB == 'true' run: | git checkout -B $BRANCH_NAME git stash apply