name: Release
on:
push:
tags:
- "v*"
permissions:
id-token: write
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
verify:
name: Verify the tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- name: The tag must match the manifest
run: |
tag="${GITHUB_REF_NAME#v}"
manifest=$(python3 -c \
"import tomllib; print(tomllib.load(open('Cargo.toml','rb'))['package']['version'])")
echo "tag $tag, manifest $manifest"
if [ "$tag" != "$manifest" ]; then
echo "::error::the tag says $tag and the manifest says $manifest"
exit 1
fi
- name: The changelog must hold the version
run: |
tag="${GITHUB_REF_NAME#v}"
if ! grep -q "^## \[$tag\]" CHANGELOG.md; then
echo "::error::CHANGELOG.md holds no section for $tag"
exit 1
fi
- name: The manifest must hold no patch
run: |
if grep -q "^\[patch" Cargo.toml; then
echo "::error::Cargo.toml holds a live [patch] section"
exit 1
fi
- run: cargo fmt --all --check
- run: cargo clippy --all-targets
env:
RUSTFLAGS: -D warnings
- run: cargo test
publish:
name: Publish to crates.io
needs: verify
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: rust-lang/crates-io-auth-action@v1
id: auth
- run: cargo publish --token ${{ steps.auth.outputs.token }}
release:
name: Write the GitHub release
needs: publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Take the notes from the changelog
run: |
python3 - "$GITHUB_REF_NAME" <<'EOF' > notes.md
import re, sys
tag = sys.argv[1].lstrip("v")
text = open("CHANGELOG.md").read()
start = text.index(f"## [{tag}]")
body = text[start:].split("\n", 1)[1]
end = re.search(r"^## \[", body, re.M)
print((body[: end.start()] if end else body).strip())
print("\n## Install\n\n```sh\ncargo add labstream\n```\n")
EOF
- name: Write the release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "$GITHUB_REF_NAME" \
--title "$GITHUB_REF_NAME" \
--notes-file notes.md \
--verify-tag