| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 3 | set -euo pipefail |
| 4 | |
| 5 | root=$(gitscip-shell system . . git. rev-parse --show-toplevel) |
| 6 | |
| 7 | function list_archivesscip-shell shell shell-project 0.0.0 list_archives().() { |
| 8 | jqscip-shell system . . jq. < dist/artifacts.json -r '.[] | select(.type == "Archive") | .name, .path, .goos, .goarch' |
| 9 | } |
| 10 | |
| 11 | function handle_archivescip-shell shell shell-project 0.0.0 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 [scip-shell system . . `[`. -z "${url}" ]; then echoscip-shell system . . 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_urlscip-shell shell shell-project 0.0.0 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_sha256sumscip-shell shell shell-project 0.0.0 get_sha256sum().() { |
| 47 | local filename=${1} |
| 48 | shasumscip-shell system . . shasum. -a 256 ${filename} | cutscip-shell system . . cut. -d " " -f 1 |
| 49 | } |
| 50 | |
| 51 | function get_signaturescip-shell shell shell-project 0.0.0 get_signature().() { |
| 52 | local filename=${1} |
| 53 | catscip-shell system . . cat. ${filename}.sig |
| 54 | } |
| 55 | |
| 56 | function get_version_majorscip-shell shell shell-project 0.0.0 get_version_major().() { |
| 57 | major=`echoscip-shell system . . echo. ${tag} | cutscip-shell system . . cut. -d. -f1` |
| 58 | echoscip-shell system . . echo. "${major}" |
| 59 | } |
| 60 | |
| 61 | function get_version_minorscip-shell shell shell-project 0.0.0 get_version_minor().() { |
| 62 | minor=`echoscip-shell system . . echo. ${tag} | cutscip-shell system . . cut. -d. -f2` |
| 63 | echoscip-shell system . . echo. "${minor}" |
| 64 | } |
| 65 | |
| 66 | function get_version_patchscip-shell shell shell-project 0.0.0 get_version_patch().() { |
| 67 | patch=`echoscip-shell system . . echo. ${tag} | cutscip-shell system . . cut. -d. -f3` |
| 68 | echoscip-shell system . . echo. "${patch}" |
| 69 | } |
| 70 | |
| 71 | function get_versionscip-shell shell shell-project 0.0.0 get_version().() { |
| 72 | jqscip-shell system . . jq. < dist/metadata.json -r '.version' |
| 73 | } |
| 74 | |
| 75 | function get_project_namescip-shell shell shell-project 0.0.0 get_project_name().() { |
| 76 | jqscip-shell system . . jq. < dist/metadata.json -r '.project_name' |
| 77 | } |
| 78 | |
| 79 | function mainscip-shell shell shell-project 0.0.0 main().() { |
| 80 | owner=humanlogio |
| 81 | project=$(get_project_namescip-shell shell shell-project 0.0.0 get_project_name().) |
| 82 | tag=$(get_versionscip-shell shell shell-project 0.0.0 get_version().) |
| 83 | |
| 84 | list_archivesscip-shell shell shell-project 0.0.0 list_archives(). | handle_archivescip-shell shell shell-project 0.0.0 handle_archive(). |
| 85 | |
| 86 | apictl create published-version \ |
| 87 | --project ${project} \ |
| 88 | --channel latest \ |
| 89 | --version $(get_versionscip-shell shell shell-project 0.0.0 get_version().) |
| 90 | } |
| 91 | |
| 92 | mainscip-shell shell shell-project 0.0.0 main(). |