Skip to content

Commit 5a67328

Browse files
authored
Add a workflow to automatically update Enos Homebrew formula file and open a PR for it on hashicorp/homebrew-internal (#41)
Add a reusable workflow to automatically update Enos Homebrew formula file after a release is completed, and open a PR for it on our internal Homebrew tap (hashicorp/homebrew-internal)
1 parent 52f969a commit 5a67328

File tree

4 files changed

+128
-5
lines changed

4 files changed

+128
-5
lines changed

.github/workflows/create_release.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ on:
2727
description: To mark this as a pre-release, check this box.
2828

2929
jobs:
30-
create_release:
30+
create-release:
31+
name: Create Release
3132
runs-on: ubuntu-latest
3233
env:
3334
GOPRIVATE: 'github.com/hashicorp/*'
@@ -58,7 +59,7 @@ jobs:
5859
-user=${{ secrets.QUALITY_TEAM_ARTIFACTORY_USER }} \
5960
-channel ${{ env.CHANNEL }} \
6061
-commit=${{ env.SHA }} \
61-
-product-name=${{env.PRODUCT }} \
62+
-product-name=${{ env.PRODUCT }} \
6263
-product-version=${{ env.VERSION }} \
6364
-pattern="${{ env.PRODUCT }}_${{ env.VERSION }}_*_*.zip"
6465
@@ -77,3 +78,20 @@ jobs:
7778
TAG=v${{ env.VERSION }}-pre+$( echo ${{ env.SHA }} | head -c 5 )
7879
fi
7980
gh release create $TAG --target ${{ env.SHA }} --generate-notes $PRERELEASE ./.bob/artifacts/*.zip
81+
82+
# If not a pre-release, generate an updated Homebrew formula definition file
83+
# and open a PR on hashicorp/homebrew-internal with the updated file
84+
trigger-homebrew-formula-update:
85+
if: ${{ github.event.inputs.pre_release == 'false' }}
86+
name: Trigger update to Homebrew formula
87+
needs: create-release
88+
uses: ./.github/workflows/update_homebrew_formula.yml
89+
with:
90+
channel: ${{ github.event.inputs.channel }}
91+
sha: ${{ github.event.inputs.sha }}
92+
product: ${{ github.event.repository.name }}
93+
version: ${{ github.event.inputs.version }}
94+
secrets:
95+
GH_TOKEN: ${{ secrets.ELEVATED_GITHUB_TOKEN }}
96+
ARTIFACTORY_TOKEN: ${{ secrets.QUALITY_TEAM_ARTIFACTORY_TOKEN }}
97+
ARTIFACTORY_USER: ${{ secrets.QUALITY_TEAM_ARTIFACTORY_USER }}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Update Homebrew Formula
2+
3+
# NOTE
4+
# This is a reusable workflow that is intended to be called by the `create_release` workflow
5+
# after a Github release is successfully created. This workflow generates an updated
6+
# version of the Enos Homebrew formula file, opens a PR on HashiCorp's internal Homebrew
7+
# tap (hashicorp/homebrew-internal), and tags `quality-team` for review.
8+
9+
on:
10+
workflow_call:
11+
inputs:
12+
channel:
13+
required: true
14+
type: string
15+
sha:
16+
required: true
17+
type: string
18+
product:
19+
required: true
20+
type: string
21+
version:
22+
required: true
23+
type: string
24+
secrets:
25+
GH_TOKEN:
26+
required: true
27+
ARTIFACTORY_TOKEN:
28+
required: true
29+
ARTIFACTORY_USER:
30+
required: true
31+
32+
jobs:
33+
34+
update-formula:
35+
name: "Update Homebrew formula definition"
36+
runs-on: ubuntu-latest
37+
env:
38+
# Note: `gh` CLI automatically looks for and uses `env.GH_TOKEN` for authentication.
39+
# This token must have read:org scope in order to authenticate on a different repo.
40+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
41+
TARGET_REPO: hashicorp/homebrew-internal
42+
TARGET_REPO_FILEPATH: homebrew-internal-checkout
43+
BASE_BRANCH: main
44+
PR_BRANCH: enos_homebrew_formula_update_v${{ inputs.version }}
45+
PR_TITLE: "Homebrew formula update for Enos version v${{ inputs.version }}"
46+
PR_BODY: "This is an automatically generated PR to update the Homebrew formula for Enos after a release has been completed. It must be manually approved and merged by a reviewer."
47+
COMMIT_MSG: "Update Homebrew formula for Enos version v${{ inputs.version }}"
48+
GIT_USER_EMAIL: [email protected]
49+
GIT_USER_NAME: Secure Quality Team
50+
REVIEWER: quality-team
51+
steps:
52+
# Checkout Enos repo and place it in the specified relative path within the runner's main directory,
53+
# in order to accommodate checking out multiple repos.
54+
- name: Checkout
55+
uses: actions/checkout@v2
56+
with:
57+
path: enos-checkout
58+
59+
# Set up bob CLI
60+
- name: Setup bob CLI
61+
uses: hashicorp/action-setup-bob@v1
62+
with:
63+
github-token: ${{ secrets.GH_TOKEN }}
64+
65+
# Use bob to download SHA256SUMS file from Artifactory
66+
- name: Download artifacts
67+
run: |
68+
bob download artifactory \
69+
-token=${{ secrets.ARTIFACTORY_TOKEN }} \
70+
-user=${{ secrets.ARTIFACTORY_USER }} \
71+
-channel ${{ inputs.channel }} \
72+
-commit=${{ inputs.sha }} \
73+
-product-name=${{ inputs.product }} \
74+
-product-version=${{ inputs.version }} \
75+
-pattern="${{ inputs.product }}_${{ inputs.version }}_SHA256SUMS"
76+
77+
# Generate Homebrew formula file (enos.rb)
78+
- name: Generate Homebrew formula file
79+
run: |
80+
cd enos-checkout
81+
go run ./tools/homebrew/... create -p ../.bob/artifacts/${{ inputs.product }}_${{ inputs.version }}_SHA256SUMS -o enos.rb
82+
83+
# Checkout target repo and place it in the specified relative path within the runner's main directory,
84+
# in order to accommodate checking out multiple repos.
85+
# A token with sufficient permissions for the target repo is required.
86+
- name: Checkout
87+
uses: actions/checkout@v2
88+
with:
89+
repository: ${{ env.TARGET_REPO }}
90+
path: ${{ env.TARGET_REPO_FILEPATH }}
91+
token: ${{ secrets.GH_TOKEN }}
92+
93+
# Create PR
94+
- name: Create PR
95+
run: |
96+
cd ${{ env.TARGET_REPO_FILEPATH }}
97+
git config user.email "${{ env.GIT_USER_EMAIL }}"
98+
git config user.name "${{ env.GIT_USER_NAME }}"
99+
git checkout -b ${{ env.PR_BRANCH }}
100+
mv ../enos-checkout/enos.rb ./HomebrewFormula/enos.rb
101+
git add HomebrewFormula/enos.rb
102+
git commit -m "${{ env.COMMIT_MSG }}"
103+
git push origin ${{ env.PR_BRANCH }}
104+
105+
gh pr create --repo ${{ env.TARGET_REPO }} --base ${{ env.BASE_BRANCH }} --head ${{ env.PR_BRANCH }} --title "${{ env.PR_TITLE }}" --body "${{ env.PR_BODY }}" --reviewer ${{ env.REVIEWER }}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,3 +549,5 @@ To create the release, the workflow downloads the release assets from Artifactor
549549
- **Bug Fixes 🐛** category includes PRs with the label `changelog/bug`
550550
- **Other Changes 😎** category includes PRs with the label `changelog/other`
551551
- PRs with the label `changelog/none` will be excluded from release notes.
552+
553+
After the release workflow completes, it automatically triggers another workflow. This workflow creates an updated version of the Enos Homebrew formula file and opens a PR for it in HashiCorp's internal Homebrew tap, `hashicorp/homebrew-internal`.

tools/homebrew/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ func newCreateFormulaCommand() *cobra.Command {
9999
}
100100

101101
createFormula.PersistentFlags().StringVarP(&createFormulaConfigs.path, "path", "p", "", "the path to the SHA265SUMS file")
102-
createFormula.PersistentFlags().StringVarP(&createFormulaConfigs.version, "version", "v", "", "the version of the release")
103-
createFormula.PersistentFlags().StringVarP(&createFormulaConfigs.versionTag, "version-tag", "t", "", "the version tag of the release")
104-
createFormula.PersistentFlags().StringVarP(&createFormulaConfigs.outPath, "outpath", "o", "", "the pat")
102+
createFormula.PersistentFlags().StringVarP(&createFormulaConfigs.outPath, "outpath", "o", "", "the path to the output file")
105103

106104
return createFormula
107105
}

0 commit comments

Comments
 (0)