From 51a5aaa8fcbafa88a99b207f98558d1a713f647f Mon Sep 17 00:00:00 2001 From: Jheison Martinez Bolivar Date: Wed, 1 Apr 2026 18:03:06 -0500 Subject: [PATCH] fix: align release workflow with texforge (auto-tag on main PR), bump to 0.1.1 --- .github/workflows/release.yml | 120 ++++++++++++++++++++++++++-------- Cargo.toml | 2 +- 2 files changed, 95 insertions(+), 27 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f931d54..ebb7f74 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,13 @@ name: Release on: - push: - tags: - - 'v*' + pull_request: + branches: + - main + types: + - closed + paths: + - Cargo.toml permissions: contents: write @@ -12,8 +16,58 @@ env: CARGO_TERM_COLOR: always jobs: + create-tag: + name: Create Release Tag + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.version.outputs.tag }} + version: ${{ steps.version.outputs.version }} + created: ${{ steps.create.outputs.created }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get version from Cargo.toml + id: version + run: | + VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/' | tr -d '\r') + TAG="v${VERSION}" + echo "version=${VERSION}" >> $GITHUB_OUTPUT + echo "tag=${TAG}" >> $GITHUB_OUTPUT + + - name: Check if tag already exists + id: check_tag + run: | + TAG=${{ steps.version.outputs.tag }} + if git rev-parse "$TAG" >/dev/null 2>&1; then + echo "exists=true" >> $GITHUB_OUTPUT + echo "Tag $TAG already exists, skipping" + else + echo "exists=false" >> $GITHUB_OUTPUT + fi + + - name: Create and push tag + id: create + run: | + if [ "${{ steps.check_tag.outputs.exists }}" = "true" ]; then + echo "created=false" >> $GITHUB_OUTPUT + echo "Tag already exists — skipping release" + exit 0 + fi + TAG=${{ steps.version.outputs.tag }} + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag -a "$TAG" -m "Release $TAG" + git push origin "$TAG" + echo "created=true" >> $GITHUB_OUTPUT + echo "Tag $TAG created and pushed" + build: name: Build ${{ matrix.target }} + needs: create-tag + if: needs.create-tag.outputs.created == 'true' runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -22,49 +76,38 @@ jobs: - target: x86_64-unknown-linux-musl os: ubuntu-latest archive: tar.gz - use_cross: true - - target: aarch64-unknown-linux-musl - os: ubuntu-latest - archive: tar.gz - use_cross: true - - target: x86_64-apple-darwin + - target: aarch64-apple-darwin os: macos-latest archive: tar.gz - use_cross: false - - target: aarch64-apple-darwin + - target: x86_64-apple-darwin os: macos-latest archive: tar.gz - use_cross: false - target: x86_64-pc-windows-msvc os: windows-latest archive: zip - use_cross: false steps: - uses: actions/checkout@v4 + with: + ref: ${{ needs.create-tag.outputs.tag }} - name: Install Rust toolchain uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.target }} - - name: Install cross - if: matrix.use_cross == true - run: cargo install cross --locked - - - name: Build release binary (cross) - if: matrix.use_cross == true - run: cross build --release --target ${{ matrix.target }} + - name: Install musl tools (Linux) + if: matrix.target == 'x86_64-unknown-linux-musl' + run: sudo apt-get update && sudo apt-get install -y musl-tools - name: Build release binary - if: matrix.use_cross == false run: cargo build --release --target ${{ matrix.target }} - name: Package (unix) if: matrix.archive == 'tar.gz' run: | cd target/${{ matrix.target }}/release - tar czf ../../../gitkit-${{ github.ref_name }}-${{ matrix.target }}.tar.gz gitkit + tar czf ../../../gitkit-${{ needs.create-tag.outputs.tag }}-${{ matrix.target }}.tar.gz gitkit cd ../../.. - name: Package (windows) @@ -72,18 +115,18 @@ jobs: shell: pwsh run: | cd target/${{ matrix.target }}/release - Compress-Archive -Path gitkit.exe -DestinationPath ../../../gitkit-${{ github.ref_name }}-${{ matrix.target }}.zip + Compress-Archive -Path gitkit.exe -DestinationPath ../../../gitkit-${{ needs.create-tag.outputs.tag }}-${{ matrix.target }}.zip cd ../../.. - name: Upload artifact uses: actions/upload-artifact@v4 with: name: gitkit-${{ matrix.target }} - path: gitkit-${{ github.ref_name }}-${{ matrix.target }}.* + path: gitkit-${{ needs.create-tag.outputs.tag }}-${{ matrix.target }}.* github-release: name: Create GitHub Release - needs: build + needs: [create-tag, build] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -97,6 +140,31 @@ jobs: - name: Create release uses: softprops/action-gh-release@v2 with: - tag_name: ${{ github.ref_name }} + tag_name: ${{ needs.create-tag.outputs.tag }} generate_release_notes: true files: artifacts/* + + approve: + name: Awaiting Manual Approval + needs: github-release + runs-on: ubuntu-latest + environment: + name: production + steps: + - name: Approval granted + run: echo "Release approved for publishing to crates.io" + + publish: + name: Publish to crates.io + needs: [create-tag, approve] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ needs.create-tag.outputs.tag }} + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Cargo publish + run: cargo publish --token ${{ secrets.CARGO_TOKEN }} diff --git a/Cargo.toml b/Cargo.toml index 41e1f86..78c704c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gitkit" -version = "0.1.0" +version = "0.1.1" edition = "2021" description = "Standalone CLI for configuring git repos — hooks, .gitignore, and .gitattributes" license = "MIT"