---
name: Release
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
permissions:
contents: write
jobs:
test:
name: Run Tests
uses: ./.github/workflows/test.yml
create-release:
name: Create Release
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Build
run: cargo build --release
- name: Generate changelog
id: changelog
run: |
# Get the tag name (which is the version in semver format)
VERSION=${GITHUB_REF#refs/tags/}
echo "tag_name=$VERSION" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Try to extract from CHANGELOG.md first
if [ -f CHANGELOG.md ]; then
# Extract the section for this version from CHANGELOG.md
CHANGELOG=$(sed -n "/## \[${VERSION}\]/,/## \[/p" CHANGELOG.md | sed '$d' | tail -n +2)
# If not found, try without brackets
if [ -z "$CHANGELOG" ]; then
CHANGELOG=$(sed -n "/## ${VERSION}/,/## /p" CHANGELOG.md | sed '$d' | tail -n +2)
fi
# If still not found or empty, extract from Unreleased
if [ -z "$CHANGELOG" ]; then
CHANGELOG=$(sed -n "/## \[Unreleased\]/,/## \[/p" CHANGELOG.md | sed '$d' | tail -n +2)
fi
fi
# Fall back to git log if CHANGELOG.md doesn't have the info
if [ -z "$CHANGELOG" ]; then
PREVIOUS_TAG=$(git describe --abbrev=0 --tags ${VERSION}^ 2>/dev/null || echo "")
if [ -z "$PREVIOUS_TAG" ]; then
# First release - get all commits
CHANGELOG=$(git log --pretty=format:"- %s (%h)" --no-merges)
else
# Get commits since previous tag
CHANGELOG=$(git log ${PREVIOUS_TAG}..${VERSION} --pretty=format:"- %s (%h)" --no-merges)
fi
fi
# Save to file
echo "# Release $VERSION" > RELEASE_NOTES.md
echo "" >> RELEASE_NOTES.md
echo "$CHANGELOG" >> RELEASE_NOTES.md
# Also save for GitHub output
{
echo 'changelog<<EOF'
cat RELEASE_NOTES.md
echo EOF
} >> $GITHUB_OUTPUT
- name: Create source archives
run: |
VERSION=${GITHUB_REF#refs/tags/}
# Create tarball
git archive --format=tar.gz --prefix=cron-parser-${VERSION}/ HEAD > cron-parser-${VERSION}.tar.gz
# Create zip
git archive --format=zip --prefix=cron-parser-${VERSION}/ HEAD > cron-parser-${VERSION}.zip
# Calculate checksums
sha256sum cron-parser-${VERSION}.tar.gz > cron-parser-${VERSION}.tar.gz.sha256
sha256sum cron-parser-${VERSION}.zip > cron-parser-${VERSION}.zip.sha256
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: Release ${{ steps.changelog.outputs.tag_name }}
body: ${{ steps.changelog.outputs.changelog }}
files: |
cron-parser-*.tar.gz
cron-parser-*.tar.gz.sha256
cron-parser-*.zip
cron-parser-*.zip.sha256
draft: false
prerelease: false
publish-crates-io:
name: Publish to crates.io
runs-on: ubuntu-latest
needs:
- test
- create-release
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Publish to crates.io
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}