fix: embed version at release time for correct --version output #34
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 | |
| actions: read | |
| 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 the latest git tag (created by release-it) | |
| TAG=$(git describe --tags --abbrev=0) | |
| VERSION="${TAG#v}" | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "No release created" | |
| echo "released=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Embed version in script | |
| if: steps.release.outputs.released == 'true' | |
| run: | | |
| sed -i 's/__VERSION__/${{ steps.release.outputs.tag }}/' bin/git-wt | |
| - name: Create GitHub release | |
| if: steps.release.outputs.released == 'true' | |
| run: | | |
| gh release create "${{ steps.release.outputs.tag }}" \ | |
| bin/git-wt \ | |
| --title "${{ steps.release.outputs.tag }}" \ | |
| --generate-notes | |
| # NOTE: Homebrew formula updates are handled by Renovate in nsheaps/homebrew-devsetup | |
| update-homebrew: | |
| if: ${{ false }} # Disabled - Renovate handles this | |
| needs: release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| persist-credentials: false | |
| - 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" | |
| # Download asset using gh CLI (more reliable than curl for fresh releases) | |
| # Retry up to 5 times with 10s delay to handle CDN propagation | |
| for i in {1..5}; do | |
| echo "Attempt $i: Downloading release asset..." | |
| if gh release download "$TAG" --pattern 'git-wt' --output /tmp/git-wt --clobber; then | |
| # Verify it's actually the script (not an error page) | |
| if head -1 /tmp/git-wt | grep -q '^#!/'; then | |
| SHA256=$(shasum -a 256 /tmp/git-wt | cut -d' ' -f1) | |
| echo "sha256=$SHA256" >> "$GITHUB_OUTPUT" | |
| echo "Successfully got SHA256: $SHA256" | |
| exit 0 | |
| else | |
| echo "Downloaded file doesn't look like a script, retrying..." | |
| fi | |
| fi | |
| echo "Download failed or invalid, waiting 10s before retry..." | |
| sleep 10 | |
| done | |
| echo "Failed to download release asset after 5 attempts" | |
| exit 1 | |
| - name: Clone homebrew-devsetup | |
| run: | | |
| gh repo clone nsheaps/homebrew-devsetup homebrew-devsetup | |
| - name: Update formula | |
| run: | | |
| cd homebrew-devsetup | |
| cat > Formula/git-wt.rb << FORMULA_EOF | |
| # typed: false | |
| # frozen_string_literal: true | |
| class GitWt < 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 }}/git-wt" | |
| 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" | |
| def install | |
| if build.head? | |
| bin.install "bin/git-wt" | |
| else | |
| bin.install "git-wt" | |
| end | |
| end | |
| test do | |
| assert_match "git-wt", shell_output("#{bin}/git-wt --help") | |
| end | |
| end | |
| FORMULA_EOF | |
| # Remove leading whitespace from heredoc | |
| sed -i 's/^ //' Formula/git-wt.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: ${{ env.GITHUB_JOB_URL }} | |
| VERSION: ${{ steps.release.outputs.version }} | |
| TAG: ${{ steps.release.outputs.tag }} | |
| run: | | |
| cd homebrew-devsetup | |
| BRANCH="bump-git-wt-${VERSION}" | |
| git checkout -b "$BRANCH" | |
| git add Formula/git-wt.rb | |
| git commit -m "chore: update git-wt to ${VERSION}" | |
| git push -u origin "$BRANCH" | |
| # Create PR body file | |
| cat > /tmp/pr-body.md << 'BODY_EOF' | |
| Automated formula update from git-wt release | |
| BODY_EOF | |
| echo "" >> /tmp/pr-body.md | |
| echo "**Release:** ${RELEASE_URL}" >> /tmp/pr-body.md | |
| echo "**Workflow:** ${JOB_URL}" >> /tmp/pr-body.md | |
| PR_URL=$(gh pr create \ | |
| --title "chore: update git-wt to ${VERSION}" \ | |
| --body-file /tmp/pr-body.md \ | |
| --base main) | |
| # Enable auto-merge with squash | |
| gh pr merge "$PR_URL" --auto --squash |