From 5b3bacc5e9b949067709ac8e3b7fd456172f9492 Mon Sep 17 00:00:00 2001 From: Marco Droll Date: Wed, 19 Nov 2025 15:59:48 +0100 Subject: [PATCH 1/3] add issue on failing github actions --- .github/workflows/docker-image.yml | 39 +++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 228a37d..4904b83 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -48,4 +48,41 @@ jobs: org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }} org.opencontainers.image.ref.name=${{ env.GIT_REF }} org.opencontainers.image.revision=${{ env.GIT_SHA }} - org.opencontainers.image.source=https://github.com/${{ github.repository }} + org.opencontainers.image.source=https://github.com/${{ github.repository }} + + notify_failure: + runs-on: ubuntu-latest + needs: build: + 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 + id: create_comment + run: | + if [ ! -z "${{ steps.manage_issue.outputs.issue_number }}" ] || [ "${{ steps.manage_issue.outputs.issue_number }}" != "null" ]; then + echo "Issue number not found!" + exit 1 + else + 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 }}))" + fi From 4c9d68799bcc5562a8e6f0c9aeda81ff587c98bf Mon Sep 17 00:00:00 2001 From: Marco Droll Date: Thu, 20 Nov 2025 09:20:51 +0100 Subject: [PATCH 2/3] fix wrong condition --- .github/workflows/docker-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 4904b83..5c5a102 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -80,7 +80,7 @@ jobs: - name: Create comment id: create_comment run: | - if [ ! -z "${{ steps.manage_issue.outputs.issue_number }}" ] || [ "${{ steps.manage_issue.outputs.issue_number }}" != "null" ]; then + if [ -z "${{ steps.manage_issue.outputs.issue_number }}" ] || [ "${{ steps.manage_issue.outputs.issue_number }}" = "null" ]; then echo "Issue number not found!" exit 1 else From 2ba5edab9813cf52e5f0154f3032fc9e6295f8d2 Mon Sep 17 00:00:00 2001 From: Marco Droll Date: Fri, 21 Nov 2025 13:26:48 +0100 Subject: [PATCH 3/3] outsourced notify_failure --- .github/workflows/docker-image.yml | 39 +++++--------------------- .github/workflows/notify_failure.yml | 42 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/notify_failure.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 5c5a102..01b5ecc 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -48,41 +48,16 @@ jobs: org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }} org.opencontainers.image.ref.name=${{ env.GIT_REF }} org.opencontainers.image.revision=${{ env.GIT_SHA }} - org.opencontainers.image.source=https://github.com/${{ github.repository }} + org.opencontainers.image.source=https://github.com/${{ github.repository }} notify_failure: - runs-on: ubuntu-latest - needs: build: + 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 - id: create_comment - run: | - if [ -z "${{ steps.manage_issue.outputs.issue_number }}" ] || [ "${{ steps.manage_issue.outputs.issue_number }}" = "null" ]; then - echo "Issue number not found!" - exit 1 - else - 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 }}))" - fi + uses: ./.github/workflows/notify_failure.yml + needs: [ build ] + if: failure() + with: + needs_job: build \ 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..b355c17 --- /dev/null +++ b/.github/workflows/notify_failure.yml @@ -0,0 +1,42 @@ +name: Notify Failure + +on: + workflow_call: + inputs: + needs_job: + required: true + type: string + +permissions: + issues: write + contents: read + +jobs: + notify_failure: + runs-on: ubuntu-latest + + 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