---
name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
permissions: {}
env:
CARGO_TERM_COLOR: always
jobs:
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
environment: release
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
fetch-depth: 0
persist-credentials: false
- name: Install Rust
run: |
rustup toolchain install stable --profile minimal --no-self-update
rustup default stable
- name: Check that the tag matches the crate versions and is on main
run: |
metadata=$(cargo metadata --no-deps --format-version 1)
version=$(jq -r '.packages[] | select(.name == "pddl") | .version' <<< "$metadata")
core_version=$(jq -r '.packages[] | select(.name == "pddl-core") | .version' <<< "$metadata")
if [ "v$version" != "$GITHUB_REF_NAME" ]; then
echo "::error::Tag $GITHUB_REF_NAME does not match the version $version in pddl/Cargo.toml"
exit 1
fi
if [ "$core_version" != "$version" ]; then
echo "::error::pddl-core is at $core_version, but pddl is at $version; release them together"
exit 1
fi
if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
echo "::error::Tag $GITHUB_REF_NAME points at a commit that is not on main"
exit 1
fi
- name: Run tests
run: |
cargo test --all-features
cargo test --no-default-features
cargo test --no-default-features --features pretty
cargo test --no-default-features --features parser
cargo test -p pddl --all-features
- name: Check which crates are already on crates.io
id: crates-io
run: |
metadata=$(cargo metadata --no-deps --format-version 1)
pending=""
for crate in pddl-runtime pddl-core pddl-codegen pddl-macros pddl; do
version=$(jq -r --arg crate "$crate" '.packages[] | select(.name == $crate) | .version' <<< "$metadata")
response="$RUNNER_TEMP/crates-io-$crate.json"
# --retry covers timeouts, 429 and 5xx; a 404 means "not published yet".
status=$(curl -s --max-time 10 --retry 3 -o "$response" -w '%{http_code}' \
-A "pddl-rs release workflow (https://github.com/sunsided/pddl-rs)" \
"https://crates.io/api/v1/crates/$crate/$version")
case "$status" in
200)
if [ "$(jq -r '.version.yanked' "$response")" != "false" ]; then
echo "::error::$crate $version is on crates.io but yanked; it can't be published again"
exit 1
fi
jq -r --arg crate "$crate" '"\($crate) \(.version.num) is already on crates.io (published \(.version.created_at), checksum \(.version.checksum)); skipping"' "$response"
;;
404) pending="$pending $crate" ;;
*) echo "::error::Unexpected HTTP $status from crates.io for $crate"; exit 1 ;;
esac
done
echo "pending=${pending# }" >> "$GITHUB_OUTPUT"
- name: Authenticate with crates.io
if: steps.crates-io.outputs.pending != ''
id: auth
uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 - name: Publish
if: steps.crates-io.outputs.pending != ''
run: |
for crate in $PENDING; do
cargo publish -p "$crate"
done
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
PENDING: ${{ steps.crates-io.outputs.pending }}
github-release:
name: Create GitHub Release
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with:
persist-credentials: false
- name: Extract release notes from CHANGELOG.md
run: |
version="${GITHUB_REF_NAME#v}"
# The section from "## [X.Y.Z]" up to the next "## " heading, without
# the heading itself and without link definitions like "[X.Y.Z]: https://...".
awk -v heading="## [$version]" '
index($0, heading) == 1 { found = 1; next }
found && /^## / { exit }
found && /^\[[^]]+\]: / { next }
found { print }
' CHANGELOG.md > release-notes.md
- name: Create the release
run: |
if gh release view "$GITHUB_REF_NAME" > /dev/null 2>&1; then
echo "Release $GITHUB_REF_NAME already exists, skipping"
elif grep -q '[^[:space:]]' release-notes.md; then
gh release create "$GITHUB_REF_NAME" --verify-tag --title "$GITHUB_REF_NAME" --notes-file release-notes.md
else
gh release create "$GITHUB_REF_NAME" --verify-tag --title "$GITHUB_REF_NAME" --generate-notes
fi
env:
GH_TOKEN: ${{ github.token }}