Release #79
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: | |
| workflow_run: | |
| workflows: ["CI"] | |
| types: [completed] | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| name: Build Binaries | |
| runs-on: ubuntu-latest | |
| # Only run if CI passes and commit message doesn't contain [skip release] | |
| if: "!contains(github.event.head_commit.message, '[skip release]')" | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get version from flake.nix | |
| id: version | |
| run: | | |
| VERSION=$(grep 'version = ' flake.nix | head -1 | sed 's/.*version = "\([^"]*\)".*/\1/') | |
| echo "version=$VERSION" >>$GITHUB_OUTPUT | |
| echo "Version: $VERSION" | |
| - name: Check if tag exists | |
| id: check_tag | |
| run: | | |
| if git ls-remote --tags origin "refs/tags/v${{ steps.version.outputs.version }}" | grep -q .; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| echo "Tag v${{ steps.version.outputs.version }} already exists on remote, skipping release" | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Set up Go | |
| if: steps.check_tag.outputs.exists == 'false' | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| - name: Build native binary for completions and man pages | |
| if: steps.check_tag.outputs.exists == 'false' | |
| env: | |
| VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| go build -ldflags="-s -w -X github.com/ahmedelgabri/git-wt/internal/cmd.Version=$VERSION" -o git-wt-native ./cmd/git-wt/ | |
| mkdir -p dist/completions dist/man | |
| ./git-wt-native completion bash > dist/completions/git-wt.bash | |
| ./git-wt-native completion zsh > dist/completions/_git-wt | |
| ./git-wt-native completion zsh-git > dist/completions/_git_wt | |
| ./git-wt-native completion fish > dist/completions/git-wt.fish | |
| ./git-wt-native man dist/man | |
| rm git-wt-native | |
| - name: Cross-compile and package | |
| if: steps.check_tag.outputs.exists == 'false' | |
| env: | |
| VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| LDFLAGS="-s -w -X github.com/ahmedelgabri/git-wt/internal/cmd.Version=$VERSION" | |
| for target in darwin/amd64 darwin/arm64 linux/amd64 linux/arm64; do | |
| OS="${target%/*}" | |
| ARCH="${target#*/}" | |
| DIR="git-wt-${VERSION}-${OS}-${ARCH}" | |
| mkdir -p "dist/${DIR}" | |
| GOOS="$OS" GOARCH="$ARCH" go build -ldflags="$LDFLAGS" -o "dist/${DIR}/git-wt" ./cmd/git-wt/ | |
| cp -r dist/completions "dist/${DIR}/" | |
| cp -r dist/man "dist/${DIR}/" | |
| tar -czf "dist/${DIR}.tar.gz" -C dist "$DIR" | |
| done | |
| - name: Generate checksums | |
| if: steps.check_tag.outputs.exists == 'false' | |
| env: | |
| VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| cd dist | |
| sha256sum git-wt-${VERSION}-*.tar.gz > "git-wt-${VERSION}-checksums.txt" | |
| - name: Upload artifacts | |
| if: steps.check_tag.outputs.exists == 'false' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-assets | |
| path: | | |
| dist/git-wt-*.tar.gz | |
| dist/git-wt-*-checksums.txt | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| tag_exists: ${{ steps.check_tag.outputs.exists }} | |
| release: | |
| name: Create Release | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: needs.build.outputs.tag_exists == 'false' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: release-assets | |
| path: dist | |
| - name: Generate changelog | |
| id: changelog | |
| env: | |
| VERSION: ${{ needs.build.outputs.version }} | |
| run: | | |
| PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || git rev-list --max-parents=0 HEAD) | |
| echo "Previous reference: $PREV_TAG" | |
| CHANGELOG=$(git log "$PREV_TAG"..HEAD --pretty=format:"- %s" --no-merges | head -50) | |
| echo "changelog<<EOF" >>$GITHUB_OUTPUT | |
| echo "$CHANGELOG" >>$GITHUB_OUTPUT | |
| echo "EOF" >>$GITHUB_OUTPUT | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ needs.build.outputs.version }} | |
| name: v${{ needs.build.outputs.version }} | |
| body: | | |
| ## Changes | |
| ${{ steps.changelog.outputs.changelog }} | |
| ## Installation | |
| ### Using Homebrew | |
| ```bash | |
| brew install ahmedelgabri/tap/git-wt | |
| ``` | |
| ### Using Nix Flakes | |
| ```bash | |
| nix run github:${{ github.repository }} | |
| ``` | |
| ### Manual Download | |
| Download the archive for your platform, extract it, and place the binary in your `$PATH`: | |
| ```bash | |
| tar xzf git-wt-${{ needs.build.outputs.version }}-<OS>-<ARCH>.tar.gz | |
| cp git-wt-${{ needs.build.outputs.version }}-<OS>-<ARCH>/git-wt ~/.local/bin/ | |
| ``` | |
| Completions and man pages are included in the archive under `completions/` and `man/`. | |
| **Checksums:** See `git-wt-${{ needs.build.outputs.version }}-checksums.txt` | |
| draft: false | |
| prerelease: false | |
| files: | | |
| dist/git-wt-*.tar.gz | |
| dist/git-wt-*-checksums.txt | |
| update-homebrew: | |
| name: Update Homebrew Formula | |
| needs: [build, release] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Homebrew tap | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ahmedelgabri/homebrew-tap | |
| token: ${{ secrets.HOMEBREW_TAP_TOKEN }} | |
| - name: Download checksums | |
| env: | |
| VERSION: ${{ needs.build.outputs.version }} | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| gh release download "v${VERSION}" \ | |
| --repo ahmedelgabri/git-wt \ | |
| --pattern "*checksums.txt" \ | |
| --dir . | |
| - name: Update formula | |
| env: | |
| VERSION: ${{ needs.build.outputs.version }} | |
| run: | | |
| sed -i "s/version \"[^\"]*\"/version \"${VERSION}\"/" Formula/git-wt.rb | |
| DARWIN_AMD64=$(grep "darwin-amd64" "git-wt-${VERSION}-checksums.txt" | awk '{print $1}') | |
| DARWIN_ARM64=$(grep "darwin-arm64" "git-wt-${VERSION}-checksums.txt" | awk '{print $1}') | |
| LINUX_AMD64=$(grep "linux-amd64" "git-wt-${VERSION}-checksums.txt" | awk '{print $1}') | |
| LINUX_ARM64=$(grep "linux-arm64" "git-wt-${VERSION}-checksums.txt" | awk '{print $1}') | |
| awk -v da="$DARWIN_AMD64" -v darm="$DARWIN_ARM64" \ | |
| -v la="$LINUX_AMD64" -v larm="$LINUX_ARM64" ' | |
| /darwin-amd64/ { platform = "da" } | |
| /darwin-arm64/ { platform = "darm" } | |
| /linux-amd64/ { platform = "la" } | |
| /linux-arm64/ { platform = "larm" } | |
| /sha256/ && platform { | |
| hash = (platform == "da") ? da : (platform == "darm") ? darm : (platform == "la") ? la : larm | |
| sub(/"[^"]*"/, "\"" hash "\"") | |
| platform = "" | |
| } | |
| { print } | |
| ' Formula/git-wt.rb > tmp && mv tmp Formula/git-wt.rb | |
| python - <<'PY' | |
| from pathlib import Path | |
| path = Path("Formula/git-wt.rb") | |
| text = path.read_text() | |
| bridge = ' zsh_completion.install "completions/_git_wt"\n' | |
| if bridge not in text: | |
| text = text.replace( | |
| ' zsh_completion.install "completions/_git-wt"\n', | |
| ' zsh_completion.install "completions/_git-wt"\n' + bridge, | |
| ) | |
| path.write_text(text) | |
| PY | |
| - name: Commit and push | |
| env: | |
| VERSION: ${{ needs.build.outputs.version }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add Formula/git-wt.rb | |
| git diff --staged --quiet && echo "No changes" && exit 0 | |
| git commit -m "chore: bump git-wt to v${VERSION}" | |
| git push |