forked from ravsamhq/notify-slack-action
-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (108 loc) · 4.33 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: Create Release
on:
push:
branches:
- master
jobs:
get-admins:
if: github.event.head_commit.message == 'do-production-release'
runs-on: ubuntu-latest
outputs:
admins: ${{ steps.admins.outputs.admins }}
steps:
- name: Dump Github Context
continue-on-error: true
run: |
printf "${{ toJson(github) }}"
- name: Set up Repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get Admins
id: admins
run: |
admins="|`tr '\n' '|' < .github/admins.txt`"
echo "::set-output name=admins::$admins"
echo "Admins: $admins"
create-release:
needs: get-admins
if: github.event.head_commit.message == 'do-production-release' && contains(needs.get-admins.outputs.admins, format('|{0}|', github.event.head_commit.author.username))
runs-on: ubuntu-latest
steps:
- name: Set up Repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get Node Version
id: node_version
run: |
node_version=`cat .nvmrc`
echo "::set-output name=node_version::$node_version"
echo "Node Version: $node_version"
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: ${{ steps.node_version.outputs.node_version }}
- name: Install Semantic Release NPM Dependencies
run: |
npm i -g semantic-release @semantic-release/{commit-analyzer,release-notes-generator}
- name: Run Semantic Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npx semantic-release --repository-url "https://github.com/$GITHUB_REPOSITORY" --branches master --tagFormat \${version} --plugins "@semantic-release/commit-analyzer" "@semantic-release/release-notes-generator" --no-ci --dry-run > temp.txt
- name: Get Last Release Version
continue-on-error: true
run: |
last_version=`git describe --tags --abbrev=0`
echo "Last Version: $last_version"
echo "last_version=$last_version" >> $GITHUB_ENV
- name: Get Next Release Version
run: |
next_version=`cat temp.txt | grep -oP 'Published release \K.*? ' | xargs`
echo "Next Version: $next_version"
echo "next_version=$next_version" >> $GITHUB_ENV
- name: Cancel if Next Version is same as Last Version
if: (env.last_version == env.next_version) || env.next_version == ''
uses: andymckay/[email protected]
- name: Get Major Version related to Next Version
run: |
major_version="v`echo $next_version | cut -d \. -f 1`"
echo "Major Version: $major_version"
echo "major_version=$major_version" >> $GITHUB_ENV
major_version_exists="false"
if git rev-parse $major_version >/dev/null 2>&1; then
major_version_exists="true"
fi
echo "major_version_exists=$major_version_exists" >> $GITHUB_ENV
- name: Generate Release Notes
run: |
release_notes=`cat temp.txt | sed '/^##/,$!d' | awk '{$1=$1};1' | sed 's/))/)/g' | sed 's/ (h/](h/g' | sed 's/^## /## [/' | sed 's/) (/)(/g' | sed 's/ (/ [/g' | sed 's/)(/) (/g' | sed 's/\w/\u&/'`
printf "$release_notes" > RELEASE_NOTES.md
- name: Create Release
uses: ncipollo/release-action@v1
with:
name: ${{ env.next_version }}
tag: ${{ env.next_version }}
commit: master
bodyFile: RELEASE_NOTES.md
prerelease: false
draft: false
token: ${{ secrets.GITHUB_TOKEN }}
- name: Create Major Version Release if it doesn't exist
if: env.major_version_exists == 'false'
uses: ncipollo/release-action@v1
with:
name: ${{ env.major_version }}
tag: ${{ env.major_version }}
commit: master
prerelease: false
draft: false
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update Major Version Release if it exists
if: env.major_version_exists == 'true'
run: |
git config user.name "Github Actions"
git config user.email [email protected]
git tag -fa $major_version -m "chore: point $major_version to $next_version"
git push origin $major_version --force