-
Notifications
You must be signed in to change notification settings - Fork 16
88 lines (82 loc) · 3.98 KB
/
failure-handler.yml
File metadata and controls
88 lines (82 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: 'Handle failures in the workflow'
on:
workflow_call:
inputs:
env:
description: 'Environment to generate the OpenAPI Spec for.'
required: true
type: string
release_name:
description: 'Name of the release.'
required: true
type: string
team_id:
description: 'ID of Jira Team'
required: true
type: string
secrets: # all secrets are passed explicitly in this workflow
jira_api_token:
required: true
permissions:
contents: write
issues: write
jobs:
failure-handler:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
sparse-checkout: |
.github/ISSUE_TEMPLATE/GH_ACTION_ISSUE_TEMPLATE.md
.github/scripts/create_jira_ticket.sh
- name: Check if an issue already exists
id: check-issue
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARGET_ENV: ${{ inputs.env }}
RELEASE_NAME: ${{ inputs.release_name }}
REPO: ${{ github.repository }}
run: |
query="(${TARGET_ENV}}) The ${RELEASE_NAME} Release has failed."
number_issue=$(gh search issues "${query}" --repo "${REPO}" --state open --label failed-release --json title | jq length)
if [ -z "${number_issue}" ]; then
echo "There was an issue with the GH APIs. Stopping execution."
return 1
fi
echo "number_issue=${number_issue}"
if [ "${number_issue}" -gt 0 ]; then
echo "An issue already exists. Stopping execution."
echo "found-issue=true" >> "${GITHUB_OUTPUT}"
return 0
fi
echo "found-issue=false" >> "${GITHUB_OUTPUT}"
- name: Create Issue # Create an issue in the repo if the release fails
if: ${{ steps.check-issue.outputs.found-issue == 'false' }}
id: create-issue
uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5
env:
TARGET_ENV: ${{ inputs.env }}
RELEASE_NAME: ${{ inputs.release_name }}
GITHUB_RUN_ID: ${{ github.run_id }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update_existing: false
with:
filename: .github/ISSUE_TEMPLATE/GH_ACTION_ISSUE_TEMPLATE.md
- name: Create JIRA Ticket
if: ${{ steps.create-issue.outputs.number != null }}
id: create-jira-ticket
env:
JIRA_API_TOKEN: ${{ secrets.jira_api_token }}
JIRA_TICKET_TITLE: "(${{inputs.env}}) The ${{inputs.release_name}} release has failed. GH Issue: ${{steps.create-issue.outputs.number}}"
JIRA_TICKET_DESCRIPTION: "The release process ${{inputs.release_name}} in [mongodb/openapi|https://github.com/mongodb/openapi] has failed. Please, look at the [issue-${{steps.create-issue.outputs.number}}|https://github.com/mongodb/openapi/issues/${{steps.create-issue.outputs.number}}] for more details."
JIRA_TEAM_ID: ${{ inputs.team_id }}
run: .github/scripts/create_jira_ticket.sh
- name: Add comment to GH Issue
if: ${{ steps.create-issue.outputs.number != null }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JIRA_TICKET_ID: ${{ steps.create-jira-ticket.outputs.jira-ticket-id }}
ISSUE_URL: ${{ steps.create-issue.outputs.url }}
run: |
gh issue comment ${{ env.ISSUE_URL }} -b "The ticket [${{env.JIRA_TICKET_ID}}](https://jira.mongodb.org/browse/${{env.JIRA_TICKET_ID}}) was created for internal tracking."