github.com/pquerna/agent@v2.1.8+incompatible/scripts/release-homebrew.sh (about) 1 #!/usr/bin/env bash 2 3 # Must be executed after github-release.sh as it depends on release meta-data 4 5 set -euo pipefail 6 7 GITHUB_RELEASE_VERSION=$(buildkite-agent meta-data get github_release_version) 8 GITHUB_RELEASE_TYPE=$(buildkite-agent meta-data get github_release_type) 9 10 if [[ "$GITHUB_RELEASE_TYPE" != "stable" ]]; then 11 BREW_RELEASE_TYPE="devel" 12 else 13 BREW_RELEASE_TYPE="stable" 14 fi 15 16 # Allows you to pipe JSON in and fetch keys using Ruby hash syntax 17 # 18 # Examples: 19 # 20 # echo '{"key":{"subkey": ["value"]}}' | parse_json '["key"]["subkey"].first' 21 function parse_json { 22 ruby -rjson -e "print JSON.parse(\$<.read)$1" 23 } 24 25 function to_json { 26 ruby -rjson -e "print \$<.read.to_json" 27 } 28 29 echo '--- Getting agent version from build meta data' 30 31 export FULL_AGENT_VERSION=$(buildkite-agent meta-data get "agent-version-full") 32 export AGENT_VERSION=$(buildkite-agent meta-data get "agent-version") 33 export BUILD_VERSION=$(buildkite-agent meta-data get "agent-version-build") 34 35 echo "Full agent version: $FULL_AGENT_VERSION" 36 echo "Agent version: $AGENT_VERSION" 37 echo "Build version: $BUILD_VERSION" 38 39 BINARY_NAME=buildkite-agent-darwin-386-$AGENT_VERSION.tar.gz 40 41 DOWNLOAD_URL="https://github.com/buildkite/agent/releases/download/v$GITHUB_RELEASE_VERSION/$BINARY_NAME" 42 FORMULA_FILE=./pkg/buildkite-agent.rb 43 UPDATED_FORMULA_FILE=./pkg/buildkite-agent-updated.rb 44 45 echo "--- :package: Fetching artifact SHA from Github release step" 46 47 echo "Fetching SHA" 48 RELEASE_SHA=$(buildkite-agent artifact shasum "releases/$BINARY_NAME") 49 50 echo "Release SHA1: $RELEASE_SHA" 51 52 echo "--- :octocat: Fetching current homebrew formula from Github Contents API" 53 54 CONTENTS_API_RESPONSE=$(curl "https://api.github.com/repos/buildkite/homebrew-buildkite/contents/buildkite-agent.rb?access_token=$GITHUB_RELEASE_ACCESS_TOKEN") 55 56 echo "Base64 decoding Github response into $FORMULA_FILE" 57 58 echo $CONTENTS_API_RESPONSE | parse_json '["content"]' | base64 -d > $FORMULA_FILE 59 60 echo "--- :ruby: Updating formula file" 61 62 echo "Homebrew release type: $BREW_RELEASE_TYPE" 63 echo "Homebrew release version: $GITHUB_RELEASE_VERSION" 64 echo "Homebrew release download URL: $DOWNLOAD_URL" 65 echo "Homebrew release download SHA: $RELEASE_SHA" 66 67 cat $FORMULA_FILE | 68 ./scripts/utils/update-homebrew-formula.rb $BREW_RELEASE_TYPE $GITHUB_RELEASE_VERSION $DOWNLOAD_URL $RELEASE_SHA \ 69 > $UPDATED_FORMULA_FILE 70 71 echo "--- :rocket: Commiting new formula to master via Github Contents API" 72 73 UPDATED_FORMULA_BASE64=$(base64 --wrap=0 $UPDATED_FORMULA_FILE) 74 MASTER_FORMULA_SHA=$(echo $CONTENTS_API_RESPONSE | parse_json '["sha"]') 75 76 echo "Old formula SHA: $MASTER_FORMULA_SHA" 77 78 echo "{ 79 \"message\": \"buildkite-agent $GITHUB_RELEASE_VERSION\", 80 \"sha\": \"$MASTER_FORMULA_SHA\", 81 \"content\": \"$UPDATED_FORMULA_BASE64\", 82 \"branch\": \"master\" 83 }" > pkg/github_post_data.json 84 85 86 echo "Posting JSON to Github Contents API" 87 curl -X PUT "https://api.github.com/repos/buildkite/homebrew-buildkite/contents/buildkite-agent.rb?access_token=$GITHUB_RELEASE_ACCESS_TOKEN" \ 88 -H "Content-Type: application/json" \ 89 --data-binary "@pkg/github_post_data.json" \ 90 --fail