fix(README): include the gh actions status #1
Workflow file for this run
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
name: Cancel Workflow Runs | |
on: | |
pull_request: | |
types: [ synchronize ] | |
jobs: | |
cancel-runs: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Extract branch name | |
shell: bash | |
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT | |
id: extract_branch | |
- name: Get Workflow Runs | |
id: get_runs | |
uses: actions/github-script@v4 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const { data: runs } = await github.actions.listRepoWorkflowRuns({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
branch: ${{ steps.extract_branch.outputs.branch }} | |
per_page: 100, | |
status: 'in_progress' // Filter for in-progress runs | |
}); | |
return runs; | |
- name: Cancel Workflow Runs | |
if: ${{ always() }} | |
run: | | |
for run in "${{ steps.get_runs.outputs.runtimes }}"; do | |
# Cancel runs based on conditions | |
# Example: cancel runs triggered by the main branch | |
if [[ $run.branch == ${{ steps.extract_branch.outputs.branch }} ]]; then | |
curl -X POST \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/actions/runs/${run.id}/cancel | |
fi | |
done |