Skip to content

Commit 327df71

Browse files
committed
add issue on failing github actions
1 parent 2b2ea9b commit 327df71

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

.github/workflows/automaticRelease.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,11 @@ jobs:
4747
4848
The image can be pulled with `$ docker pull ghcr.io/cloudogu/helm:${{ steps.compare_releases.outputs.helmRelease }}-1`
4949
draft: false
50-
prerelease: false
50+
prerelease: false
51+
52+
notify_failure:
53+
uses: ./.github/workflows/notify_failure.yml
54+
secrets:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
with:
57+
needs_job: check_for_new_helm_version
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Notify Failure
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
needs_job:
7+
required: true
8+
type: string
9+
secrets:
10+
GITHUB_TOKEN:
11+
required: true
12+
13+
jobs:
14+
notify_failure:
15+
runs-on: ubuntu-latest
16+
needs:
17+
- ${{ inputs.needs_job }}
18+
permissions:
19+
issues: write
20+
contents: read
21+
if: failure()
22+
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
26+
steps:
27+
- name: Manage issue
28+
id: manage_issue
29+
run: |
30+
ISSUE_TITLE="[Workflow Log] Central error logging"
31+
ISSUE_DATA=$(gh issue list -R "$GITHUB_REPOSITORY" --search "is:open in:title \"${ISSUE_TITLE}\"" --json number --limit 1)
32+
ISSUE_NUMBER=$(echo "$ISSUE_DATA" | jq -r '.[0].number')
33+
34+
if [ -z "$ISSUE_NUMBER" ] || [ "$ISSUE_NUMBER" = "null" ]; then
35+
NEW_ISSUE_NUMBER=$(gh issue create -R "$GITHUB_REPOSITORY" --title "$ISSUE_TITLE" \
36+
--body "This issue serves as a central log for all workflow errors." \
37+
| sed -n 's/.*#\([0-9]\+\).*/\1/p')
38+
echo "issue_number=$NEW_ISSUE_NUMBER" >> "$GITHUB_OUTPUT"
39+
else
40+
echo "issue_number=$ISSUE_NUMBER" >> "$GITHUB_OUTPUT"
41+
fi
42+
43+
- name: Create comment
44+
run: |
45+
gh issue comment ${{ steps.manage_issue.outputs.issue_number }} \
46+
-R "$GITHUB_REPOSITORY" \
47+
--body "***Workflow failure*** ([View workflow run for details](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}))"

.github/workflows/publishImage.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,10 @@ jobs:
5353
tags: ${{ env.TAGS }}
5454
- name: Check manifest
5555
run: docker buildx imagetools inspect ${{ env.GHCR_IMAGE }}:${{ env.VERSION }}
56+
57+
notify_failure:
58+
uses: ./.github/workflows/notify_failure.yml
59+
secrets:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
with:
62+
needs_job: push_to_registry

0 commit comments

Comments
 (0)