Update Formula #16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Formula | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| update: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - tag: latest | |
| formula: Formula/denvig.rb | |
| - tag: alpha | |
| formula: Formula/denvig-alpha.rb | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| # Use a PAT (not the default GITHUB_TOKEN) so the PR this workflow | |
| # opens triggers the test-formula workflow. PRs created with | |
| # GITHUB_TOKEN do not trigger further workflow runs. | |
| token: ${{ secrets.FORMULA_UPDATE_TOKEN }} | |
| - name: Get version from npm | |
| id: npm | |
| run: | | |
| VERSION=$(curl -s "https://registry.npmjs.org/denvig/${{ matrix.tag }}" | jq -r '.version') | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| - name: Check if update is needed | |
| id: check | |
| run: | | |
| CURRENT=$(grep -oP 'denvig-\K[^"]+(?=\.tgz)' "${{ matrix.formula }}" | head -1) | |
| echo "current=$CURRENT" >> "$GITHUB_OUTPUT" | |
| if [ "$CURRENT" = "${{ steps.npm.outputs.version }}" ]; then | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| echo "Already up to date ($CURRENT)" | |
| else | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| echo "Updating $CURRENT -> ${{ steps.npm.outputs.version }}" | |
| fi | |
| - name: Update formula | |
| if: steps.check.outputs.skip == 'false' | |
| run: | | |
| VERSION="${{ steps.npm.outputs.version }}" | |
| CURRENT="${{ steps.check.outputs.current }}" | |
| FORMULA="${{ matrix.formula }}" | |
| # Bump the version in every npm tarball URL. denvig and the first-party | |
| # @denvig/* resources are published in lockstep at the same version, so a | |
| # global replace of the old version string covers the main download and the | |
| # @denvig/cli + @denvig/sdk resource blocks alike (both formulae vendor them). | |
| sed -i "s/${CURRENT}/${VERSION}/g" "$FORMULA" | |
| # Recompute each sha256 to match the URL on the line above it. This handles the | |
| # main formula download and every resource block, in both formulae. | |
| ruby - "$FORMULA" <<'RUBY' | |
| path = ARGV[0] | |
| text = File.read(path) | |
| text.gsub!(/^([ \t]*)url "([^"]+\.tgz)"(.*)\n([ \t]*)sha256 "[0-9a-f]+"/) do | |
| url_indent, url, url_suffix, sha_indent = $1, $2, $3, $4 | |
| sha = %x(curl -sL "#{url}" | sha256sum).split.first | |
| %(#{url_indent}url "#{url}"#{url_suffix}\n#{sha_indent}sha256 "#{sha}") | |
| end | |
| File.write(path, text) | |
| RUBY | |
| - name: Create pull request | |
| if: steps.check.outputs.skip == 'false' | |
| env: | |
| GH_TOKEN: ${{ secrets.FORMULA_UPDATE_TOKEN }} | |
| run: | | |
| VERSION="${{ steps.npm.outputs.version }}" | |
| TAG="${{ matrix.tag }}" | |
| BRANCH="update-${TAG}-v${VERSION}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git checkout -b "$BRANCH" | |
| git add "${{ matrix.formula }}" | |
| git commit -m "v${VERSION} (${TAG})" | |
| git push -u origin "$BRANCH" | |
| gh pr create \ | |
| --draft \ | |
| --title "v${VERSION} (${TAG})" \ | |
| --body "Updates denvig \`${TAG}\` formula to v${VERSION}" \ | |
| --base main |