Debian Codegraph @

.github/scripts/delete_release.sh

raw symbols SCIP
1
2 GIT_COMMIT="${GITHUB_SHA}"
3 GIT_REPO_SLUG="${GITHUB_REPOSITORY}"
4
5 release_url="https://api.github.com/repos/${GIT_REPO_SLUG}/releases/tags/${RELEASE_TAG}"
6 echo "Getting the release ID..."
7 echo "release_url: ${release_url}"
8
9 release_infos=$(curl -XGET --header "Authorization: token ${GITHUB_TOKEN}" "${release_url}")
10 echo "release_infos: ${release_infos}"
11
12 release_id=$(echo "${release_infos}" | grep "\"id\":" | head -n 1 | tr -s " " | cut -f 3 -d" " | cut -f 1 -d ",")
13 echo "release ID: ${release_id}"
14
15 git fetch --tags origin
16 target_commit_sha=$(git rev-list -n 1 "${RELEASE_TAG}")
17 echo "target_commit_sha: ${target_commit_sha}"
18 echo "GIT_COMMIT: ${GIT_COMMIT}"
19
20 if [ "${GIT_COMMIT}" != "${target_commit_sha}" ] ; then
21
22 echo "GIT_COMMIT != target_commit_sha, hence deleting tag and release for '${RELEASE_TAG}'..."
23
24 if [ -n "${release_id}" ]; then
25 delete_release_url="https://api.github.com/repos/${GIT_REPO_SLUG}/releases/${release_id}"
26 echo "Delete the release..."
27 echo "delete_url: ${delete_release_url}"
28 curl -XDELETE \
29 --header "Authorization: token ${GITHUB_TOKEN}" \
30 "${delete_release_url}"
31 fi
32
33 if [ "${RELEASE_TAG}" == "continuous" ] ; then
34 # if this is a continuous build tag, then delete the old tag
35 # in preparation for the new release
36 echo "Delete the tag..."
37 delete_tag_url="https://api.github.com/repos/${GIT_REPO_SLUG}/git/refs/tags/${RELEASE_TAG}"
38 echo "delete_url: ${delete_tag_url}"
39 curl -XDELETE \
40 --header "Authorization: token ${GITHUB_TOKEN}" \
41 "${delete_tag_url}"
42 fi
43
44 fi