1818 types : [completed]
1919 branches : [main]
2020
21+ pull_request :
22+ types : [closed]
23+ branches : [main]
24+
2125concurrency :
2226 group : release
2327 cancel-in-progress : false
@@ -30,17 +34,16 @@ jobs:
3034 runs-on : ubuntu-latest
3135 if : >-
3236 github.event_name == 'workflow_dispatch' ||
33- (github.event.workflow_run.conclusion == 'success' &&
37+ (github.event_name == 'workflow_run' &&
38+ github.event.workflow_run.conclusion == 'success' &&
3439 github.event.workflow_run.head_branch == 'main')
3540 outputs :
3641 version : ${{ steps.bump.outputs.version }}
3742 skip : ${{ steps.check.outputs.skip }}
38- sha : ${{ steps.push.outputs.sha }}
3943 steps :
4044 - uses : actions/checkout@v6
4145 with :
4246 fetch-depth : 0
43- token : ${{ secrets.GITHUB_TOKEN }}
4447
4548 - name : Check if release commit
4649 id : check
@@ -88,27 +91,42 @@ jobs:
8891 echo "version=${NEW_VERSION}" >> "$GITHUB_OUTPUT"
8992 echo "Bumped $CURRENT -> $NEW_VERSION ($BUMP)"
9093
91- - name : Commit and tag
94+ - name : Create release PR
9295 if : steps.check.outputs.skip != 'true'
9396 id : push
97+ env :
98+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
9499 run : |
95100 VERSION="${{ steps.bump.outputs.version }}"
101+ BRANCH="release-v${VERSION}"
102+
96103 git config user.name "github-actions[bot]"
97104 git config user.email "github-actions[bot]@users.noreply.github.com"
105+
106+ git checkout -b "$BRANCH"
98107 git add version.json
99- git commit -m "release: v${VERSION}"
100- git tag -a "v${VERSION}" -m "v${VERSION}"
101- git push origin main --follow-tags
102- echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
108+ git commit -m "release: v${VERSION} [no ci]"
109+ git push origin "$BRANCH"
110+
111+ gh pr create \
112+ --base main \
113+ --head "$BRANCH" \
114+ --title "release: v${VERSION}" \
115+ --body "Automated release v${VERSION}"
116+ gh pr merge "$BRANCH" --auto --squash --delete-branch
103117
104118 publish-nuget :
105119 runs-on : ubuntu-latest
106- needs : version
107- if : needs.version.outputs.skip != 'true'
120+ if : >-
121+ github.event_name == 'pull_request' &&
122+ github.event.pull_request.merged == true &&
123+ startsWith(github.event.pull_request.title, 'release: v')
108124 steps :
109125 - uses : actions/checkout@v6
110- with :
111- ref : ${{ needs.version.outputs.sha }}
126+
127+ - name : Extract version
128+ id : version
129+ run : echo "version=$(jq -r .version version.json)" >> "$GITHUB_OUTPUT"
112130
113131 - name : Setup .NET
114132 uses : actions/setup-dotnet@v5
@@ -128,19 +146,23 @@ jobs:
128146 run : dotnet restore
129147
130148 - name : Pack
131- run : dotnet pack -c Release -p:Version=${{ needs .version.outputs.version }} --no-restore -o ./nupkgs
149+ run : dotnet pack -c Release -p:Version=${{ steps .version.outputs.version }} --no-restore -o ./nupkgs
132150
133151 - name : Push to NuGet
134152 run : dotnet nuget push ./nupkgs/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
135153
136154 publish-npm :
137155 runs-on : ubuntu-latest
138- needs : version
139- if : needs.version.outputs.skip != 'true'
156+ if : >-
157+ github.event_name == 'pull_request' &&
158+ github.event.pull_request.merged == true &&
159+ startsWith(github.event.pull_request.title, 'release: v')
140160 steps :
141161 - uses : actions/checkout@v6
142- with :
143- ref : ${{ needs.version.outputs.sha }}
162+
163+ - name : Extract version
164+ id : version
165+ run : echo "version=$(jq -r .version version.json)" >> "$GITHUB_OUTPUT"
144166
145167 - name : Setup Node.js
146168 uses : actions/setup-node@v6
@@ -159,29 +181,34 @@ jobs:
159181 env :
160182 NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
161183 run : |
162- VERSION="${{ needs .version.outputs.version }}"
184+ VERSION="${{ steps .version.outputs.version }}"
163185 for pkg in packages/SimpleModule.Client packages/SimpleModule.UI packages/SimpleModule.Theme.Default; do
164186 (cd "$pkg" && npm version "$VERSION" --no-git-tag-version && npm publish --access public)
165187 done
166188
167189 github-release :
168190 runs-on : ubuntu-latest
169- needs : [version, publish-nuget, publish-npm]
170- if : needs.version.outputs.skip != 'true'
191+ needs : [publish-nuget, publish-npm]
192+ if : >-
193+ github.event_name == 'pull_request' &&
194+ github.event.pull_request.merged == true &&
195+ startsWith(github.event.pull_request.title, 'release: v')
171196 permissions :
172197 contents : write
173198 steps :
174199 - uses : actions/checkout@v6
175200 with :
176- ref : v${{ needs.version.outputs.version }}
177201 fetch-depth : 0
178202
179- - name : Create GitHub Release
203+ - name : Create tag and GitHub Release
180204 env :
181205 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
182206 run : |
183- VERSION="${{ needs.version.outputs.version }}"
207+ VERSION="$(jq -r .version version.json)"
208+ git config user.name "github-actions[bot]"
209+ git config user.email "github-actions[bot]@users.noreply.github.com"
210+ git tag -a "v${VERSION}" -m "v${VERSION}"
211+ git push origin "v${VERSION}"
184212 gh release create "v${VERSION}" \
185213 --title "v${VERSION}" \
186- --generate-notes \
187- --verify-tag
214+ --generate-notes
0 commit comments