From 327df71711041706a9d0df6b4b150bf7e9e29e59 Mon Sep 17 00:00:00 2001 From: Marco Droll Date: Thu, 20 Nov 2025 17:19:18 +0100 Subject: [PATCH 1/2] add issue on failing github actions --- .github/workflows/automaticRelease.yml | 9 ++++- .github/workflows/notify_failure.yml | 47 ++++++++++++++++++++++++++ .github/workflows/publishImage.yml | 7 ++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/notify_failure.yml diff --git a/.github/workflows/automaticRelease.yml b/.github/workflows/automaticRelease.yml index 4433f4e..5f19932 100644 --- a/.github/workflows/automaticRelease.yml +++ b/.github/workflows/automaticRelease.yml @@ -47,4 +47,11 @@ jobs: The image can be pulled with `$ docker pull ghcr.io/cloudogu/helm:${{ steps.compare_releases.outputs.helmRelease }}-1` draft: false - prerelease: false + prerelease: false + + notify_failure: + uses: ./.github/workflows/notify_failure.yml + secrets: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + needs_job: check_for_new_helm_version \ No newline at end of file diff --git a/.github/workflows/notify_failure.yml b/.github/workflows/notify_failure.yml new file mode 100644 index 0000000..9614778 --- /dev/null +++ b/.github/workflows/notify_failure.yml @@ -0,0 +1,47 @@ +name: Notify Failure + +on: + workflow_call: + inputs: + needs_job: + required: true + type: string + secrets: + GITHUB_TOKEN: + required: true + +jobs: + notify_failure: + runs-on: ubuntu-latest + needs: + - ${{ inputs.needs_job }} + permissions: + issues: write + contents: read + if: failure() + + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + steps: + - name: Manage issue + id: manage_issue + run: | + ISSUE_TITLE="[Workflow Log] Central error logging" + ISSUE_DATA=$(gh issue list -R "$GITHUB_REPOSITORY" --search "is:open in:title \"${ISSUE_TITLE}\"" --json number --limit 1) + ISSUE_NUMBER=$(echo "$ISSUE_DATA" | jq -r '.[0].number') + + if [ -z "$ISSUE_NUMBER" ] || [ "$ISSUE_NUMBER" = "null" ]; then + NEW_ISSUE_NUMBER=$(gh issue create -R "$GITHUB_REPOSITORY" --title "$ISSUE_TITLE" \ + --body "This issue serves as a central log for all workflow errors." \ + | sed -n 's/.*#\([0-9]\+\).*/\1/p') + echo "issue_number=$NEW_ISSUE_NUMBER" >> "$GITHUB_OUTPUT" + else + echo "issue_number=$ISSUE_NUMBER" >> "$GITHUB_OUTPUT" + fi + + - name: Create comment + run: | + gh issue comment ${{ steps.manage_issue.outputs.issue_number }} \ + -R "$GITHUB_REPOSITORY" \ + --body "***Workflow failure*** ([View workflow run for details](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}))" \ No newline at end of file diff --git a/.github/workflows/publishImage.yml b/.github/workflows/publishImage.yml index 0a0aece..6ed898c 100644 --- a/.github/workflows/publishImage.yml +++ b/.github/workflows/publishImage.yml @@ -53,3 +53,10 @@ jobs: tags: ${{ env.TAGS }} - name: Check manifest run: docker buildx imagetools inspect ${{ env.GHCR_IMAGE }}:${{ env.VERSION }} + + notify_failure: + uses: ./.github/workflows/notify_failure.yml + secrets: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + needs_job: push_to_registry \ No newline at end of file From 30d5102916d57e1745bed8809339283fa42a9e9d Mon Sep 17 00:00:00 2001 From: Marco Droll Date: Fri, 21 Nov 2025 13:45:44 +0100 Subject: [PATCH 2/2] outsourced notify_failure --- .github/workflows/automaticRelease.yml | 8 ++++++-- .github/workflows/publishImage.yml | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/automaticRelease.yml b/.github/workflows/automaticRelease.yml index 5f19932..b5b32e3 100644 --- a/.github/workflows/automaticRelease.yml +++ b/.github/workflows/automaticRelease.yml @@ -50,8 +50,12 @@ jobs: prerelease: false notify_failure: + permissions: + issues: write + contents: read + uses: ./.github/workflows/notify_failure.yml - secrets: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + needs: [ check_for_new_helm_version ] + if: failure() with: needs_job: check_for_new_helm_version \ No newline at end of file diff --git a/.github/workflows/publishImage.yml b/.github/workflows/publishImage.yml index 6ed898c..8d21cf9 100644 --- a/.github/workflows/publishImage.yml +++ b/.github/workflows/publishImage.yml @@ -55,8 +55,12 @@ jobs: run: docker buildx imagetools inspect ${{ env.GHCR_IMAGE }}:${{ env.VERSION }} notify_failure: + permissions: + issues: write + contents: read + uses: ./.github/workflows/notify_failure.yml - secrets: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + needs: [ push_to_registry ] + if: failure() with: needs_job: push_to_registry \ No newline at end of file