Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65444584ad |
@@ -0,0 +1,87 @@
|
|||||||
|
name: Publish Rust crate
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
paths: ['Cargo.toml']
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check-version:
|
||||||
|
name: Check version change
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
changed: ${{ steps.check.outputs.changed }}
|
||||||
|
published: ${{ steps.check.outputs.published }}
|
||||||
|
version: ${{ steps.check.outputs.version }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 2
|
||||||
|
|
||||||
|
- name: Check if version changed
|
||||||
|
id: check
|
||||||
|
run: |
|
||||||
|
NEW_VERSION=$(python3 -c 'import pathlib, tomllib; print(tomllib.loads(pathlib.Path("Cargo.toml").read_text())["package"]["version"])')
|
||||||
|
OLD_VERSION=$(git show HEAD~1:Cargo.toml | python3 -c 'import sys, tomllib; print(tomllib.loads(sys.stdin.read())["package"]["version"])')
|
||||||
|
echo "old=$OLD_VERSION new=$NEW_VERSION"
|
||||||
|
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
if [ "$NEW_VERSION" = "$OLD_VERSION" ]; then
|
||||||
|
echo "changed=false" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "published=false" >> "$GITHUB_OUTPUT"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "changed=true" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
HTTP_STATUS=$(curl --silent --show-error --output /tmp/crate-version.json --write-out "%{http_code}" \
|
||||||
|
-H "User-Agent: firecrawl/pdf-inspector publish workflow (https://github.com/firecrawl/pdf-inspector)" \
|
||||||
|
"https://crates.io/api/v1/crates/pdf-inspector/$NEW_VERSION")
|
||||||
|
|
||||||
|
case "$HTTP_STATUS" in
|
||||||
|
200)
|
||||||
|
echo "published=true" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "pdf-inspector v$NEW_VERSION is already published"
|
||||||
|
;;
|
||||||
|
404)
|
||||||
|
echo "published=false" >> "$GITHUB_OUTPUT"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
cat /tmp/crate-version.json
|
||||||
|
echo "Unexpected crates.io response: $HTTP_STATUS" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
publish:
|
||||||
|
name: Publish to crates.io
|
||||||
|
needs: check-version
|
||||||
|
if: needs.check-version.outputs.changed == 'true' && needs.check-version.outputs.published == 'false'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment: crates-io
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
id-token: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Rust
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
|
||||||
|
- name: Verify package
|
||||||
|
run: cargo publish --dry-run
|
||||||
|
|
||||||
|
- name: Authenticate with crates.io
|
||||||
|
id: auth
|
||||||
|
uses: rust-lang/crates-io-auth-action@v1
|
||||||
|
|
||||||
|
- name: Publish crate
|
||||||
|
run: cargo publish
|
||||||
|
env:
|
||||||
|
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# Publishing
|
||||||
|
|
||||||
|
The Rust crate is published to [crates.io](https://crates.io/crates/pdf-inspector) with trusted publishing from GitHub Actions. The first release was published manually; future releases publish from `.github/workflows/publish-crate.yml` when a `Cargo.toml` version change lands on `main`.
|
||||||
|
|
||||||
|
## crates.io Trusted Publisher
|
||||||
|
|
||||||
|
Configure the trusted publisher for the `pdf-inspector` crate with:
|
||||||
|
|
||||||
|
- Repository: `firecrawl/pdf-inspector`
|
||||||
|
- Workflow: `publish-crate.yml`
|
||||||
|
- Environment: `crates-io`
|
||||||
|
|
||||||
|
The workflow uses `rust-lang/crates-io-auth-action@v1` to exchange GitHub's OIDC token for a short-lived crates.io token, then passes it to `cargo publish`.
|
||||||
|
|
||||||
|
## Release Steps
|
||||||
|
|
||||||
|
1. Update `version` in `Cargo.toml`.
|
||||||
|
2. Merge the version bump to `main`.
|
||||||
|
3. The publish workflow compares the new `Cargo.toml` version with `HEAD~1`, runs `cargo publish --dry-run`, then publishes if that version is not already on crates.io.
|
||||||
|
|
||||||
|
If `Cargo.toml` changes without a package version bump, the workflow exits without publishing.
|
||||||
Reference in New Issue
Block a user