From 9456bf167fd55450538667086116f1c577c970eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rok=20Ro=C5=A1kar?= Date: Tue, 11 Feb 2020 14:10:34 +0100 Subject: [PATCH] feat: Update kill logic (#6) Co-Authored-By: Ruben Laban <5331085+tun0@users.noreply.github.com> --- entrypoint.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1466cc8..245d4c0 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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 @@ -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