Skip to content

Commit 722b226

Browse files
committed
feat!: deploy creates a PR, and merging it will create a release
1 parent 03240f7 commit 722b226

2 files changed

Lines changed: 98 additions & 22 deletions

File tree

.github/workflows/auto-release.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Auto-release following a release commit
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
paths:
9+
- 'docs/CHANGELOG.md'
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
RELEASE_VERSION: ${{ steps.parse_commit.outputs.RELEASE_VERSION }}
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Parse commit message to get version
21+
id: parse_commit
22+
run: |
23+
# Commit message must be in the format of
24+
# "chore: release vX.X"
25+
VERSION=$(echo "$COMMIT_MESSAGE" | grep -oP '^chore:\ release\ v[a-zA-Z0-9.\-\+]+' | head -n 1 | cut -d' ' -f3)
26+
if [[ -z "$VERSION" ]]; then
27+
echo "Commit message does not match the expected format. Please use 'chore: release vX.X.X' format in your commit message."
28+
echo "Commit message: $COMMIT_MESSAGE"
29+
exit 1
30+
fi
31+
echo "RELEASE_VERSION=$VERSION" >> "$GITHUB_OUTPUT"
32+
33+
env:
34+
# Avoid script injection by using an environment variable
35+
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
36+
37+
- name: Parse CHANGELOG.md to get release notes
38+
id: parse_changelog
39+
uses: kiyoon/parse-changelog-action@v1
40+
with:
41+
changelog-path: docs/CHANGELOG.md
42+
version: ${{ steps.parse_commit.outputs.RELEASE_VERSION }}
43+
44+
- name: Create Release
45+
id: create_release
46+
uses: softprops/action-gh-release@v2
47+
with:
48+
tag_name: ${{ steps.parse_commit.outputs.RELEASE_VERSION }}
49+
name: ${{ steps.parse_commit.outputs.RELEASE_VERSION }}
50+
body: ${{ steps.parse_changelog.outputs.body }}
51+
52+
deploy-mkdocs:
53+
needs: release
54+
uses: deargen/workflows/.github/workflows/deploy-mkdocs.yml@master
55+
with:
56+
requirements-file: deps/lock/x86_64-manylinux_2_28/requirements_docs.txt
57+
gitlab-project: ${{ vars.GITLAB_PROJECT }}
58+
gitlab-branch: master
59+
version-tag: ${{ needs.release.outputs.RELEASE_VERSION }}
60+
deploy-type: tag
61+
secrets:
62+
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}

.github/workflows/deploy.yml

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
name: Commit CHANGELOG.md, create a Release and deploy MkDocs
1+
name: Deploy
22

33
on:
44
workflow_dispatch:
55
inputs:
66
version-tag:
77
description: Version tag
88
required: true
9-
default: v0.1.0
10-
dry-run:
9+
default: 'v0.1.0'
10+
dry-run: # print the changelog without creating a PR.
1111
description: Dry run
1212
type: boolean
1313
default: false
@@ -17,23 +17,37 @@ on:
1717
default: build,docs,style,other
1818

1919
jobs:
20-
commit-changelog-and-release:
21-
uses: deargen/workflows/.github/workflows/commit-changelog-and-release.yml@master
22-
with:
23-
version-tag: ${{ github.event.inputs.version-tag }}
24-
dry-run: ${{ github.event.inputs.dry-run == 'true' }}
25-
changelog-path: docs/CHANGELOG.md
26-
exclude-types: ${{ github.event.inputs.exclude-types }}
20+
changelog:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
2725

28-
deploy-mkdocs:
29-
if: ${{ github.event.inputs.dry-run == 'false' }}
30-
needs: commit-changelog-and-release
31-
uses: deargen/workflows/.github/workflows/deploy-mkdocs.yml@master
32-
with:
33-
requirements-file: deps/lock/x86_64-manylinux_2_28/requirements_docs.txt
34-
gitlab-project: ${{ vars.GITLAB_PROJECT }}
35-
gitlab-branch: master
36-
version-tag: ${{ github.event.inputs.version-tag }}
37-
deploy-type: tag
38-
secrets:
39-
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
26+
- name: Get CHANGELOG
27+
id: changelog
28+
uses: kiyoon/changelog-action@v2
29+
with:
30+
new-version-tag-for-future: ${{ github.event.inputs.version-tag }}
31+
tag-prefix: v
32+
exclude-types: ${{ github.event.inputs.exclude-types }}
33+
write-to-file: true
34+
changelog-file-path: docs/CHANGELOG.md
35+
36+
- name: Display CHANGELOG
37+
env:
38+
CHANGES_BODY: ${{ steps.changelog.outputs.changes }}
39+
run: |
40+
echo "${CHANGES_BODY}"
41+
echo "${CHANGES_BODY}" > "$GITHUB_STEP_SUMMARY"
42+
43+
- name: Create PR
44+
if: ${{ github.event.inputs.dry-run == 'false' }}
45+
uses: peter-evans/create-pull-request@v7
46+
with:
47+
commit-message: 'chore: release ${{ github.event.inputs.version-tag }}'
48+
title: 'chore: release ${{ github.event.inputs.version-tag }}'
49+
body: |
50+
:robot: The changelog was automatically generated by [kiyoon/changelog-action](https://github.com/kiyoon/changelog-action). :robot:
51+
branch: chore/release-${{ github.event.inputs.version-tag }}
52+
labels: |
53+
release

0 commit comments

Comments
 (0)