From ddbafb1f7853a4258420372acabd4329b68d76eb Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 27 Apr 2026 22:05:36 -0400 Subject: [PATCH] switch to PR-based release flow with publish on merge --- .github/workflows/publish.yml | 64 ++++++++++++++++++++++------------- flake.nix | 26 ++++++++------ 2 files changed, 56 insertions(+), 34 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 866697b..3c1d730 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,41 +2,48 @@ name: Publish to crates.io on: push: - tags: ["v*"] + branches: [main] + paths: + - "Cargo.toml" + +permissions: + contents: write env: CARGO_TERM_COLOR: always RUST_BACKTRACE: 1 jobs: - test: - name: Test + check-version: + name: Check version change runs-on: ubuntu-latest + outputs: + version: ${{ steps.detect.outputs.version }} + changed: ${{ steps.detect.outputs.changed }} steps: - uses: actions/checkout@v4 - - - uses: DeterminateSystems/nix-installer-action@main - - - uses: DeterminateSystems/magic-nix-cache-action@main - - - name: Check - run: nix develop --command cargo check --workspace - - - name: Clippy - run: nix develop --command cargo clippy --workspace -- -D warnings - - - name: Test - run: nix develop --command cargo test --workspace - - - name: Derive tests - run: nix develop --command cargo test -p packr-abi --features derive + with: + fetch-depth: 2 + + - name: Detect version change + id: detect + run: | + NEW=$(grep -m1 '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/') + OLD=$(git show HEAD~1:Cargo.toml 2>/dev/null | grep -m1 '^version = ' | sed 's/version = "\(.*\)"/\1/' || echo "") + echo "version=$NEW" >> "$GITHUB_OUTPUT" + if [ "$NEW" != "$OLD" ] && [ -n "$OLD" ]; then + echo "changed=true" >> "$GITHUB_OUTPUT" + echo "Version changed: $OLD -> $NEW" + else + echo "changed=false" >> "$GITHUB_OUTPUT" + echo "No version change (current: $NEW)" + fi publish: name: Publish runs-on: ubuntu-latest - needs: test - permissions: - contents: write + needs: check-version + if: needs.check-version.outputs.changed == 'true' steps: - uses: actions/checkout@v4 @@ -44,6 +51,11 @@ jobs: - uses: DeterminateSystems/magic-nix-cache-action@main + - name: Test + run: | + nix develop --command cargo test --workspace + nix develop --command cargo test -p packr-abi --features derive + - name: Publish packr-derive run: nix develop --command cargo publish -p packr-derive env: @@ -69,7 +81,11 @@ jobs: env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} - - name: Create GitHub release - run: gh release create "${{ github.ref_name }}" --generate-notes + - name: Create tag and GitHub release + run: | + VERSION="v${{ needs.check-version.outputs.version }}" + git tag "$VERSION" + git push origin "$VERSION" + gh release create "$VERSION" --generate-notes env: GH_TOKEN: ${{ github.token }} diff --git a/flake.nix b/flake.nix index aedec2f..0171f51 100644 --- a/flake.nix +++ b/flake.nix @@ -66,7 +66,7 @@ echo " cargo clippy --workspace - Lint" echo " nix run .#test - Run full test suite" echo " nix run .#pr - Create PR from jj revision" - echo " nix run .#release -- patch - Bump version, tag, publish" + echo " nix run .#release -- patch - Bump version, create release PR" ''; }; @@ -103,7 +103,8 @@ echo "All tests passed!" ''; - # Release: bump version, commit, tag, push + # Release: bump version and create a PR + # After merge, CI publishes to crates.io and creates the git tag packages.release = pkgs.writeShellScriptBin "pack-release" '' set -e @@ -139,22 +140,27 @@ echo "Updated to v$NEW" echo "" - # Commit and tag + BRANCH="release-v$NEW" + if command -v jj &>/dev/null; then jj describe -m "release v$NEW" - # Use git directly for the tag — jj bookmarks are branches, not tags - COMMIT=$(jj log -r @ --no-graph -T 'commit_id' 2>/dev/null) - ${pkgs.git}/bin/git tag "v$NEW" "$COMMIT" - ${pkgs.git}/bin/git push origin "refs/tags/v$NEW" + jj bookmark create "$BRANCH" -r @ 2>/dev/null || jj bookmark set "$BRANCH" -r @ + jj git push --bookmark "$BRANCH" --allow-new else + git checkout -b "$BRANCH" git add -A git commit -m "release v$NEW" - git tag "v$NEW" - git push origin "refs/tags/v$NEW" + git push -u origin "$BRANCH" fi + ${pkgs.gh}/bin/gh pr create \ + --title "release v$NEW" \ + --body "Bump version to v$NEW. Merging will publish to crates.io and create a GitHub release." \ + --base main \ + --head "$BRANCH" + echo "" - echo "Pushed v$NEW — CI will publish to crates.io" + echo "PR created. Merge to publish v$NEW to crates.io." ''; # Create a PR from the current jj revision