2020-08-29 22:33:23 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-11-22 16:12:19 +01:00
|
|
|
repo="sschueller/peertube-android"
|
2020-08-29 22:33:23 +02: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..."
|
2021-02-06 15:08:34 +01:00
|
|
|
echo "${postdata}" | jq .
|
2020-08-29 22:33:23 +02:00
|
|
|
|
|
|
|
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}")
|
2021-02-06 15:08:34 +01:00
|
|
|
echo "${res}" | jq .
|
2020-08-29 22:33:23 +02:00
|
|
|
|
|
|
|
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
|