From 82c82812c91ab52ba626d3327df5f5f5abc2f6c8 Mon Sep 17 00:00:00 2001 From: Sarah Gibson Date: Fri, 13 Sep 2024 13:35:06 +0100 Subject: [PATCH 1/4] Support tags triggering the workflow --- .github/workflows/publish-chart.yaml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish-chart.yaml b/.github/workflows/publish-chart.yaml index f76707b..1f820b7 100644 --- a/.github/workflows/publish-chart.yaml +++ b/.github/workflows/publish-chart.yaml @@ -12,6 +12,8 @@ on: - "**.md" - ".github/workflows/*" - "!.github/workflows/publish-chart.yaml" + tags: + - "**" jobs: publish-chart: @@ -33,9 +35,13 @@ jobs: if ( "${{ github.repository }}" == "2i2c-org/gcp-filestore-backups" and "${{ github.event_name }}" == "push" - and "${{ github.event.ref }}" == "refs/heads/main" + and ( + "${{ github.event.ref }}" == "refs/heads/main" + or "${{ github.event.ref }}".startswith("refs/tags/") + ) ): publish = "true" + print("Publishing chart") output_file = os.getenv("GITHUB_OUTPUT") with open(output_file, "w") as f: @@ -84,10 +90,14 @@ jobs: PUBLISH_ARGS="--publish-chart --push" - PR_OR_HASH=$(git log -1 --pretty=%h-%B | head -n1 | sed 's/^.*\(#[0-9]*\).*/\1/' | sed 's/^\([0-9a-f]*\)-.*/@\1/') - LATEST_COMMIT_TITLE=$(git log -1 --pretty=%B | head -n1) - EXTRA_MESSAGE="${{ github.repository }}${PR_OR_HASH} ${LATEST_COMMIT_TITLE}" + if [[ $GITHUB_REF != refs/tags/* ]]; then + PR_OR_HASH=$(git log -1 --pretty=%h-%B | head -n1 | sed 's/^.*\(#[0-9]*\).*/\1/' | sed 's/^\([0-9a-f]*\)-.*/@\1/') + LATEST_COMMIT_TITLE=$(git log -1 --pretty=%B | head -n1) + EXTRA_MESSAGE="${{ github.repository }}${PR_OR_HASH} ${LATEST_COMMIT_TITLE}" - chartpress $PUBLISH_ARGS --extra-message "${EXTRA_MESSAGE}" + chartpress $PUBLISH_ARGS --extra-message "${EXTRA_MESSAGE}" + else + chartpress $PUBLISH_ARGS --tag "${GITHUB_REF:10}" + fi git --no-pager diff --color From dd1c6c6aef39b6acdbbe40c9b19c57a03924ae7b Mon Sep 17 00:00:00 2001 From: Sarah Gibson Date: Fri, 13 Sep 2024 13:37:04 +0100 Subject: [PATCH 2/4] Only run push trigger on main branch --- .github/workflows/publish-chart.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/publish-chart.yaml b/.github/workflows/publish-chart.yaml index 1f820b7..5493a3e 100644 --- a/.github/workflows/publish-chart.yaml +++ b/.github/workflows/publish-chart.yaml @@ -7,6 +7,8 @@ on: - "**.md" - ".github/workflows/*" - "!.github/workflows/publish-chart.yaml" + branches: + - "main" pull_request: paths-ignore: - "**.md" From e2e57acbf2fad9215e9453d9ebafe8e0697c7125 Mon Sep 17 00:00:00 2001 From: Sarah Gibson Date: Fri, 13 Sep 2024 13:37:44 +0100 Subject: [PATCH 3/4] Configure a git user for chartpress to use to push with --- .github/workflows/publish-chart.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/publish-chart.yaml b/.github/workflows/publish-chart.yaml index 5493a3e..9a781be 100644 --- a/.github/workflows/publish-chart.yaml +++ b/.github/workflows/publish-chart.yaml @@ -71,6 +71,11 @@ jobs: - name: Install dependencies run: pip install chartpress + - name: Configure a git user + run: | + git config --global user.email "github-actions@example.local" + git config --global user.name "GitHub Actions user" + - name: Run image, push if necessary env: PUBLISH: ${{ steps.publish.outputs.publish }} From e5e2d104619bf6ca7edcc84016946ea2263e3e0c Mon Sep 17 00:00:00 2001 From: Sarah Gibson Date: Fri, 13 Sep 2024 13:38:40 +0100 Subject: [PATCH 4/4] Clarify a step name --- .github/workflows/publish-chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-chart.yaml b/.github/workflows/publish-chart.yaml index 9a781be..bc3740c 100644 --- a/.github/workflows/publish-chart.yaml +++ b/.github/workflows/publish-chart.yaml @@ -76,7 +76,7 @@ jobs: git config --global user.email "github-actions@example.local" git config --global user.name "GitHub Actions user" - - name: Run image, push if necessary + - name: Build image, push if necessary env: PUBLISH: ${{ steps.publish.outputs.publish }} run: |