Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 40 additions & 24 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,60 @@ 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

- uses: DeterminateSystems/nix-installer-action@main

- 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:
Expand All @@ -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 }}
26 changes: 16 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
'';
};

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading