minor #2
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 | |
run-name: ${{inputs.release_type}} | |
concurrency: | |
cancel-in-progress: false | |
group: '${{ github.workflow }}' | |
on: | |
workflow_dispatch: | |
inputs: | |
release_type: | |
description: "Which type of release is this?" | |
type: choice | |
options: | |
- "patch" | |
- "minor" | |
- "major" | |
default: "patch" | |
permissions: | |
contents: write | |
jobs: | |
prepare: | |
name: Prepare release | |
runs-on: ubuntu-latest | |
outputs: | |
current: ${{ steps.current.outputs.version }} | |
next: ${{ steps.next.outputs.version }} | |
branch: ${{ steps.branch.outputs.branch }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GH_ADMIN_TOKEN }} | |
- name: Configure git | |
run: |- | |
gh api /user > user.json | |
git config --global user.email "$(jq -r '.email' user.json)" | |
git config --global user.name "$(jq -r '.name' user.json)" | |
- name: Prepare branch name | |
id: branch | |
run: echo "branch=release${{ github.run_id }}" >> "$GITHUB_OUTPUT" | |
- name: Create branch | |
run: git checkout -b "${{ steps.branch.outputs.branch }}" | |
- name: Install semver-cli | |
run: |- | |
go install github.com/maykonlf/semver-cli/cmd/semver@latest | |
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH" | |
- name: Get current version | |
id: current | |
run: echo "version=$(semver get release)" >> "$GITHUB_OUTPUT" | |
- name: Get next version | |
id: next | |
env: | |
FLAG: ${{ inputs.release_type == 'patch' && 'release' || inputs.release_type}} | |
run: |- | |
semver up "$FLAG" | |
echo "version=$(semver get release)" >> "$GITHUB_OUTPUT" | |
git add .semver.yaml | |
git commit -m "update .semver.yaml" | |
- name: Prepare environment variables | |
run: |- | |
{ | |
echo "CURRENT=${{steps.current.outputs.version}}" | |
echo "NEXT=${{steps.next.outputs.version}}" | |
echo "CURRENT_CARGO=$(echo '${{ steps.current.outputs.version }}' | sed 's/v//')" | |
echo "NEXT_CARGO=$(echo '${{steps.next.outputs.version}}' | sed 's/v//')" | |
} >> "$GITHUB_ENV" | |
- name: update Cargo.toml | |
run: |- | |
sed -i "s/$CURRENT_CARGO/$NEXT_CARGO/g" Cargo.toml | |
git add Cargo.toml | |
git commit -m "update Cargo.toml" | |
- name: update CHANGELOG.md | |
run: |- | |
head -n 13 CHANGELOG.md > changelog.md.0 | |
tail -n +15 CHANGELOG.md > changelog.md.1 | |
# Reset the file | |
echo -n > CHANGELOG.md | |
{ | |
cat changelog.md.0 | |
echo "## [Unreleased](https://github.com/powerd6/spec/compare/$NEXT...HEAD)" | |
echo "" | |
echo "## [$NEXT](https://github.com/powerd6/spec/releases/tag/$NEXT)" | |
cat changelog.md.1 | |
} >> CHANGELOG.md | |
rm changelog.md.* | |
git add CHANGELOG.md | |
git commit -m "update CHANGELOG.md" | |
- name: Push changes | |
run: git push -u origin "${{ steps.branch.outputs.branch }}" | |
pr: | |
name: Create Pull Request | |
runs-on: ubuntu-latest | |
needs: | |
- prepare | |
outputs: | |
pr: ${{ steps.pr.outputs.link }} | |
env: | |
NEXT: ${{needs.prepare.outputs.next}} | |
GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{needs.prepare.outputs.branch}} | |
- name: Create Pull Request | |
id: pr | |
run: |- | |
PR_URL=$(gh pr create --title "chore: prepare release for $NEXT" --body "") | |
echo "link=$PR_URL" >> "$GITHUB_OUTPUT" | |
- name: Document | |
run: |- | |
echo "[PR link](${{ steps.pr.outputs.link }})" >> "$GITHUB_STEP_SUMMARY" | |
merge: | |
name: Merge Pull Request | |
runs-on: ubuntu-latest | |
needs: pr | |
env: | |
PR_URL: ${{needs.pr.outputs.pr}} | |
GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Merge PR | |
run: gh pr merge "$PR_URL" --admin --squash | |
draft: | |
name: Draft release | |
runs-on: ubuntu-latest | |
needs: | |
- prepare | |
- merge | |
outputs: | |
release: ${{ steps.release.outputs.link }} | |
env: | |
NEXT: ${{needs.prepare.outputs.next}} | |
GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Create Release | |
id: release | |
run: |- | |
RELEASE_URL=$(gh release create "$NEXT" \ | |
--target main \ | |
--title "$NEXT" \ | |
--generate-notes \ | |
--latest \ | |
--draft) | |
echo "link=$RELEASE_URL" >> "$GITHUB_OUTPUT" | |
- name: Document | |
run: |- | |
echo "[Release link](${{ steps.release.outputs.link }})" >> "$GITHUB_STEP_SUMMARY" | |