1
+ name : Commit New Version Action
2
+
3
+ on :
4
+ push :
5
+ branches :
6
+ - master
7
+
8
+ jobs :
9
+ create-release :
10
+ if : |
11
+ contains(github.event.head_commit.message, 'commit new version') == true
12
+ runs-on : ubuntu-latest
13
+
14
+ steps :
15
+ - name : Checkout code
16
+ uses : actions/checkout@v2
17
+
18
+ - name : Extract Version
19
+ id : extract-version
20
+ run : |
21
+ # Use grep to find the first occurrence of the version number matching "## version" pattern
22
+ version=$(grep -m 1 -oP '## \d+\.\d+\.\d+(-\w+)?' CHANGELOG.md | cut -d ' ' -f 2)
23
+ echo "version=$version" >> $GITHUB_ENV
24
+
25
+ - name : Extract Changelog
26
+ id : extract-changelog
27
+ run : |
28
+ # Extract the content between the last two version headers
29
+ changelog=$(awk '/^## [0-9]+\.[0-9]+\.[0-9]+/{if (!version) {version=$0; next}} /^## [0-9]+\.[0-9]+\.[0-9]+/{exit} {if (version) description = description ORS $0} END {if (version) print description}' CHANGELOG.md | sed -e '/^## [0-9]+\.[0-9]+\.[0-9]+/d; s/^# //' > changelog.txt)
30
+ echo "changelog_file=changelog.txt" >> $GITHUB_ENV
31
+
32
+ - name : Create Release
33
+ id : create-release
34
+ uses : actions/create-release@v1
35
+ env :
36
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
37
+ with :
38
+ tag_name : ${{ env.version }}
39
+ release_name : ${{ env.version }}
40
+ body_path : ${{ env.changelog_file }}
41
+ draft : false
42
+ prerelease : false
43
+
44
+ - name : Post to a Slack channel
45
+ if : success()
46
+ id : slack
47
+
48
+ env :
49
+ SLACK_BOT_TOKEN : ${{ secrets.SLACK_BOT_TOKEN }}
50
+ REPOSITORY_NAME : ${{ github.repository }}
51
+ RELEASE_URL : ${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ env.version }}
52
+ with :
53
+ # You can pass in multiple channels to post to by providing a comma-delimited list of channel IDs.
54
+ channel-id : ' git-releases'
55
+ payload-file-path : " ./.github/slack/payload-slack-content-commit.json"
0 commit comments