Skip to content
Merged
81 changes: 52 additions & 29 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ name: Release and publish

on:
workflow_dispatch:
pull_request_target:
types:
- closed

permissions:
contents: write
pull-requests: write

jobs:
release:
prepare:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

outputs:
version: ${{ steps.version-label.outputs.version }}
Expand All @@ -19,13 +24,6 @@ jobs:
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]"
Expand Down Expand Up @@ -58,36 +56,46 @@ jobs:
}
echo "changelog<<EOF"$'\n'"$(generate)"$'\n'EOF >> $GITHUB_OUTPUT

- name: Update CHANGELOG.md
- name: Update changelog.txt
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
echo "# [v${{ steps.version-label.outputs.version }}] - `date +%d-%m-%Y`" >> changelog.txt.tmp
echo "${{steps.generate-release-notes.outputs.changelog}}" >> changelog.txt.tmp
echo '-n' >> changelog.txt
cat changelog.txt >> changelog.txt.tmp
mv changelog.txt.tmp changelog.txt

- 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
run: git add -f changelog.txt README.md

- 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
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
commit-message: "[skip test] update changelog"
title: "[skip test] Release v${{ steps.version-label.outputs.version }}"
body: >
This is an automated PR to build the latest changelog. Upon merging,
a new release will be created and published to crates.io.<br/>
Due to security considerations, PRs created by GitHub Actions cannot
be merged automatically. Please review the changes and merge the PR.<br/>
If you require the test suites to run, you can close the PR and reopen it to trigger
those workflows.
delete-branch: true
labels: release
branch: "release/v${{ steps.version-label.outputs.version }}"

- name: Enable Pull Request Automerge
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}

publish:
needs: release
release:
if: ${{ (github.event.pull_request.merged == true) && (contains(github.event.pull_request.labels.*.name, 'release')) }}
runs-on: ubuntu-latest
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
Expand All @@ -97,8 +105,23 @@ jobs:
with:
submodules: recursive

- 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: 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: Login to Crates.io
run: cargo login ${CRATES_IO_TOKEN}

- name: Publish GitHub release
run: |
gh release create v${{ steps.version-label.outputs.version }} --generate-notes

- name: Publish crate
run: cargo publish
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "comrak"
version = "0.23.1-pre.1"
version = "0.23.0"
authors = ["Amelia Cuss <[email protected]>"]
rust-version = "1.62.1"
description = "A 100% CommonMark-compatible GitHub Flavored Markdown parser and formatter"
Expand Down
Loading