Stable/v0 0 1 #8
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 self-hosted job | |
on: [ push, pull_request ] | |
jobs: | |
cancel-job: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Cancel self-hosted job | |
run: | | |
# Replace with your repository details | |
REPO_OWNER=zenflux | |
REPO_NAME=zenflux | |
# Get the ID of the running job | |
JOB_ID=$(curl -H "Authorization: token ${{ secrets.ACTIONS_PAT }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/runs" | jq '.workflow_runs[] | select(.status == "queued" and .path == ".github/workflows/main.yml") | .id') | |
# Cancel the job | |
if [ -n "$JOB_ID" ]; then | |
curl -X POST \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/runs/$JOB_ID/cancel" | |
else | |
echo "No queued runs to cancel" | |
fi |