Skip to content

Commit

Permalink
feat: Update kill logic (#6)
Browse files Browse the repository at this point in the history
Co-Authored-By: Ruben Laban <[email protected]>
  • Loading branch information
rokroskar and tun0 authored Feb 11, 2020
1 parent e2f086e commit 9456bf1
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ else
fi

# jq queries
jq_run_id=".workflow_runs | .[] | select(.head_branch==\"${BRANCH}\" and .status==\"in_progress\") | .id"
jq_run_ids=".workflow_runs | .[] | select(.head_branch==\"${BRANCH}\" and (.status==\"in_progress\" or .status==\"queued\")) | .id"

# get the github workflow ID

Expand All @@ -42,15 +42,13 @@ workflow_id=${workflow_url##/*/}
echo "workflow id: "$workflow_id

# get the run ids
run_ids=$(curl -s ${GITHUB_API}/repos/${GITHUB_REPOSITORY}/actions/workflows/${workflow_id}/runs -H "${auth_header}" | jq -r "${jq_run_id}")
run_ids=$(curl -s ${GITHUB_API}/repos/${GITHUB_REPOSITORY}/actions/workflows/${workflow_id}/runs -H "${auth_header}" | jq -r "${jq_run_ids}" | sort -n | head -n-1)

echo "run ids: "$run_ids

# cancel the previous runs
for run_id in $run_ids
do
if [ "$run_id" != "$GITHUB_RUN_ID" ]; then
curl -s -X POST -H "${auth_header}" ${GITHUB_API}/repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/cancel
echo "Cancelled run $run_id"
fi
curl -s -X POST -H "${auth_header}" ${GITHUB_API}/repos/${GITHUB_REPOSITORY}/actions/runs/${run_id}/cancel
echo "Cancelled run $run_id"
done

0 comments on commit 9456bf1

Please sign in to comment.