Release and publish #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release and publish | |
on: | |
workflow_dispatch: | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.version-label.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: true | |
- name: Setup Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
override: true | |
- name: Configure Git | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "Actions Auto Build" | |
- name: Get current version | |
id: version-label | |
run: | | |
VERSION=$(grep version Cargo.toml | head -n 1 | cut -d'"' -f2) | |
echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
- name: Get previous version | |
id: previous-version-label | |
run: | | |
PREVIOUS_VERSION=$(gh api "/repos/${{ github.repository }}/tags?per_page=1" | jq -r '.[] | .name?') | |
echo "previous_version=${PREVIOUS_VERSION}" >> $GITHUB_OUTPUT | |
- name: Generate Release Notes | |
id: generate-release-notes | |
run: | | |
generate() { | |
gh api \ | |
--method POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/${{ github.repository }}/releases/generate-notes \ | |
-f tag_name='v${{ steps.version-label.outputs.version }}' \ | |
-f previous_tag='v${{ steps.previous-version-label.outputs.previous_version }}' \ | |
| jq -r ".body" | |
} | |
echo "changelog<<EOF"$'\n'"$(generate)"$'\n'EOF >> $GITHUB_OUTPUT | |
- name: Update CHANGELOG.md | |
run: | | |
echo "## [v${{ steps.version-label.outputs.version }}] - `date +%d-%m-%Y`" >> CHANGELOG.md.tmp | |
echo "${{steps.generate-release-notes.outputs.changelog}}" >> CHANGELOG.md.tmp | |
echo '-n' >> CHANGELOG.md | |
cat CHANGELOG.md >> CHANGELOG.md.tmp | |
mv CHANGELOG.md.tmp CHANGELOG.md | |
- name: Update README | |
run: | | |
cargo run --example update-readme | |
- name: Commit Changelog and README | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "Actions Auto Build" | |
git add -f CHANGELOG.md README.md | |
git commit -m "[auto-docs][skip test]: update changelog" || true | |
- name: Create tag | |
run: | | |
git tag -a v${{ steps.version-label.outputs.version }} -m "Release v${{ steps.version-label.outputs.version }}" | |
git push origin --tags | |
- name: Publish GitHub release | |
run: | | |
gh release create v${{ steps.version-label.outputs.version }} --generate-notes | |
publish: | |
needs: release | |
runs-on: ubuntu-latest | |
env: | |
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Login to Crates.io | |
run: cargo login ${CRATES_IO_TOKEN} | |
- name: Publish crate | |
run: cargo publish |