Skip to content

Commit 475a39f

Browse files
authored
Cancel manual workflow early (#227)
* Cancel run if prepareImage fails
1 parent 8564a25 commit 475a39f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tools/compare_versions/prepare_image.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@
66
#
77
# Usage: export QDRANT_VERSION="ghcr/dev" && ./prepare_image.sh
88

9+
cancel_github_workflow() {
10+
echo "Canceling the current GH workflow run..."
11+
12+
RUN_ID=$(curl -s \
13+
-H "Accept: application/vnd.github+json" \
14+
-H "Authorization: Bearer ${BEARER_TOKEN}" \
15+
-H "X-GitHub-Api-Version: 2022-11-28" \
16+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs" \
17+
| jq '.workflow_runs[] | select(.head_branch=="'${GITHUB_REF#refs/heads/}'") | .id' | head -n 1)
18+
19+
curl -s \
20+
-X POST \
21+
-H "Accept: application/vnd.github+json" \
22+
-H "Authorization: Bearer ${BEARER_TOKEN}" \
23+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs/${RUN_ID}/cancel"
24+
}
925

1026
QDRANT_VERSION=${QDRANT_VERSION:-"ghcr/dev"}
1127

@@ -15,6 +31,7 @@ EVENT_TYPE="benchmark-trigger-image-build"
1531

1632
if [[ -z "${BEARER_TOKEN}" ]]; then
1733
echo "BEARER_TOKEN is not set. Exiting."
34+
cancel_github_workflow
1835
exit 1
1936
fi
2037

@@ -34,6 +51,7 @@ if [[ ${QDRANT_VERSION} == docker/* ]] || [[ ${QDRANT_VERSION} == ghcr/* ]]; the
3451
fi
3552
else
3653
echo "Error: unknown version ${QDRANT_VERSION}. Version name should start with 'docker/' or 'ghcr/'"
54+
cancel_github_workflow
3755
exit 1
3856
fi
3957

@@ -48,6 +66,7 @@ fi
4866

4967
if [[ "${CONTAINER_REGISTRY}" == "docker.io" ]]; then
5068
echo "Impossible to push the image to Docker Container Registry in this workflow."
69+
cancel_github_workflow
5170
exit 1
5271
fi
5372

@@ -65,6 +84,7 @@ counter=0
6584
while ! docker manifest inspect "$IMAGE" > /dev/null 2>&1; do
6685
if [ $counter -ge $MAX_RETRIES ]; then
6786
echo "Reached maximum retries. Exiting."
87+
cancel_github_workflow
6888
exit 2
6989
fi
7090
# sleep for 10 minutes, in seconds

0 commit comments

Comments
 (0)