fix: use gh CLI for GitHub releases and add PR links #22
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: Release | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| permissions: | ||
| contents: write | ||
| jobs: | ||
| release: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| released: ${{ steps.release.outputs.released }} | ||
| version: ${{ steps.release.outputs.version }} | ||
| tag: ${{ steps.release.outputs.tag }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Authenticate as GitHub App | ||
| id: auth | ||
| uses: ./.github/actions/github-app-auth | ||
| with: | ||
| app-id: ${{ secrets.AUTOMATION_GITHUB_APP_ID }} | ||
| private-key: ${{ secrets.AUTOMATION_GITHUB_APP_PRIVATE_KEY }} | ||
| - name: Fetch tags | ||
| run: git fetch --tags --force | ||
| - name: Setup mise | ||
| uses: jdx/mise-action@v2 | ||
| - name: Install dependencies | ||
| run: yarn install | ||
| - name: Run release-it | ||
| id: release | ||
| run: | | ||
| # Run release-it to bump version, update changelog, commit, and tag | ||
| if yarn release-it --ci; then | ||
| echo "released=true" >> "$GITHUB_OUTPUT" | ||
| # Get version from package.json (updated by release-it) | ||
| VERSION=$(node -p "require('./package.json').version") | ||
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | ||
| echo "tag=v$VERSION" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "No release created" | ||
| echo "released=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
| - name: Create GitHub release | ||
| if: steps.release.outputs.released == 'true' | ||
| run: | | ||
| gh release create "${{ steps.release.outputs.tag }}" \ | ||
| bin/worktree-switcher \ | ||
| --title "${{ steps.release.outputs.tag }}" \ | ||
| --generate-notes | ||
| update-homebrew: | ||
| needs: release | ||
| if: needs.release.outputs.released == 'true' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Get job context | ||
| id: context | ||
| uses: qoomon/actions--context@v4 | ||
| - name: Authenticate as GitHub App | ||
| id: auth | ||
| uses: ./.github/actions/github-app-auth | ||
| with: | ||
| app-id: ${{ secrets.AUTOMATION_GITHUB_APP_ID }} | ||
| private-key: ${{ secrets.AUTOMATION_GITHUB_APP_PRIVATE_KEY }} | ||
| - name: Get release info | ||
| id: release | ||
| run: | | ||
| VERSION="${{ needs.release.outputs.version }}" | ||
| TAG="${{ needs.release.outputs.tag }}" | ||
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | ||
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | ||
| # Get SHA256 of the script from release | ||
| SHA256=$(curl -sL "https://github.com/${{ github.repository }}/releases/download/${TAG}/worktree-switcher" | shasum -a 256 | cut -d' ' -f1) | ||
| echo "sha256=$SHA256" >> "$GITHUB_OUTPUT" | ||
| - name: Clone homebrew-devsetup | ||
| run: | | ||
| gh repo clone nsheaps/homebrew-devsetup homebrew-devsetup | ||
| - name: Update formula | ||
| run: | | ||
| cd homebrew-devsetup | ||
| cat > Formula/worktree-switcher.rb << FORMULA_EOF | ||
| # typed: false | ||
| # frozen_string_literal: true | ||
| class WorktreeSwitcher < Formula | ||
| desc "Interactive TUI for git worktree management" | ||
| homepage "https://github.com/nsheaps/git-wt" | ||
| url "https://github.com/nsheaps/git-wt/releases/download/${{ steps.release.outputs.tag }}/worktree-switcher" | ||
| sha256 "${{ steps.release.outputs.sha256 }}" | ||
| version "${{ steps.release.outputs.version }}" | ||
| license "MIT" | ||
| head do | ||
| url "https://github.com/nsheaps/git-wt.git", branch: "main" | ||
| end | ||
| depends_on "gum" | ||
| depends_on "gh" | ||
| depends_on "jq" | ||
| def install | ||
| if build.head? | ||
| bin.install "bin/worktree-switcher" | ||
| else | ||
| bin.install "worktree-switcher" | ||
| end | ||
| end | ||
| test do | ||
| assert_match "worktree-switcher", shell_output("#{bin}/worktree-switcher --help") | ||
| end | ||
| end | ||
| FORMULA_EOF | ||
| # Remove leading whitespace from heredoc | ||
| sed -i 's/^ //' Formula/worktree-switcher.rb | ||
| - name: Create PR to update formula with auto-merge | ||
| env: | ||
| RELEASE_URL: https://github.com/${{ github.repository }}/releases/tag/${{ steps.release.outputs.tag }} | ||
| JOB_URL: ${{ steps.context.outputs.job_html_url }} | ||
| run: | | ||
| cd homebrew-devsetup | ||
| BRANCH="bump-worktree-switcher-${{ steps.release.outputs.version }}" | ||
| git checkout -b "$BRANCH" | ||
| git add Formula/worktree-switcher.rb | ||
| git commit -m "chore: update worktree-switcher to ${{ steps.release.outputs.version }}" | ||
| git push -u origin "$BRANCH" | ||
| PR_URL=$(gh pr create \ | ||
| --title "chore: update worktree-switcher to ${{ steps.release.outputs.version }}" \ | ||
| --body "$(cat <<EOF | ||
| Automated formula update from git-wt release ${{ steps.release.outputs.tag }} | ||
| **Release:** ${RELEASE_URL} | ||
| **Workflow:** ${JOB_URL} | ||
| EOF | ||
| )" \ | ||
| --base main) | ||
| # Enable auto-merge with squash | ||
| gh pr merge "$PR_URL" --auto --squash | ||