1+ name : release
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ version :
7+ description : " The version to release"
8+ type : string
9+
10+ permissions :
11+ contents : write
12+ pull-requests : read
13+ statuses : write
14+ packages : write
15+
16+ jobs :
17+ release :
18+ name : release
19+ runs-on : ubuntu-latest
20+ timeout-minutes : 15
21+ outputs :
22+ has-changes : ${{ steps.check-changes.outputs.has-changes }}
23+ next-version : ${{ steps.next-version.outputs.NEXT_VERSION }}
24+ commit-hash : ${{ steps.auto-commit-action.outputs.commit_hash }}
25+ steps :
26+ - uses : actions/checkout@v6
27+ with :
28+ fetch-depth : 0
29+ - uses : jdx/mise-action@v3
30+ with :
31+ experimental : true
32+ - name : check for changes since last release
33+ id : check-changes
34+ run : |
35+ LAST_TAG=$(git tag -l | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1)
36+ if [ -z "$LAST_TAG" ]; then
37+ echo "No previous Log releases found, will release"
38+ echo "has-changes=true" >> $GITHUB_OUTPUT
39+ else
40+ if [ -n "$(git diff --name-only ${LAST_TAG}..HEAD)" ]; then
41+ echo "Log changes found since $LAST_TAG"
42+ echo "has-changes=true" >> $GITHUB_OUTPUT
43+ else
44+ echo "No Log changes since $LAST_TAG"
45+ echo "has-changes=false" >> $GITHUB_OUTPUT
46+ fi
47+ fi
48+ - name : Get next version
49+ id : next-version
50+ if : steps.check-changes.outputs.has-changes == 'true'
51+ env :
52+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
53+ run : |
54+ NEXT_VERSION=$(git cliff --config ./cliff.toml --bumped-version)
55+ echo "NEXT_VERSION=$NEXT_VERSION" >> "$GITHUB_OUTPUT"
56+ echo "Next Log version will be: $NEXT_VERSION"
57+ - name : Update CHANGELOG.md
58+ if : steps.check-changes.outputs.has-changes == 'true'
59+ env :
60+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
61+ run : git cliff --config ./cliff.toml --bump -o ./CHANGELOG.md
62+ - name : Update README.md version
63+ if : steps.check-changes.outputs.has-changes == 'true'
64+ run : |
65+ sed -i -E 's|https://github.com/space-code/log.git", from: "[0-9]+\.[0-9]+\.[0-9]+"|https://github.com/space-code/log.git", from: "'"${{ steps.next-version.outputs.NEXT_VERSION }}"'"|g' README.md
66+ echo "Updated README.md with version ${{ steps.next-version.outputs.NEXT_VERSION }}"
67+ - name : Get release notes
68+ id : release-notes
69+ if : steps.check-changes.outputs.has-changes == 'true'
70+ env :
71+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
72+ run : |
73+ echo "RELEASE_NOTES<<EOF" >> "$GITHUB_OUTPUT"
74+
75+ echo "All notable changes to this project will be documented in this file." >> "$GITHUB_OUTPUT"
76+ echo "" >> "$GITHUB_OUTPUT"
77+ echo "The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)," >> "$GITHUB_OUTPUT"
78+ echo "and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)." >> "$GITHUB_OUTPUT"
79+ echo "" >> "$GITHUB_OUTPUT"
80+
81+ git cliff --config ./cliff.toml --tag ${{ steps.next-version.outputs.NEXT_VERSION }} --unreleased --strip header | awk 'NF{p=1} p' | tail -n +2 >> "$GITHUB_OUTPUT"
82+
83+ echo "EOF" >> "$GITHUB_OUTPUT"
84+ - name : Commit changes
85+ id : auto-commit-action
86+ uses : stefanzweifel/git-auto-commit-action@v7
87+ if : steps.check-changes.outputs.has-changes == 'true'
88+ with :
89+ commit_options : " --allow-empty --no-verify"
90+ tagging_message : ${{ steps.next-version.outputs.NEXT_VERSION }}
91+ skip_dirty_check : true
92+ commit_message : " [Release] Log ${{ steps.next-version.outputs.NEXT_VERSION }}"
93+ - name : Create GitHub Release
94+ uses : softprops/action-gh-release@v2
95+ if : steps.check-changes.outputs.has-changes == 'true'
96+ with :
97+ draft : false
98+ repository : space-code/log
99+ name : ${{ steps.next-version.outputs.NEXT_VERSION }}
100+ tag_name : ${{ steps.next-version.outputs.NEXT_VERSION }}
101+ body : ${{ steps.release-notes.outputs.RELEASE_NOTES }}
102+ target_commitish : ${{ steps.auto-commit-action.outputs.commit_hash }}
0 commit comments