thorium-fork/ci-scripts/make-github-release.sh

53 lines
1.7 KiB
Bash
Raw Normal View History

2020-08-29 13:33:23 -07:00
#!/usr/bin/env bash
repo="sschueller/peertube-android"
2020-08-29 13:33:23 -07:00
username="sschueller"
# set work dir
cd "$(dirname "${BASH_SOURCE[0]}")/.."
# get release notes
release_notes=$(cat fastlane/metadata/android/en-US/changelogs/"${VERSION_CODE}".txt)
echo "Commit Tag: ${CI_COMMIT_TAG}"
if [[ "${CI_COMMIT_TAG}" = "" ]] ; then
echo "No CI_COMMIT_TAG" >&2; exit 1
fi
# Check release exists?
echo "Check release exists..."
res=$(curl -X GET -s -H "Content-Type:application/json" -H "Authorization: token ${github_token}" https://${username}@api.github.com/repos/${repo}/releases/tags/$CI_COMMIT_TAG)
rel=$(echo "${res}" | jq ".id")
if ! [[ "${rel}" = "null" ]] || [[ "${rel}" = "" ]] ; then
echo "Release exists ${CI_COMMIT_TAG}, stopping" >&2; exit 1
else
echo "Release does not exist.";
fi
# escape release notes
release_notes=$(echo "${release_notes}" | jq -aRs .)
postdata="{\"tag_name\":\"${CI_COMMIT_TAG}\",\"target_commitish\":\"master\",\"name\":\"Release ${CI_COMMIT_TAG}\",\"body\":${release_notes},\"draft\":false,\"prerelease\":false}"
# Generate Release
echo "Generate Release..."
echo "${postdata}" | jq
res=$(curl -s -X POST -H "Content-Type:application/json" -H "Authorization: token ${github_token}" https://${username}@api.github.com/repos/${repo}/releases -d "${postdata}")
echo "${res}" | jq
release_id=$(echo "${res}" | jq '.id')
echo "Release ID: ${release_id}"
re='^[0-9]+$'
if ! [[ ${release_id} =~ ${re} ]] ; then
echo "Invalid ID ${release_id}" >&2; exit 1
fi
echo "Attaching artifact..."
# Attach artifact
curl -X POST -H "Authorization: token ${github_token}" -F 'data=@app/build/outputs/apk/release/app-release.apk' https://${username}@uploads.github.com/repos/${repo}/releases/"${release_id}"/assets?name=app-release.apk