Debian Codegraph @

script/create_version_artifacts.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 set -euo pipefail
4
5 root=$(git rev-parse --show-toplevel)
6
7 function list_archives() {
8 jq < dist/artifacts.json -r '.[] | select(.type == "Archive") | .name, .path, .goos, .goarch'
9 }
10
11 function handle_archive() {
12 while read -r filename; read -r path; read -r goos; read -r goarch; do
13 local url=$(get_archive_url ${filename})
14 if [ -z "${url}" ]; then echo "no archive for ${filename}"; continue; fi
15 local sig=$(get_signature ${path})
16
17 apictl create version-artifact \
18 --project ${project} \
19 --major $(get_version_major) \
20 --minor $(get_version_minor) \
21 --patch $(get_version_patch) \
22 --sha256 $(get_sha256sum ${path}) \
23 --url ${url} \
24 --os ${goos} \
25 --arch ${goarch} \
26 --sig ${sig}
27 done
28 }
29
30 function get_archive_url() {
31 local filename=${1}
32 gh api graphql -F owner=${owner} -F name=${project} -F tag="v${tag}" -F filename=${filename} -f query='
33 query($name: String!, $owner: String!, $tag: String!, $filename: String!) {
34 repository(name: $name, owner: $owner) {
35 release(tagName: $tag) {
36 releaseAssets(first: 1, name: $filename) {
37 nodes {
38 downloadUrl
39 }
40 }
41 }
42 }
43 }' --jq '.data.repository.release.releaseAssets.nodes[0].downloadUrl'
44 }
45
46 function get_sha256sum() {
47 local filename=${1}
48 shasum -a 256 ${filename} | cut -d " " -f 1
49 }
50
51 function get_signature() {
52 local filename=${1}
53 cat ${filename}.sig
54 }
55
56 function get_version_major() {
57 major=`echo ${tag} | cut -d. -f1`
58 echo "${major}"
59 }
60
61 function get_version_minor() {
62 minor=`echo ${tag} | cut -d. -f2`
63 echo "${minor}"
64 }
65
66 function get_version_patch() {
67 patch=`echo ${tag} | cut -d. -f3`
68 echo "${patch}"
69 }
70
71 function get_version() {
72 jq < dist/metadata.json -r '.version'
73 }
74
75 function get_project_name() {
76 jq < dist/metadata.json -r '.project_name'
77 }
78
79 function main() {
80 owner=humanlogio
81 project=$(get_project_name)
82 tag=$(get_version)
83
84 list_archives | handle_archive
85
86 apictl create published-version \
87 --project ${project} \
88 --channel latest \
89 --version $(get_version)
90 }
91
92 main