|
| 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 | + |
| 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 }} |
0 commit comments