Skip to content

Commit fe9af1a

Browse files
CLOUDP-311043: Prevent Duplicate Issues for optional-spec-validations (#663)
1 parent 02b1d93 commit fe9af1a

File tree

2 files changed

+78
-15
lines changed

2 files changed

+78
-15
lines changed

.github/workflows/optional-spec-validations.yml

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,19 @@ jobs:
5656
popd
5757
- name: Create Issue - Postman validation Failed
5858
if: ${{ failure() && steps.spectral-validation.outcome == 'failure' }}
59-
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
60-
env:
61-
target_env: ${{ inputs.env }}
59+
uses: ./.github/workflows/task-failure-handler.yml
6260
with:
63-
labels: failed-release
64-
title: "(${{env.target_env}}) Optional Postman validation failed :scream_cat:"
65-
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
66-
token: ${{ secrets.GITHUB_TOKEN }}
61+
env: ${{ inputs.env }}
62+
task_name: 'Optional Postman validation'
63+
team_id: ${{ vars.JIRA_TEAM_ID_APIX_1 }}
64+
secrets:
65+
jira_api_token: ${{ secrets.JIRA_API_TOKEN }}
6766
- name: Create Issue - IPA validation Failed
68-
if: ${{ failure() && steps.ipa-spectral-validation.outcome == 'failure' }}
69-
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
70-
env:
71-
target_env: ${{ inputs.env }}
67+
if: ${{ failure() && steps.ipa-spectral-validation.outcome == 'failure'}}
68+
uses: ./.github/workflows/task-failure-handler.yml
7269
with:
73-
labels: failed-release
74-
title: "(${{env.target_env}}) Optional IPA validation failed :scream_cat:"
75-
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
76-
token: ${{ secrets.GITHUB_TOKEN }}
70+
env: ${{ inputs.env }}
71+
task_name: 'Optional IPA validation'
72+
team_id: ${{ vars.JIRA_TEAM_ID_APIX_1 }}
73+
secrets:
74+
jira_api_token: ${{ secrets.JIRA_API_TOKEN }}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: 'Handle failures in the workflow'
2+
on:
3+
workflow_call:
4+
inputs:
5+
env:
6+
description: 'Environment the task has been failed.'
7+
required: true
8+
type: string
9+
task_name:
10+
description: 'Name of the task.'
11+
required: true
12+
type: string
13+
team_id:
14+
description: 'ID of Jira Team'
15+
required: true
16+
type: string
17+
secrets: # all secrets are passed explicitly in this workflow
18+
jira_api_token:
19+
required: true
20+
21+
permissions:
22+
contents: write
23+
issues: write
24+
25+
jobs:
26+
failure-handler:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
31+
32+
- name: Check if an issue already exists
33+
id: check-issue
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
TARGET_ENV: ${{ inputs.env }}
37+
TASK_NAME: ${{ inputs.task_name }}
38+
REPO: ${{ github.repository }}
39+
run: |
40+
query="(${TARGET_ENV}}) The ${TASK_NAME} task has failed."
41+
number_issue=$(gh search issues "${query}" --repo "${REPO}" --state open --label failed-release --json title | jq length)
42+
43+
if [ -z "${number_issue}" ]; then
44+
echo "There was an issue with the GH APIs. Stopping execution."
45+
return 1
46+
fi
47+
48+
echo "number_issue=${number_issue}"
49+
if [ "${number_issue}" -gt 0 ]; then
50+
echo "An issue already exists. Stopping execution."
51+
echo "found-issue=true" >> "${GITHUB_OUTPUT}"
52+
return 0
53+
fi
54+
55+
echo "found-issue=false" >> "${GITHUB_OUTPUT}"
56+
- name: Create Issue # Create an issue in the repo if the release fails
57+
if: ${{ steps.check-issue.outputs.found-issue == 'false' }}
58+
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
59+
env:
60+
target_env: ${{ inputs.env }}
61+
with:
62+
labels: failed-release
63+
title: "(${{env.target_env}}) ${{ inputs.task_name }} failed :scream_cat:"
64+
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
65+
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)