From fca292f767a3b6a0d8f4fc893b60120daba73d06 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 16 Mar 2022 15:15:05 -0700 Subject: [PATCH 1/6] 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. --- .github/workflows/npm-brew.yaml | 10 +++++++++- ci/steps/brew-bump.sh | 13 +++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/npm-brew.yaml b/.github/workflows/npm-brew.yaml index 8c8b84fe2c38..1421394e9f18 100644 --- a/.github/workflows/npm-brew.yaml +++ b/.github/workflows/npm-brew.yaml @@ -49,11 +49,19 @@ 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 coder/homebrew-core + uses: actions/checkout@v3 + with: + repository: coder/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}} diff --git a/ci/steps/brew-bump.sh b/ci/steps/brew-bump.sh index 7df17da92431..7e0bf42373bb 100755 --- a/ci/steps/brew-bump.sh +++ b/ci/steps/brew-bump.sh @@ -21,15 +21,8 @@ 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 + if ! directory_exists "homebrew-core"; then echo "git clone failed. Cannot find homebrew-core directory." ls -la exit 1 @@ -67,7 +60,7 @@ main() { echo 'echo $HOMEBREW_GITHUB_API_TOKEN' > "$PATH_TO_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,7 +70,7 @@ 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 From f408b78db27a3743285a7492ba47f6392f20c8ed Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Fri, 18 Mar 2022 11:58:06 -0700 Subject: [PATCH 2/6] refactor: clean up brew-bump.sh script --- .github/workflows/npm-brew.yaml | 4 +-- ci/steps/brew-bump.sh | 57 ++++++++++++++++----------------- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/.github/workflows/npm-brew.yaml b/.github/workflows/npm-brew.yaml index 1421394e9f18..91b04f218a22 100644 --- a/.github/workflows/npm-brew.yaml +++ b/.github/workflows/npm-brew.yaml @@ -52,10 +52,10 @@ jobs: - name: Checkout code-server uses: actions/checkout@v3 - - name: Checkout coder/homebrew-core + - name: Checkout cdrci/homebrew-core uses: actions/checkout@v3 with: - repository: coder/homebrew-core + repository: cdrci/homebrew-core - name: Configure git run: | diff --git a/ci/steps/brew-bump.sh b/ci/steps/brew-bump.sh index 7e0bf42373bb..92ae536fbe45 100755 --- a/ci/steps/brew-bump.sh +++ b/ci/steps/brew-bump.sh @@ -2,10 +2,12 @@ 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 + source ./lib.sh + source ./steps-lib.sh echo "Checking environment variables" @@ -22,17 +24,17 @@ main() { fi # 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 @@ -43,21 +45,19 @@ 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 @@ -76,30 +76,27 @@ main() { 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" - else - echo "$output" - exit 1 - fi - fi + # local output + brew bump-formula-pr --version="${VERSION}" code-server --no-browse --no-audit # Clean up and remove homebrew-core popd - rm -rf homebrew-core + rm -rf "$REPO" - # Make sure homebrew-core is removed - if directory_exists "homebrew-core"; then - echo "rm -rf homebrew-core failed." + # Make sure $REPO is removed + if directory_exists "$REPO"; then + echo "rm -rf $REPO failed." ls -la fi } From f9a33c212a6c090cea57f8a83969ddf75c3ed63c Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Fri, 18 Mar 2022 12:15:58 -0700 Subject: [PATCH 3/6] fixup --- .github/workflows/npm-brew.yaml | 1 + ci/steps/brew-bump.sh | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/npm-brew.yaml b/.github/workflows/npm-brew.yaml index d34a56ff1d24..60b3208b5ff3 100644 --- a/.github/workflows/npm-brew.yaml +++ b/.github/workflows/npm-brew.yaml @@ -63,6 +63,7 @@ jobs: uses: actions/checkout@v3 with: repository: cdrci/homebrew-core + path: homebrew-core - name: Configure git run: | diff --git a/ci/steps/brew-bump.sh b/ci/steps/brew-bump.sh index 92ae536fbe45..5be87fecf088 100755 --- a/ci/steps/brew-bump.sh +++ b/ci/steps/brew-bump.sh @@ -6,8 +6,8 @@ main() { GITHUB_USERNAME="cdrci" UPSTREAM_USERNAME_AND_REPO="Homebrew/$REPO" # Only sourcing this so we get access to $VERSION - source ./lib.sh - source ./steps-lib.sh + source ./ci/lib.sh + source ./ci/steps-lib.sh echo "Checking environment variables" From 1e388d415e8443938b678e72a64e5131a771c3eb Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Fri, 18 Mar 2022 15:43:55 -0700 Subject: [PATCH 4/6] fixup!: remove step to clean up homebrew repo --- ci/steps/brew-bump.sh | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/ci/steps/brew-bump.sh b/ci/steps/brew-bump.sh index 5be87fecf088..5aa6864a5ff1 100755 --- a/ci/steps/brew-bump.sh +++ b/ci/steps/brew-bump.sh @@ -89,16 +89,6 @@ main() { # https://github.com/Homebrew/brew/blob/master/Library/Homebrew/dev-cmd/bump-formula-pr.rb#L18 # local output brew bump-formula-pr --version="${VERSION}" code-server --no-browse --no-audit - - # Clean up and remove homebrew-core - popd - rm -rf "$REPO" - - # Make sure $REPO is removed - if directory_exists "$REPO"; then - echo "rm -rf $REPO failed." - ls -la - fi } main "$@" From 0c2fa9771417f811c1b4e96115ebc2126f551bea Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Fri, 18 Mar 2022 15:45:06 -0700 Subject: [PATCH 5/6] fixup!: use correct ./ci path steps-lib.sh --- ci/steps/brew-bump.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/steps/brew-bump.sh b/ci/steps/brew-bump.sh index 5aa6864a5ff1..cd35019b49b0 100755 --- a/ci/steps/brew-bump.sh +++ b/ci/steps/brew-bump.sh @@ -7,7 +7,7 @@ main() { UPSTREAM_USERNAME_AND_REPO="Homebrew/$REPO" # Only sourcing this so we get access to $VERSION source ./ci/lib.sh - source ./ci/steps-lib.sh + source ./ci/steps/steps-lib.sh echo "Checking environment variables" From 2f1fe5040c3a46adf92a4a0ef2f5a930e1bcf5e8 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Mon, 21 Mar 2022 14:47:00 -0700 Subject: [PATCH 6/6] fixup!: add exit code 0 for duplicate PRs --- ci/steps/brew-bump.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ci/steps/brew-bump.sh b/ci/steps/brew-bump.sh index cd35019b49b0..68ae26de2ef7 100755 --- a/ci/steps/brew-bump.sh +++ b/ci/steps/brew-bump.sh @@ -87,8 +87,16 @@ main() { # 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 - brew bump-formula-pr --version="${VERSION}" code-server --no-browse --no-audit + 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 } main "$@"