Debian Codegraph @

.github/workflows/tools/upload-build

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 set +x # Do not leak information
4
5 # Exit immediately if one of the files given as arguments is not there
6 # because we don't want to delete the existing release if we don't have
7 # the new files that should be uploaded
8 for file in "$@"
9 do
10 if [scip-shell system . . `[`. ! -e "$file" ]
11 then echoscip-shell system . . echo. "$file is missing, giving up." >&2; exit 1
12 fi
13 done
14
15 if [scip-shell system . . `[`. $# -eq 0 ]; then
16 echoscip-shell system . . echo. "No artifacts to use for release, giving up."
17 exit 0
18 fi
19
20 if command -v sha256sum >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 ; then
21 shatool="sha256sum"
22 elif command -v shasum >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 ; then
23 shatool="shasum -a 256" # macOS fallback
24 else
25 echoscip-shell system . . echo. "Neither sha256sum nor shasum is available, cannot check hashes"
26 fi
27
28 if [[ ${GITHUB_REF} == refs/heads/* ]]; then
29 GITHUB_BRANCH=${GITHUB_REF##*/}
30 elif [[ ${GITHUB_REF} == refs/tags/* ]]; then
31 GITHUB_TAG=${GITHUB_REF##*/}
32 fi
33
34 # The calling script (usually .travis.yml) can set a suffix to be used for
35 # the tag and release name. This way it is possible to have a release for
36 # the output of the CI/CD pipeline (marked as 'continuous') and also test
37 # builds for other branches.
38 # If this build was triggered by a tag, call the result a Release
39 if [scip-shell system . . `[`. ! -z "$UPLOADTOOL_SUFFIX" ] ; then
40 if [scip-shell system . . `[`. "$UPLOADTOOL_SUFFIX" = "${GITHUB_TAG}" ] ; then
41 RELEASE_NAME="${GITHUB_TAG}"
42 RELEASE_TITLE="Release build (${GITHUB_TAG})"
43 is_prerelease="false"
44 else
45 RELEASE_NAME="continuous-$UPLOADTOOL_SUFFIX"
46 RELEASE_TITLE="Continuous build ($UPLOADTOOL_SUFFIX)"
47 is_prerelease="true"
48 fi
49 else
50 if [scip-shell system . . `[`. "${GITHUB_TAG}" != "" ]; then
51 RELEASE_NAME="${GITHUB_TAG}"
52 RELEASE_TITLE="Release build (${GITHUB_TAG})"
53 is_prerelease="false"
54 elif [scip-shell system . . `[`. "${GITHUB_BRANCH}" != "" ] && [scip-shell system . . `[`. "${GITHUB_BRANCH}" != "master" ]; then
55 RELEASE_NAME="continuous-${GITHUB_BRANCH}"
56 RELEASE_TITLE="Continuous build (${GITHUB_BRANCH})"
57 is_prerelease="true"
58 else
59 RELEASE_NAME="continuous" # Do not use "latest" as it is reserved by GitHub
60 RELEASE_TITLE="Continuous build"
61 is_prerelease="true"
62 fi
63 fi
64
65 # Do not upload non-master branch builds
66 if [scip-shell system . . `[`. "${GITHUB_EVENT_NAME}" == "pull_request" ] ; then
67 echoscip-shell system . . echo. "Release uploading disabled for pull requests, uploading to transfer.sh instead"
68 rmscip-shell system . . rm. -f ./uploaded-to
69 for FILE in "$@" ; do
70 BASENAME="$(basenamescip-shell system . . basename. "${FILE}")"
71 curlscip-shell system . . curl. --upload-file $FILE "https://transfer.sh/$BASENAME" > ./one-upload
72 echoscip-shell system . . echo. "$(catscip-shell system . . cat. ./one-upload)" # this way we get a newline
73 echoscip-shell system . . echo. -n "$(catscip-shell system . . cat. ./one-upload)\\n" >> ./uploaded-to # this way we get a \n but no newline
74 done
75 $shatool "$@"
76 exit 0
77 fi
78
79 tag_url="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/git/refs/tags/${RELEASE_NAME}"
80 tag_infos=$(curlscip-shell system . . curl. -XGET --header "Authorization: token ${RELEASE_TOKEN}" "${tag_url}")
81 echoscip-shell system . . echo. "tag_infos: $tag_infos"
82 tag_sha=$(echoscip-shell system . . echo. "$tag_infos" | grepscip-shell system . . grep. '"sha":' | headscip-shell system . . head. -n 1 | cutscip-shell system . . cut. -d '"' -f 4 | cutscip-shell system . . cut. -d '{' -f 1)
83 echoscip-shell system . . echo. "tag_sha: $tag_sha"
84
85 release_url="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${RELEASE_NAME}"
86 echoscip-shell system . . echo. "Getting the release ID..."
87 echoscip-shell system . . echo. "release_url: $release_url"
88 release_infos=$(curlscip-shell system . . curl. -XGET --header "Authorization: token ${RELEASE_TOKEN}" "${release_url}")
89 echoscip-shell system . . echo. "release_infos: $release_infos"
90 release_id=$(echoscip-shell system . . echo. "$release_infos" | grepscip-shell system . . grep. "\"id\":" | headscip-shell system . . head. -n 1 | trscip-shell system . . tr. -s " " | cutscip-shell system . . cut. -f 3 -d" " | cutscip-shell system . . cut. -f 1 -d ",")
91 echoscip-shell system . . echo. "release ID: $release_id"
92 upload_url=$(echoscip-shell system . . echo. "$release_infos" | grepscip-shell system . . grep. '"upload_url":' | headscip-shell system . . head. -n 1 | cutscip-shell system . . cut. -d '"' -f 4 | cutscip-shell system . . cut. -d '{' -f 1)
93 echoscip-shell system . . echo. "upload_url: $upload_url"
94 release_url=$(echoscip-shell system . . echo. "$release_infos" | grepscip-shell system . . grep. '"url":' | headscip-shell system . . head. -n 1 | cutscip-shell system . . cut. -d '"' -f 4 | cutscip-shell system . . cut. -d '{' -f 1)
95 echoscip-shell system . . echo. "release_url: $release_url"
96 target_commit_sha=$(echoscip-shell system . . echo. "$release_infos" | grepscip-shell system . . grep. '"target_commitish":' | headscip-shell system . . head. -n 1 | cutscip-shell system . . cut. -d '"' -f 4 | cutscip-shell system . . cut. -d '{' -f 1)
97 echoscip-shell system . . echo. "target_commit_sha: $target_commit_sha"
98
99 if [scip-shell system . . `[`. "${GITHUB_SHA}" != "$target_commit_sha" ] ; then
100
101 echoscip-shell system . . echo. "${GITHUB_SHA} != target_commit_sha, hence deleting ${RELEASE_NAME}..."
102
103 if [scip-shell system . . `[`. ! -z "$release_id" ]; then
104 delete_url="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/$release_id"
105 echoscip-shell system . . echo. "Delete the release..."
106 echoscip-shell system . . echo. "delete_url: $delete_url"
107 curlscip-shell system . . curl. -XDELETE \
108 --header "Authorization: token ${RELEASE_TOKEN}" \
109 "${delete_url}"
110 fi
111
112 # echo "Checking if release with the same name is still there..."
113 # echo "release_url: $release_url"
114 # curl -XGET --header "Authorization: token ${RELEASE_TOKEN}" \
115 # "$release_url"
116
117 if [scip-shell system . . `[`. "$is_prerelease" = "true" ] ; then
118 # if this is a continuous build tag, then delete the old tag
119 # in preparation for the new release
120 echoscip-shell system . . echo. "Delete the tag..."
121 delete_url="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/git/refs/tags/${RELEASE_NAME}"
122 echoscip-shell system . . echo. "delete_url: $delete_url"
123 curlscip-shell system . . curl. -XDELETE \
124 --header "Authorization: token ${RELEASE_TOKEN}" \
125 "${delete_url}"
126 fi
127
128 echoscip-shell system . . echo. "Create release..."
129
130 if [scip-shell system . . `[`. -z "${GITHUB_BRANCH}" ] ; then
131 {GITHUB_BRANCH}="master"
132 fi
133
134 if [scip-shell system . . `[`. ! -z "${GITHUB_RUN_ID}" ] ; then
135 if [scip-shell system . . `[`. -z "${UPLOADTOOL_BODY+x}" ] ; then
136 BODY="GitHub Actions build log: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
137 else
138 BODY="$UPLOADTOOL_BODY"
139 fi
140 else
141 BODY="$UPLOADTOOL_BODY"
142 fi
143
144 release_infos=$(curlscip-shell system . . curl. -H "Authorization: token ${RELEASE_TOKEN}" \
145 --data '{"tag_name": "'"${RELEASE_NAME}"'","target_commitish": "'"${GITHUB_SHA}"'","name": "'"${RELEASE_TITLE}"'","body": "'"${BODY}"'","draft": false,"prerelease": '$is_prerelease'}' "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases")
146
147 echoscip-shell system . . echo. "$release_infos"
148
149 unset upload_url
150 upload_url=$(echoscip-shell system . . echo. "$release_infos" | grepscip-shell system . . grep. '"upload_url":' | headscip-shell system . . head. -n 1 | cutscip-shell system . . cut. -d '"' -f 4 | cutscip-shell system . . cut. -d '{' -f 1)
151 echoscip-shell system . . echo. "upload_url: $upload_url"
152
153 unset release_url
154 release_url=$(echoscip-shell system . . echo. "$release_infos" | grepscip-shell system . . grep. '"url":' | headscip-shell system . . head. -n 1 | cutscip-shell system . . cut. -d '"' -f 4 | cutscip-shell system . . cut. -d '{' -f 1)
155 echoscip-shell system . . echo. "release_url: $release_url"
156
157 fi # if [ "${GITHUB_SHA}" != "$tag_sha" ]
158
159 if [scip-shell system . . `[`. -z "$release_url" ] ; then
160 echoscip-shell system . . echo. "Cannot figure out the release URL for ${RELEASE_NAME}"
161 exit 1
162 fi
163
164 echoscip-shell system . . echo. "Upload binaries to the release..."
165
166 for FILE in "$@" ; do
167 FULLNAME="${FILE}"
168 BASENAME="$(basenamescip-shell system . . basename. "${FILE}")"
169 curlscip-shell system . . curl. -H "Authorization: token ${RELEASE_TOKEN}" \
170 -H "Accept: application/vnd.github.manifold-preview" \
171 -H "Content-Type: application/octet-stream" \
172 --data-binary @$FULLNAME \
173 "$upload_url?name=$BASENAME"
174 echoscip-shell system . . echo. ""
175 done
176
177 $shatool "$@"
178
179 if [scip-shell system . . `[`. "${GITHUB_SHA}" != "$tag_sha" ] ; then
180 echoscip-shell system . . echo. "Publish the release..."
181
182 release_infos=$(curlscip-shell system . . curl. -H "Authorization: token ${RELEASE_TOKEN}" \
183 --data '{"draft": false}' "$release_url")
184
185 echoscip-shell system . . echo. "$release_infos"
186 fi # if [ "${GITHUB_SHA}" != "$tag_sha" ]