name: Release
on:
push:
tags: ["v*"]
permissions:
contents: write
jobs:
build:
name: Build (${{ matrix.target }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2.9.1
with:
key: ${{ matrix.target }}
- run: cargo build --release --target ${{ matrix.target }}
- name: Package binary
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../decruft-${{ matrix.target }}.tar.gz decruft
cd ../../..
- uses: actions/upload-artifact@v7
with:
name: decruft-${{ matrix.target }}
path: decruft-${{ matrix.target }}.tar.gz
release:
name: Create Release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Generate changelog
id: changelog
run: |
# Get previous tag
PREV_TAG=$(git tag --sort=-version:refname | head -2 | tail -1)
TAG=${GITHUB_REF#refs/tags/}
# Generate changelog from commits since last tag
echo "## ${TAG}" > /tmp/changelog_entry.md
echo "" >> /tmp/changelog_entry.md
if [ -n "$PREV_TAG" ]; then
git log --pretty=format:"- %s" "${PREV_TAG}..HEAD" >> /tmp/changelog_entry.md
else
git log --pretty=format:"- %s" >> /tmp/changelog_entry.md
fi
echo "" >> /tmp/changelog_entry.md
# Prepend to CHANGELOG.md
if [ -f CHANGELOG.md ]; then
cat /tmp/changelog_entry.md CHANGELOG.md > /tmp/changelog_full.md
else
echo "# Changelog" > /tmp/changelog_full.md
echo "" >> /tmp/changelog_full.md
cat /tmp/changelog_entry.md >> /tmp/changelog_full.md
fi
mv /tmp/changelog_full.md CHANGELOG.md
# Commit changelog
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git commit -m "Update CHANGELOG for ${TAG}" || true
git push origin HEAD:main || true
- uses: actions/download-artifact@v8
with:
merge-multiple: true
- uses: softprops/action-gh-release@v2.6.1
with:
generate_release_notes: true
files: decruft-*.tar.gz
publish:
name: Publish to crates.io
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
- run: cargo publish || echo "Already published (expected for re-runs)"
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}