diff --git a/.github/workflows/automaticRelease.yml b/.github/workflows/automaticRelease.yml index 4433f4e..b5b32e3 100644 --- a/.github/workflows/automaticRelease.yml +++ b/.github/workflows/automaticRelease.yml @@ -47,4 +47,15 @@ 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: + permissions: + issues: write + contents: read + + uses: ./.github/workflows/notify_failure.yml + 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/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..8d21cf9 100644 --- a/.github/workflows/publishImage.yml +++ b/.github/workflows/publishImage.yml @@ -53,3 +53,14 @@ jobs: tags: ${{ env.TAGS }} - name: Check manifest run: docker buildx imagetools inspect ${{ env.GHCR_IMAGE }}:${{ env.VERSION }} + + notify_failure: + permissions: + issues: write + contents: read + + uses: ./.github/workflows/notify_failure.yml + needs: [ push_to_registry ] + if: failure() + with: + needs_job: push_to_registry \ No newline at end of file