Skip to content

Commit

Permalink
refactor: checkout homebrew-core in action instead of script (coder#4996
Browse files Browse the repository at this point in the history
)

* refactor: checkout homebrew-core in action instead of script

This moves the git clone step from the `brew-bump.sh` script into the
`npm-brew.yaml` as part of the job using actions/checkout instead.

* refactor: clean up brew-bump.sh script

* fixup

* fixup!: remove step to clean up homebrew repo

* fixup!: use correct ./ci path steps-lib.sh

* fixup!: add exit code 0 for duplicate PRs
  • Loading branch information
jsjoeio authored Mar 21, 2022
1 parent 60ebf2f commit be72787
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 35 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/npm-brew.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,20 @@ jobs:
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master

- uses: actions/checkout@v3
- name: Checkout code-server
uses: actions/checkout@v3

- name: Checkout cdrci/homebrew-core
uses: actions/checkout@v3
with:
repository: cdrci/homebrew-core
path: homebrew-core

- name: Configure git
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Bump code-server homebrew version
env:
HOMEBREW_GITHUB_API_TOKEN: ${{secrets.HOMEBREW_GITHUB_API_TOKEN}}
Expand Down
56 changes: 22 additions & 34 deletions ci/steps/brew-bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
set -euo pipefail

main() {
cd "$(dirname "$0")/../.."
REPO="homebrew-core"
GITHUB_USERNAME="cdrci"
UPSTREAM_USERNAME_AND_REPO="Homebrew/$REPO"
# Only sourcing this so we get access to $VERSION
source ./ci/lib.sh
source ./ci/steps/steps-lib.sh
Expand All @@ -21,25 +23,18 @@ main() {
exit 1
fi

# NOTE: we need to make sure coderci/homebrew-core
# is up-to-date
# otherwise, brew bump-formula-pr will use an
# outdated base
echo "Cloning coderci/homebrew-core"
git clone https://github.com/coderci/homebrew-core.git

# Make sure the git clone step is successful
if directory_exists "homebrew-core"; then
echo "git clone failed. Cannot find homebrew-core directory."
if ! directory_exists "$REPO"; then
echo "git clone failed. Cannot find $REPO directory."
ls -la
exit 1
fi

echo "Changing into homebrew-core directory"
pushd homebrew-core && pwd
echo "Changing into $REPO directory"
pushd "$REPO" && pwd

echo "Adding Homebrew/homebrew-core"
git remote add upstream https://github.com/Homebrew/homebrew-core.git
echo "Adding $UPSTREAM_USERNAME_AND_REPO"
git remote add upstream "https://github.com/$UPSTREAM_USERNAME_AND_REPO.git"

# Make sure the git remote step is successful
if ! git config remote.upstream.url > /dev/null; then
Expand All @@ -50,24 +45,22 @@ main() {
fi

# TODO@jsjoeio - can I somehow check that this succeeded?
echo "Fetching upstream Homebrew/hombrew-core commits"
git fetch upstream
echo "Fetching upstream $UPSTREAM_USERNAME_AND_REPO commits"
git fetch upstream master

# TODO@jsjoeio - can I somehow check that this succeeded?
echo "Merging in latest Homebrew/homebrew-core changes"
echo "Merging in latest $UPSTREAM_USERNAME_AND_REPO changes branch master"
git merge upstream/master

echo "Pushing changes to coderci/homebrew-core fork on GitHub"

# GIT_ASKPASS lets us use the password when pushing without revealing it in the process list
# See: https://serverfault.com/a/912788
PATH_TO_GIT_ASKPASS="$HOME/git-askpass.sh"
# Source: https://serverfault.com/a/912788
# shellcheck disable=SC2016,SC2028
echo 'echo $HOMEBREW_GITHUB_API_TOKEN' > "$PATH_TO_ASKPASS"
echo 'echo $HOMEBREW_GITHUB_API_TOKEN' > "$PATH_TO_GIT_ASKPASS"

# Make sure the git-askpass.sh file creation is successful
if file_exists "$PATH_TO_GIT_ASKPASS"; then
if ! file_exists "$PATH_TO_GIT_ASKPASS"; then
echo "git-askpass.sh not found in $HOME."
ls -la "$HOME"
exit 1
Expand All @@ -77,38 +70,33 @@ main() {
chmod +x "$PATH_TO_GIT_ASKPASS"

# Make sure the git-askpass.sh file is executable
if is_executable "$PATH_TO_GIT_ASKPASS"; then
if ! is_executable "$PATH_TO_GIT_ASKPASS"; then
echo "$PATH_TO_GIT_ASKPASS is not executable."
ls -la "$PATH_TO_GIT_ASKPASS"
exit 1
fi

# NOTE: we need to make sure our fork is up-to-date
# otherwise, brew bump-formula-pr will use an
# outdated base
echo "Pushing changes to $GITHUB_USERNAME/$REPO fork on GitHub"
# Export the variables so git sees them
export HOMEBREW_GITHUB_API_TOKEN="$HOMEBREW_GITHUB_API_TOKEN"
export GIT_ASKPASS="$PATH_TO_ASKPASS"
git push https://coder-oss@github.com/coder-oss/homebrew-core.git --all
export GIT_ASKPASS="$PATH_TO_GIT_ASKPASS"
git push "https://$GITHUB_USERNAME@github.com/$GITHUB_USERNAME/$REPO.git" --all

# Find the docs for bump-formula-pr here
# https://github.com/Homebrew/brew/blob/master/Library/Homebrew/dev-cmd/bump-formula-pr.rb#L18
local output
if ! output=$(brew bump-formula-pr --version="${VERSION}" code-server --no-browse --no-audit 2>&1); then
if [[ $output == *"Duplicate PRs should not be opened"* ]]; then
echo "$VERSION is already submitted"
exit 0
else
echo "$output"
exit 1
fi
fi

# Clean up and remove homebrew-core
popd
rm -rf homebrew-core

# Make sure homebrew-core is removed
if directory_exists "homebrew-core"; then
echo "rm -rf homebrew-core failed."
ls -la
fi
}

main "$@"

0 comments on commit be72787

Please sign in to comment.