Skip to content

Commit 0858581

Browse files
committed
add cargo package publish GA and update readme
1 parent f4e14a9 commit 0858581

3 files changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Publish Crate
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
dry_run:
7+
description: "Run cargo publish --dry-run (recommended first)"
8+
required: true
9+
default: true
10+
type: boolean
11+
expected_tag:
12+
description: "Optional tag to validate against Cargo.toml version (example: v0.1.0)"
13+
required: false
14+
type: string
15+
16+
permissions:
17+
contents: read
18+
19+
concurrency:
20+
group: publish-crate-${{ github.ref }}
21+
cancel-in-progress: false
22+
23+
jobs:
24+
publish:
25+
name: Publish to crates.io
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v6
30+
with:
31+
fetch-depth: 0
32+
33+
- name: Set up Rust
34+
uses: dtolnay/rust-toolchain@stable
35+
36+
- name: Cache cargo artifacts
37+
uses: Swatinem/rust-cache@v2
38+
39+
- name: Read package metadata
40+
id: meta
41+
shell: bash
42+
run: |
43+
PKGID="$(cargo pkgid)"
44+
PACKAGE_NAME="$(echo "$PKGID" | sed -E 's/.*#([^@]+)@.*/\1/')"
45+
PACKAGE_VERSION="$(echo "$PKGID" | sed -E 's/.*@([^ ]+)$/\1/')"
46+
47+
echo "package_name=$PACKAGE_NAME" >> "$GITHUB_OUTPUT"
48+
echo "package_version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
49+
50+
echo "Publishing target: $PACKAGE_NAME@$PACKAGE_VERSION"
51+
52+
- name: Validate expected tag
53+
if: inputs.expected_tag != ''
54+
shell: bash
55+
run: |
56+
EXPECTED="v${{ steps.meta.outputs.package_version }}"
57+
PROVIDED="${{ inputs.expected_tag }}"
58+
if [ "$EXPECTED" != "$PROVIDED" ]; then
59+
echo "::error::Tag mismatch. Provided '$PROVIDED' but Cargo.toml expects '$EXPECTED'."
60+
exit 1
61+
fi
62+
63+
- name: Dry run publish
64+
if: inputs.dry_run
65+
run: cargo publish --dry-run
66+
67+
- name: Publish
68+
if: ${{ !inputs.dry_run }}
69+
env:
70+
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
71+
shell: bash
72+
run: |
73+
if [ -z "$CRATES_IO_TOKEN" ]; then
74+
echo "::error::Missing CRATES_IO_TOKEN repository secret."
75+
exit 1
76+
fi
77+
cargo publish --token "$CRATES_IO_TOKEN"

CONTRIBUTING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ cargo test
6161
`filo` follows SemVer and uses the package version in `Cargo.toml` as the source of truth.
6262

6363
- `Cargo.toml` `[package].version` is the crate/app version.
64+
- crates.io package name is `filo-rs`.
65+
- Installed CLI command remains `filo`.
6466
- `filo --version` comes from that same Cargo package version.
6567
- Release tags should match the package version with a leading `v`.
6668

@@ -77,6 +79,17 @@ Suggested release flow:
7779
4. Bump/finalize version to `X.Y.Z` (without prerelease suffix) if needed.
7880
5. Tag `main` with `vX.Y.Z` and push the tag. GitHub will publish a stable release.
7981

82+
## Publishing to crates.io
83+
84+
- Use the dedicated `Publish Crate` workflow (manual trigger) instead of coupling crate publish to the tag release workflow.
85+
- Add `CRATES_IO_TOKEN` in repository secrets before first publish.
86+
- Run a dry run first, then run a real publish.
87+
88+
Why separate workflows?
89+
90+
- GitHub Release creation and crates.io publishing have different failure/retry behavior.
91+
- `cargo publish` is immutable per version; separating it reduces accidental publishes.
92+
8093
## Pull Request Checklist
8194

8295
- [ ] Code is formatted (`cargo fmt --check`)

readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ that's the point.
5858

5959
## Installation
6060

61+
### From crates.io (recommended)
62+
63+
```bash
64+
cargo install filo-rs
65+
```
66+
67+
The package name is `filo-rs`, and the installed command is still `filo`.
68+
6169
### From source
6270

6371
Requires Rust `1.85` or newer.

0 commit comments

Comments
 (0)