dependabot-buildfailure #7687
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################### | |
# This action will create a shortcut story when build-test fails for dependabot | |
# pull requests. | |
############################################################################### | |
name: dependabot-buildfailure | |
on: | |
workflow_run: | |
workflows: [ "build-test" ] | |
types: [ completed ] | |
permissions: | |
pull-requests: write | |
jobs: | |
on-failure: | |
runs-on: ubuntu-latest | |
# only run for dependabot pull requests | |
if: | | |
( | |
github.actor == 'dependabot[bot]' | |
) && ( | |
github.event.workflow_run.conclusion == 'failure' | |
) | |
steps: | |
- name: Create shortcut story if build-test fails | |
run: | | |
PR_URL="$(gh pr view --repo "${GITHUB_REPO}" "${PR_NUMBER}" --json url --jq '.url')" | |
PR_TITLE="$(gh pr view --repo "${GITHUB_REPO}" "${PR_NUMBER}" --json title --jq '.title')" | |
STORY_NAME="Dependabot auto-merge failed for #${PR_NUMBER} - '${PR_TITLE//\"/\\\"}'" | |
STORY_DESCRIPTION="Dependabot auto-merge failed - build-test workflow run failed ${{ github.event.workflow_run.html_url }}\\n\\n${PR_URL}" | |
EXISTING_STORY_ID="$(gh pr view --repo "${GITHUB_REPO}" "${PR_NUMBER}" --json comments --jq '.comments | .[].body' | grep -o '\[sc-[0-9]*\]' | sed 's/\[sc-\([0-9]*\)\]/\1/' || true)" | |
if [ -n "${EXISTING_STORY_ID}" ] ; then | |
curl -X POST \ | |
-H "Content-Type: application/json" \ | |
-H "Shortcut-Token: ${SHORTCUT_API_TOKEN}" \ | |
-d "{ \"text\": \"${STORY_DESCRIPTION}\" }" \ | |
-L "https://api.app.shortcut.com/api/v3/stories/${EXISTING_STORY_ID}/comments" | |
echo "::notice ::shortcut story already exists" | |
exit 0 | |
fi | |
# 28614 == Project id "Kubernetes Installer (kURL)" | |
# 500123931 == Workflow state "Untriaged" | |
NEW_STORY="$(curl -X POST \ | |
-H "Content-Type: application/json" \ | |
-H "Shortcut-Token: ${SHORTCUT_API_TOKEN}" \ | |
-d "{ \ | |
\"project_id\": 28614, \ | |
\"story_type\": \"chore\", \ | |
\"workflow_state_id\": 500123931, \ | |
\"labels\": [{ \"name\": \"requester/dependabot\" }], \ | |
\"name\": \"${STORY_NAME}\", \ | |
\"description\": \"${STORY_DESCRIPTION}\" }" \ | |
-L "https://api.app.shortcut.com/api/v3/stories")" | |
NEW_STORY_ID="$(echo "${NEW_STORY}"| jq -r '.id')" | |
# this is required as the script uses this comment to determine if it has already opened a shortcut story | |
gh pr comment --repo "${GITHUB_REPO}" "${PR_NUMBER}" --body "[sc-${NEW_STORY_ID}]" | |
echo "::notice ::shortcut story created" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SHORTCUT_API_TOKEN: ${{ secrets.SHORTCUT_API_TOKEN }} | |
GITHUB_REPO: ${{ github.repository }} | |
PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }} |