Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvments #159

Merged
merged 13 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions .github/workflows/auto-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,42 @@ on:
- cron: '0 0 * * *'

jobs:

auto-bump-chart:
runs-on: ubuntu-latest

steps:

- 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
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions hack/update/get-latest-chart-version.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 9 additions & 6 deletions hack/update/make-module-chart.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions hack/update/make-module-resources.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/bash
set -e
set -o pipefail

cd "$(dirname "$0")"

readonly CHART_PATH="../../module-chart/chart"
Expand All @@ -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() {
Expand Down Expand Up @@ -45,7 +49,6 @@ actionForExistingResource() {
}

incoming_resources=()

runActionForEachYaml $NEW_RESOURCES_PATH actionForNewResource

touch to-delete.yml
Expand Down