Skip to content

Commit b1cc5b6

Browse files
authored
Merge pull request #3514 from mgxd/ci/tutorial-cancel
CI: Allow tutorial test cancellation
2 parents bf48f77 + 740bdc1 commit b1cc5b6

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

.github/workflows/tutorials.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ jobs:
3030
- name: Check Action was successfully dispatched
3131
id: dispatched
3232
run: |
33-
set -x
3433
START=${{ steps.start.outputs.start_time }}
35-
RUN_ID=$(curl -H "Accept: application/vnd.github+json" \
34+
RUN_ID=$(curl -s -H "Accept: application/vnd.github+json" \
3635
'https://api.github.com/repos/miykael/nipype_tutorial/actions/runs?created=>'${START}'&per_page=1' \
3736
| jq -r '.workflow_runs[0].id')
3837
@@ -42,13 +41,12 @@ jobs:
4241
- name: Check if action completed
4342
timeout-minutes: 120
4443
run: |
45-
set -x
4644
RUN_ID=${{ steps.dispatched.outputs.run_id }}
4745
while :
4846
do
4947
TIMESTAMP=$(date +'%Y-%m-%dT%H:%M:%S%z')
5048
# check status every 5 minutes
51-
STATUS=$(curl -H "Accept: application/vnd.github+json" \
49+
STATUS=$(curl -s -H "Accept: application/vnd.github+json" \
5250
https://api.github.com/repos/miykael/nipype_tutorial/actions/runs/${RUN_ID} \
5351
| jq -r '.conclusion')
5452
case $STATUS in
@@ -65,3 +63,13 @@ jobs:
6563
sleep 300
6664
esac
6765
done
66+
- name: Cancel ongoing run if cancelled or failed
67+
if: ${{ failure() || cancelled() }}
68+
run: |
69+
set -x
70+
RUN_ID=${{ steps.dispatched.outputs.run_id }}
71+
echo "Something went wrong, cancelling dispatched run"
72+
curl -s -X POST \
73+
-H "Accept: application/vnd.github+json" \
74+
-H "Authorization: Bearer ${{ secrets.TUTORIAL_ACCESS_TOKEN }}" \
75+
https://api.github.com/repos/miykael/nipype_tutorial/actions/runs/${RUN_ID}/cancel

0 commit comments

Comments
 (0)