Skip to content

Commit

Permalink
🚧 Replace job with reusable workflow
Browse files Browse the repository at this point in the history
The code has been relocated.
  • Loading branch information
victorlin committed Feb 8, 2025
1 parent 3c01cf9 commit 4bb7556
Showing 1 changed file with 9 additions and 74 deletions.
83 changes: 9 additions & 74 deletions .github/workflows/installation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,79 +43,14 @@ jobs:
cli-version: ">=7.3.0.post1"
runtime: conda

# Surface failures via GitHub issues
failure-reporting:
report-failure:
if: ${{ always() && github.ref_name == github.event.repository.default_branch }}
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v4

- name: Set variables
run: |
echo "title='Installation failure'" >> "$GITHUB_ENV"
if [[ "${{ needs.test.result }}" == "failure" ]]; then
echo "failure=true" >> "$GITHUB_ENV"
fi
if [[ "${{ needs.test.result }}" == "success" ]]; then
echo "success=true" >> "$GITHUB_ENV"
fi
- name: Extract workflow link
run: |
workflow_path=$(echo "${{ github.workflow_ref }}" | sed -E 's|^.*/(\.github/workflows/[^@]+)@\S*$|\1|')
echo "workflow_link=https://github.com/${{ github.repository }}/blob/${{ github.sha }}/$workflow_path" >> "$GITHUB_ENV"
- name: Create or close issue
run: |
# Search for issues opened by this job.
matching_issues=$(gh issue list \
--state open \
--author '@me' \
--json 'number,title' \
--jq 'map(select(.title == "${{ env.title }}") | .number)')
# Handle the case of multiple matching issues, even though this
# shouldn't happen under normal circumstances.
if [[ $(jq length <<<"$matching_issues") -gt 1 ]]; then
echo "ERROR: Multiple matching issues found:" >&2
for issue in $(jq -r '.[]' <<<"$matching_issues"); do
echo "- https://github.com/${{ github.repository }}/issues/$issue" >&2
done
echo "This must be handled manually." >&2
exit 1
fi
existing_issue=$(jq -r '.[0] | values' <<<"$matching_issues")
if [[ "${{ env.failure }}" == "true" ]]; then
if [[ -z "$existing_issue" ]]; then
echo "New failure detected. Creating issue..."
new_issue=$(gh issue create \
--title "${{ env.title }}" \
--body "$body")
echo "Created issue: $new_issue"
else
echo "Open issue already exists: https://github.com/${{ github.repository }}/issues/$existing_issue"
fi
fi
if [[ "${{ env.success }}" == "true" ]]; then
if [[ -n "$existing_issue" ]]; then
echo "Closing issue https://github.com/${{ github.repository }}/issues/$existing_issue"
gh issue close "$existing_issue" \
--comment "Workflow is successful as of https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
else
echo "No open issue to be closed."
fi
fi
env:
body: |
Automatically created by the workflow [${{ github.workflow }}](${{ env.workflow_link }}) which indicated failure on [run ${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}).
See the workflow run for details and make changes as necessary.
This issue will be automatically closed upon the next successful run of the workflow.
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_REPO }}
# FIXME: drop the branch tag after merging https://github.com/nextstrain/.github/pull/121
uses: nextstrain/.github/.github/workflows/report-failure.yaml@victorlin/report-failure
with:
failure: ${{ needs.test.result == 'failure' }}
success: ${{ needs.test.result == 'success' }}
title: Installation failure
secrets:
token: ${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_REPO }}

0 comments on commit 4bb7556

Please sign in to comment.