Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLOUDP-269500: Add logic to create jira ticket when we file an issue #196

Merged
merged 9 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/ISSUE_TEMPLATE/GH_ACTION_ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: "({{env.TARGET_ENV}}) The {{env.RELEASE_NAME}} Release has failed. :scream_cat:"
labels: failed-release
---
See https://github.com/{{tools.context.issue}}/actions/runs/{{env.GITHUB_RUN_ID}}

35 changes: 35 additions & 0 deletions .github/scripts/create_jira_ticket.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -eou pipefail

json_response=$(curl --request POST \
--url 'https://jira.mongodb.org/rest/api/2/issue' \
--header 'Authorization: Bearer '"${JIRA_API_TOKEN:?}" \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"fields": {
"project": {
"id": "10984"
},
"summary": "('"${TARGET_ENV:?}"') The '"${RELEASE_NAME:?}"' release has failed",
"issuetype": {
"id": "12"
},
"customfield_12751": [{
"id": "22223"
}],
"description": "The release process '"${RELEASE_NAME:?}"' in [mongodb/openapi|https://github.com/mongodb/openapi] has failed. Please, look at the [issue-'"${ISSUE_ID:?}"'|https://github.com/mongodb/openapi/issues/'"${ISSUE_ID}"'] for more details.",
"components": [
{
"id": "35986"
}
]
}
}')

echo "Response: ${json_response}"

JIRA_TICKET_ID=$(echo "${json_response}" | jq -r '.key')

echo "The following JIRA ticket has been created: ${JIRA_TICKET_ID}"
echo "jira-ticket-id=${JIRA_TICKET_ID}" >> "${GITHUB_OUTPUT}"
76 changes: 76 additions & 0 deletions .github/workflows/failure-handler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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
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@692973e3d937129bcbf40652eb9f2f61becf3332
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)
echo "number_issue=${number_issue}"
echo "found-issue=false" >> "${GITHUB_OUTPUT}"
if [ "${number_issue}" -gt 0 ]; then
echo "An issue already exists. Stopping execution."
echo "found-issue=true" >> "${GITHUB_OUTPUT}"
fi
- 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:
TARGET_ENV: ${{ inputs.env }}
RELEASE_NAME: ${{ inputs.release_name }}
JIRA_API_TOKEN: ${{ secrets.jira_api_token }}
ISSUE_ID: ${{ steps.create-issue.outputs.number }}
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."
10 changes: 0 additions & 10 deletions .github/workflows/release-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,3 @@ jobs:
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
branch: ${{env.target_branch}}
file_pattern: "changelog/*"
# - name: Create Issue To enable in CLOUDP-269500
# if: ${{ failure() }}
# uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
# env:
# target_env: ${{ inputs.env }}
# with:
# labels: failed-release
# title: "(${{env.target_env}}) The API Changelog Release has failed. :scream_cat:"
# body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
# token: ${{ secrets.GITHUB_TOKEN }}
29 changes: 11 additions & 18 deletions .github/workflows/release-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ jobs:
commit_sha: ${{ steps.get-sha.outputs.sha }}
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg_passphrase: ${{ secrets.PASSPHRASE }}
- name: Create Issue
if: ${{ failure() }}
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
labels: failed-release
title: "Releasing foascli v${{ inputs.version_number }} failed at the tag creation step :scream_cat:"
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}

run-tests:
needs: [ create-tag ]
Expand Down Expand Up @@ -80,12 +71,14 @@ jobs:
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Issue
if: ${{ failure() }}
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
labels: failed-release
title: "Releasing foascli ${{ inputs.version_number }} failed at the goreleaser step :scream_cat:"
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}

failure-handler:
name: Failure Handler
needs: [ release ]
if: ${{ always() && contains(needs.*.result, 'failure') }}
uses: ./.github/workflows/failure-handler.yml
with:
env: "prod"
release_name: "FOASCLI"
secrets:
jira_api_token: ${{ secrets.JIRA_API_TOKEN }}
18 changes: 0 additions & 18 deletions .github/workflows/release-postman.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ jobs:
run: |
make convert_to_collection

- name: Create Issue
if: ${{ failure() && steps.convert.outcome == 'failure' }}
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
with:
labels: failed-release
title: "Postman Release: `make convert_to_collection` command failed :scream_cat:"
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Transform Postman Collection
id: transform
env:
Expand All @@ -50,15 +41,6 @@ jobs:
run: |
make transform_collection

- name: Create Issue
if: ${{ failure() && steps.transform.outcome == 'failure' }}
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
with:
labels: failed-release
title: "Postman Release: `make transform_collection` command failed :scream_cat:"
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Collection to Postman
env:
POSTMAN_API_KEY: ${{ secrets.postman_api_key }}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release-spec-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
api_bot_pat: ${{ secrets.API_BOT_PAT }}
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_DEV }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }}
jira_api_token: ${{ secrets.JIRA_API_TOKEN }}
with:
aws_default_region: ${{ vars.AWS_DEFAULT_REGION}}
aws_s3_bucket: ${{ vars.S3_BUCKET_DEV}}
Expand All @@ -69,6 +70,7 @@ jobs:
api_bot_pat: ${{ secrets.API_BOT_PAT }}
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_QA }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_QA }}
jira_api_token: ${{ secrets.JIRA_API_TOKEN }}
with:
aws_default_region: ${{ vars.AWS_DEFAULT_REGION}}
aws_s3_bucket: ${{ vars.S3_BUCKET_QA}}
Expand All @@ -86,6 +88,7 @@ jobs:
api_bot_pat: ${{ secrets.API_BOT_PAT }}
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID_STAGING }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_STAGING }}
jira_api_token: ${{ secrets.JIRA_API_TOKEN }}
with:
aws_default_region: ${{ vars.AWS_DEFAULT_REGION}}
aws_s3_bucket: ${{ vars.S3_BUCKET_STAGING}}
Expand All @@ -105,6 +108,7 @@ jobs:
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_PROD }}
postman_api_key: ${{ secrets.POSTMAN_API_KEY }}
workspace_id: ${{ secrets.WORKSPACE_ID }}
jira_api_token: ${{ secrets.JIRA_API_TOKEN }}
with:
aws_default_region: ${{ vars.AWS_DEFAULT_REGION}}
aws_s3_bucket: ${{ vars.S3_BUCKET_PROD}}
Expand Down
26 changes: 14 additions & 12 deletions .github/workflows/release-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ on:
required: false
workspace_id:
required: false
jira_api_token:
required: true

permissions:
contents: write
Expand Down Expand Up @@ -118,8 +120,7 @@ jobs:
run-id: ${{ github.run_id }}
path: release-scripts
- name: Add permissions to execute scripts
run: |
chmod +x release-scripts/*.sh
run: chmod +x release-scripts/*.sh
- name: Install FOASCLI
env:
foascli_version: ${{ inputs.foascli_version }}
Expand Down Expand Up @@ -150,16 +151,6 @@ jobs:
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
branch: ${{env.target_branch}}
file_pattern: "openapi/*"
- name: Create Issue
if: ${{ failure() }}
uses: imjohnbo/issue-bot@572eed14422c4d6ca37e870f97e7da209422f5bd
env:
target_env: ${{ inputs.env }}
with:
labels: failed-release
title: "(${{env.target_env}}) The OpenAPI Release has failed. :scream_cat:"
body: See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
token: ${{ secrets.GITHUB_TOKEN }}

release-postman:
name: Release Postman
Expand Down Expand Up @@ -187,3 +178,14 @@ jobs:
env: ${{ inputs.env }}
branch: ${{ inputs.branch }}
foascli_version: ${{ inputs.foascli_version }}

failure-handler:
name: Failure Handler
needs: [ release, release-postman, release-changelog ]
if: ${{ always() && contains(needs.*.result, 'failure') }}
uses: ./.github/workflows/failure-handler.yml
with:
env: ${{ inputs.env }}
release_name: "OpenAPI Spec"
secrets:
jira_api_token: ${{ secrets.JIRA_API_TOKEN }}
Loading