Skip to content

Stable/v0 0 1

Stable/v0 0 1 #8

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