Skip to content

Commit

Permalink
feat(ci): Automatically bump brew formula in ci
Browse files Browse the repository at this point in the history
This adds a script to ci to automatically bump the brew formula to the newest version when merged to master.
  • Loading branch information
Johann authored Jul 9, 2019
1 parent 3af4fda commit bc2957a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ jobs:
- run: npm install
- run: npm run build
- run: npm run semantic-release
bump-brew-formula:
macos:
xcode: "9.0"
steps:
- checkout
- run: npm run bump-brew-formula
workflows:
version: 2
build_and_test:
Expand All @@ -73,3 +79,6 @@ workflows:
- integration
- linux
- osx
- bump-brew-formula:
requires:
- release
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"build": "npm run clean && babel lib -d dist",
"build:standalone": "npm run build && pkg --targets node8-macos-x64,node8-linux-x64,node8-win-x64 --out-dir build .",
"build:package": "npm run build:standalone && script/package",
"bump-brew-formula": "script/bump-brew-formula.sh",
"clean": "rimraf dist",
"dev": "nodemon --exec npm run build -w lib",
"lint": "eslint bin lib test",
Expand Down
46 changes: 46 additions & 0 deletions script/bump-brew-formula.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
#
# Script to automatically create a pr in the Homebrew/homebrew-core repo to update the contentful-cli formula
# (works only for macOS, with HOMEBREW_GITHUB_API_TOKEN set and a valid ssh key)

command -v brew >/dev/null 2>&1 || /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
brew install coreutils

DRY_RUN=" --dry-run"
if [ "${CIRCLE_BRANCH}" == "master" ]; then DRY_RUN=""; fi

if [ ! $(git config --global user.email) ]; then git config --global user.email "[email protected]"; fi
if [ ! $(git config --global user.name) ]; then git config --global user.name "contentful"; fi

package="contentful-cli"
version=$(npm show ${package} version)
url="https://registry.npmjs.org/${package}/-/${package}-${version}.tgz"
sha256=$(curl -s ${url} | gsha256sum | awk '{ print $1 }')

# send stderr to variable, pass stdout through
{
err=$(
brew bump-formula-pr --strict ${package} --url=${url} --sha256=${sha256} --no-browse --message="This PR was automatically created via a script. Contact @contentful with any questions." ${DRY_RUN} 2>&1 >&3 3>&-
)
} 3>&1

echo "$err"

function has_substring() {
[[ "$1" =~ "$2" ]]
}

if has_substring "$err" "Error:"; then
# fail soft for CI (if version not bumped, pr already opened or running on feature branch)
if has_substring "$err" "You probably need to bump this formula manually"; then
echo "Soft Fail${DRY_RUN}: Potentially manual PR required"
exit 0
fi
if has_substring "$err" "Duplicate PRs should not be opened."; then
echo "Soft Fail${DRY_RUN}: Duplicate PR found"
exit 0
fi
echo "Hard Fail${DRY_RUN}:"
exit 1
fi

0 comments on commit bc2957a

Please sign in to comment.