Create github release from tags and upload artifacts as assets

This commit is contained in:
Joseph Donofry 2023-02-20 17:17:37 -05:00
parent 07707e1558
commit b219d6a6b6
No known key found for this signature in database
GPG key ID: E8A1D78EF044B0CB
3 changed files with 74 additions and 6 deletions

View file

@ -0,0 +1,56 @@
#!/bin/sh
if [ -z "$CI_COMMIT_TAG" ]; then
echo "CI_COMMIT_TAG is unset or empty; exiting"
exit 1
fi
# check if we already have a release for the current tag or not
http_code=$(curl \
-s \
-o /dev/null \
-I \
-w "%{http_code}" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_AUTH_TOKEN}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/Nheko-Reborn/nheko/releases/tags/$CI_COMMIT_TAG")
if [ "$http_code" = "404" ]; then
# Doing a 'fresh' release, not just updating the assets.
release_json="$(curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_AUTH_TOKEN}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/Nheko-Reborn/nheko/releases \
-d "{\"tag_name\":\"${CI_COMMIT_TAG}\",\"target_commitish\":\"master\",\"name\":\"${CI_COMMIT_TAG}\",\"body\":\"Description of the release\",\"draft\":true,\"prerelease\":true,\"generate_release_notes\":false}")"
elif [ "$http_code" = "200" ]; then
# Updating a release (probably because of cirrus-ci or so)
release_json=$(curl \
-s \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_AUTH_TOKEN}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/Nheko-Reborn/nheko/releases/tags/$CI_COMMIT_TAG")
fi
upload_url="$(echo "$release_json" | jq ".upload-url")"
# get rid of the 'hypermedia' stuff at the end and use a 'real' URL
upload_url="$(echo "$upload_url" | sed 's/{?name,label\}/?name/g')"
for file in ./artifacts/*; do
name="${file##*/}"
[ -e "$file" ] && curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_AUTH_TOKEN}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"${upload_url}=$name" \
--data-binary "@$name"
done
# TODO: AppVeyor stuffs?

View file

@ -1,3 +1,8 @@
stages:
- build
- sign
- deploy
variables:
CCACHE_COMPILERCHECK: content
CCACHE_DIR: "${CI_PROJECT_DIR}/.ccache"
@ -136,7 +141,7 @@ build-macos:
- "${CCACHE_DIR}"
codesign-macos:
stage: deploy
stage: sign
tags: [macos]
variables:
PLAT: "intel"
@ -153,12 +158,12 @@ codesign-macos:
rules:
- if : '$CI_PIPELINE_TRIGGERED && $CI_COMMIT_REF_PROTECTED == "true"'
variables:
PLAT: "m1"
PLAT: "apple_silicon"
- if : '$CI_COMMIT_BRANCH == "master"'
- if : $CI_COMMIT_TAG
artifacts:
paths:
- artifacts/nheko-${CI_COMMIT_SHORT_SHA}_${PLAT}.dmg
- artifacts/nheko-${CI_COMMIT_SHORT_SHA}-${PLAT}.dmg
- /tmp/notarize*
name: nheko-${CI_COMMIT_SHORT_SHA}-macos
@ -303,3 +308,13 @@ linting:
rules:
- if : '$CI_PIPELINE_TRIGGERED == null'
github-release:
stage: deploy
image: alpine:latest
tags: [docker]
rules:
- if: '$CI_COMMIT_TAG != null'
before_script:
- apk update && apk add jq
script:
- ./.ci/update-github-release.sh

View file

@ -109,9 +109,6 @@ after_build:
- copy nheko-installer.exe nheko-%APPVEYOR_PULL_REQUEST_HEAD_COMMIT%-installer.exe
- ps: .\.ci\upload-nightly.ps1
on_success:
- if "%APPVEYOR_REPO_TAG%" == "true" (curl -T nheko-%APPVEYOR_REPO_TAG_NAME%-installer.exe -uredsky17:%BINTRAY_APIKEY% https://api.bintray.com/content/nheko-reborn/nheko/%APPVEYOR_REPO_TAG_NAME%/nheko/%APPVEYOR_REPO_TAG_NAME%/)
deploy:
- description: "Development builds"
provider: GitHub