name: Release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
verify:
name: Verify (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
link_tests: true
- os: macos-latest
link_tests: true
- os: windows-latest
link_tests: false
steps:
- uses: actions/checkout@v7
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@stable
- name: Check tag matches Cargo.toml version
if: runner.os == 'Linux'
shell: bash
run: |
set -euo pipefail
tag="${GITHUB_REF_NAME#v}"
crate="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)"
echo "tag=${tag} crate=${crate}"
if [ "${tag}" != "${crate}" ]; then
echo "::error::Git tag v${tag} does not match Cargo.toml version ${crate}"
exit 1
fi
- name: Install libvips (Linux)
if: runner.os == 'Linux' && matrix.link_tests
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libvips-dev
- name: Install libvips (macOS)
if: runner.os == 'macOS' && matrix.link_tests
run: |
brew install vips pkg-config
echo "PKG_CONFIG_PATH=$(brew --prefix vips)/lib/pkgconfig:$(brew --prefix)/lib/pkgconfig" >> "$GITHUB_ENV"
- name: cargo check
run: cargo check --features helpers
- name: cargo test
if: matrix.link_tests
run: cargo test --features helpers
- name: Package dry-run
if: runner.os == 'Linux'
run: |
cargo package --list
# Pregenerated bindings compile without system libvips for packaging.
cargo publish --dry-run --features helpers
publish:
name: Publish crates.io and GitHub Release
needs: verify
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v7
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@stable
- name: Publish to crates.io
run: cargo publish --locked --token "${CRATES_IO_TOKEN}"
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
- name: Extract changelog for this version
id: changelog
shell: bash
run: |
set -euo pipefail
ver="${GITHUB_REF_NAME#v}"
awk -v ver="$ver" '
$0 ~ "^## \\[" ver "\\]" {grab=1; next}
grab && /^## \[/ {exit}
grab {print}
' CHANGELOG.md > release-notes.md
if [ ! -s release-notes.md ]; then
echo "No CHANGELOG section for ${ver}; using tag name only." >&2
echo "v${ver}" > release-notes.md
fi
cat release-notes.md
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: ${{ github.ref_name }}
body_path: release-notes.md
draft: false
prerelease: ${{ contains(github.ref_name, '-') }}
generate_release_notes: false