github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/clients/ruby/.github/workflows/release.sh (about) 1 #!/bin/bash 2 3 set -eo pipefail 4 5 [ -z "${GITHUB_TOKEN}" ] && { echo "Missing input.token!"; exit 2; } 6 [ -z "${OWNER}" ] && { echo "Missing input.owner!"; exit 2; } 7 8 # ----------- 9 10 echo "Build release $VERSION" 11 12 # ----------- 13 14 echo "Setting up gem version" 15 sed -e "s/1.0.0/${VERSION}/g" ./version.rb.template > ./lib/phrase/version.rb 16 rm ./version.rb.template 17 18 # ----------- 19 20 echo "Building the gem" 21 gem build phrase.gemspec 22 23 # Create release 24 function create_release_data() 25 { 26 cat <<EOF 27 { 28 "tag_name": "${VERSION}", 29 "name": "${VERSION}", 30 "draft": true, 31 "prerelease": false 32 } 33 EOF 34 } 35 36 echo "Create release $VERSION" 37 api_url="https://api.github.com/repos/phrase/phrase-ruby/releases" 38 response="$(curl -H "Authorization: token ${GITHUB_TOKEN}" --data "$(create_release_data)" ${api_url})" 39 release_id=$(echo $response | python -c "import sys, json; print(json.load(sys.stdin).get('id', ''))") 40 41 if [ -z "$release_id" ] 42 then 43 echo "Failed to create GitHub release" 44 echo $response 45 exit 1 46 else 47 echo "New release created created with id: ${release_id}" 48 fi 49 50 echo "Uploading ${file}" 51 file=phrase-${VERSION}.gem 52 asset="https://uploads.github.com/repos/phrase/phrase-ruby/releases/${release_id}/assets?name=$(basename "$file")" 53 curl --data-binary @"$file" -H "Authorization: token ${GITHUB_TOKEN}" -H "Content-Type: application/octet-stream" $asset > /dev/null 54 echo Hash: $(sha256sum $file) 55 56 # ----------- 57 58 echo "Setting up access to RubyGems" 59 mkdir -p ~/.gem 60 touch ~/.gem/credentials 61 chmod 600 ~/.gem/credentials 62 echo ":rubygems_api_key: ${RUBYGEMS_TOKEN}" > ~/.gem/credentials 63 64 echo "Pushing the built gem to RubyGems" 65 gem push phrase-${VERSION}.gem 66 67 # ----------- 68 # file name and specs must match repo name for Github Packages 69 70 echo "Building the phrase-ruby gem" 71 sed -e "s/\"phrase\"/\"phrase-ruby\"/g" ./phrase.gemspec > ./phrase-ruby.gemspec 72 gem build phrase-ruby.gemspec 73 74 echo "Setting up access to GitHub Package Registry" 75 mkdir -p ~/.gem 76 touch ~/.gem/credentials 77 chmod 600 ~/.gem/credentials 78 echo ":github: Bearer ${GITHUB_TOKEN}" > ~/.gem/credentials 79 80 echo "Pushing the built gem to GitHub Package Registry" 81 gem push --key github --host https://rubygems.pkg.github.com/${OWNER} phrase-ruby-${VERSION}.gem 82 83 echo "Publishing release" 84 curl \ 85 --silent \ 86 -X PATCH \ 87 -H "Authorization: token ${GITHUB_TOKEN}" \ 88 -H "Accept: application/vnd.github.v3+json" \ 89 "https://api.github.com/repos/phrase/phrase-ruby/releases/${release_id}" \ 90 -d '{"draft": false}' > /dev/null 91 92 echo "Release successful"