-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploying from phrase/openapi@97fc6a90
- Loading branch information
Phrase
committed
May 21, 2020
1 parent
9aec7e4
commit 33ac876
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
|
||
set -eo pipefail | ||
|
||
echo "Build release $VERSION" | ||
|
||
echo "Setting up gem version" | ||
sed -e "s/1.0.0/${VERSION}/g" ./version.rb.template > ./lib/phrase/version.rb | ||
rm ./version.rb.template | ||
|
||
[ -z "${GITHUB_TOKEN}" ] && { echo "Missing input.token!"; exit 2; } | ||
[ -z "${OWNER}" ] && { echo "Missing input.owner!"; exit 2; } | ||
|
||
echo "Setting up access to GitHub Package Registry" | ||
mkdir -p ~/.gem | ||
touch ~/.gem/credentials | ||
chmod 600 ~/.gem/credentials | ||
echo ":github: Bearer ${GITHUB_TOKEN}" >> ~/.gem/credentials | ||
|
||
echo "Building the gem" | ||
gem build *.gemspec | ||
|
||
echo "Pushing the built gem to GitHub Package Registry" | ||
gem push --key github --host "https://rubygems.pkg.github.com/${OWNER}" *.gem | ||
|
||
# Create release | ||
function create_release_data() | ||
{ | ||
cat <<EOF | ||
{ | ||
"tag_name": "${VERSION}", | ||
"name": "${VERSION}", | ||
"draft": true, | ||
"prerelease": false | ||
} | ||
EOF | ||
} | ||
|
||
echo "Create release $VERSION" | ||
api_url="https://api.github.com/repos/phrase/phrase-ruby/releases?access_token=${GITHUB_TOKEN}" | ||
response="$(curl --data "$(create_release_data)" ${api_url})" | ||
release_id=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['id']") | ||
|
||
if [ -z "$release_id" ] | ||
then | ||
echo "Failed to create GitHub release" | ||
echo $response | ||
exit 1 | ||
else | ||
echo "New release created created with id: ${release_id}" | ||
fi | ||
|
||
# Upload artifacts | ||
DIST_DIR="." | ||
for file in "$DIST_DIR"/*.gem; do | ||
echo "Uploading ${file}" | ||
asset="https://uploads.github.com/repos/phrase/phrase-ruby/releases/${release_id}/assets?name=$(basename "$file")&access_token=${GITHUB_TOKEN}" | ||
curl --data-binary @"$file" -H "Content-Type: application/octet-stream" $asset > /dev/null | ||
echo Hash: $(sha256sum $file) | ||
done | ||
|
||
echo "Release successful" |