refactor: checkout homebrew-core in action instead of script (#4996)

* 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
This commit is contained in:
Joe Previte 2022-03-21 16:57:36 -07:00 committed by GitHub
parent 60ebf2f851
commit be727871f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 35 deletions

View File

@ -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 github-actions@github.com
- name: Bump code-server homebrew version
env:
HOMEBREW_GITHUB_API_TOKEN: ${{secrets.HOMEBREW_GITHUB_API_TOKEN}}

View File

@ -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
@ -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
@ -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
@ -77,16 +70,20 @@ 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
@ -94,21 +91,12 @@ main() {
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 "$@"