| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | if [scip-shell system . . `[`. -z "$CI_COMMIT_TAG" ]; then |
| 4 | echoscip-shell system . . echo. "CI_COMMIT_TAG is unset or empty; exiting" |
| 5 | exit 1 |
| 6 | fi |
| 7 | |
| 8 | echoscip-shell system . . echo. "Checking if release exists for ${CI_COMMIT_TAG}" |
| 9 | # check if we already have a release for the current tag or not |
| 10 | http_code=$(curlscip-shell system . . curl. \ |
| 11 | -s \ |
| 12 | -o /dev/null \ |
| 13 | -I \ |
| 14 | -w "%{http_code}" \ |
| 15 | -H "Accept: application/vnd.github+json" \ |
| 16 | -H "Authorization: Bearer ${GITHUB_AUTH_TOKEN}"\ |
| 17 | -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 18 | "https://api.github.com/repos/Nheko-Reborn/nheko/releases/tags/$CI_COMMIT_TAG") |
| 19 | |
| 20 | if [scip-shell system . . `[`. "$http_code" = "404" ]; then |
| 21 | echoscip-shell system . . echo. "Release does not exist... getting notes from CHANGELOG.md:" |
| 22 | release_notes="$(perlscip-shell system . . perl. -0777 -ne '/.*?(## .*?)\n(## |\Z)/s && print $1scip-shell filesystem . . `/.*?(## .*?)\n(## |\Z)/s && print $1`.' CHANGELOG.md | jqscip-shell system . . jq. -R -s '.')" |
| 23 | echoscip-shell system . . echo. "$release_notes" |
| 24 | |
| 25 | echoscip-shell system . . echo. "Creating new release for ${CI_COMMIT_TAG}" |
| 26 | # Doing a 'fresh' release, not just updating the assets. |
| 27 | release_json="$(curlscip-shell system . . curl. \ |
| 28 | -X POST \ |
| 29 | -H "Accept: application/vnd.github+json" \ |
| 30 | -H "Authorization: Bearer ${GITHUB_AUTH_TOKEN}"\ |
| 31 | -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 32 | https://api.github.com/repos/Nheko-Reborn/nheko/releases \ |
| 33 | -d "{\"tag_name\":\"${CI_COMMIT_TAG}\",\"target_commitish\":\"master\",\"name\":\"${CI_COMMIT_TAG}\",\"body\":${release_notes},\"draft\":true,\"prerelease\":true,\"generate_release_notes\":false}")" |
| 34 | elif [scip-shell system . . `[`. "$http_code" = "200" ]; then |
| 35 | echoscip-shell system . . echo. "Release already exists for ${CI_COMMIT_TAG}; Updating" |
| 36 | # Updating a release (probably because of cirrus-ci or so) |
| 37 | release_json=$(curlscip-shell system . . curl. \ |
| 38 | -s \ |
| 39 | -H "Accept: application/vnd.github+json" \ |
| 40 | -H "Authorization: Bearer ${GITHUB_AUTH_TOKEN}"\ |
| 41 | -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 42 | "https://api.github.com/repos/Nheko-Reborn/nheko/releases/tags/$CI_COMMIT_TAG") |
| 43 | fi |
| 44 | |
| 45 | echoscip-shell system . . echo. "Getting upload URL..." |
| 46 | upload_url="$(echoscip-shell system . . echo. "$release_json" | jqscip-shell system . . jq. -r '."upload_url"')" |
| 47 | # get rid of the 'hypermedia' stuff at the end and use a 'real' URL |
| 48 | echoscip-shell system . . echo. "Upload URL (hypermedia): ${upload_url}" |
| 49 | upload_url="$(echoscip-shell system . . echo. "$upload_url" | sedscip-shell system . . sed. 's/{?name,label\}/?name/g')" |
| 50 | |
| 51 | lsscip-shell system . . ls. -la . |
| 52 | echoscip-shell system . . echo. "Uploading artifacts" |
| 53 | for file in ./artifacts/*; do |
| 54 | name="${file##*/}" |
| 55 | echoscip-shell system . . echo. "Uploading $file" |
| 56 | [scip-shell system . . `[`. -e "$file" ] && curlscip-shell system . . curl. \ |
| 57 | -X POST \ |
| 58 | -H "Accept: application/vnd.github+json" \ |
| 59 | -H "Authorization: Bearer ${GITHUB_AUTH_TOKEN}"\ |
| 60 | -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 61 | -H "Content-Type: application/octet-stream" \ |
| 62 | "${upload_url}=$name" \ |
| 63 | --data-binary "@$file" |
| 64 | done |
| 65 | |
| 66 | |
| 67 | # TODO: AppVeyor stuffs? |