Skip to content

ci: add changelog release workflow #1

ci: add changelog release workflow

ci: add changelog release workflow #1

Workflow file for this run

name: Release
on:
push:
tags:
- "v*.*.*"
permissions:
contents: write
jobs:
release:
name: Validate and publish release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust toolchain
run: |
rustup toolchain install stable --profile minimal
rustup default stable
rustup component add clippy rustfmt
- name: Validate tag version
run: |
set -eu
tag="${GITHUB_REF_NAME}"
version="${tag#v}"
cargo_version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1)"
if [ "$tag" = "$version" ]; then
echo "Release tags must start with v, for example v0.1.0." >&2
exit 1
fi
if [ "$version" != "$cargo_version" ]; then
echo "Tag $tag does not match Cargo.toml version $cargo_version." >&2
exit 1
fi
- name: Extract changelog notes
run: |
set -eu
version="${GITHUB_REF_NAME#v}"
awk -v version="$version" '
$0 ~ "^## \\[" version "\\]" {
found = 1
print
next
}
found && /^## \[/ {
exit
}
found {
print
}
END {
if (!found) {
exit 1
}
}
' CHANGELOG.md > release-notes.md
if [ "$(wc -l < release-notes.md)" -lt 3 ]; then
echo "CHANGELOG.md entry for $version is missing release notes." >&2
exit 1
fi
- name: Check formatting
run: cargo fmt --check
- name: Lint
run: cargo clippy --all-targets -- -D warnings
- name: Test
run: cargo test
- name: Build
run: cargo build --release
- name: Ensure release does not already exist
env:
GH_TOKEN: ${{ github.token }}
run: |
set -eu
if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then
echo "Release $GITHUB_REF_NAME already exists." >&2
exit 1
fi
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "$GITHUB_REF_NAME" \
--verify-tag \
--title "$GITHUB_REF_NAME" \
--notes-file release-notes.md