-
Notifications
You must be signed in to change notification settings - Fork 3
159 lines (139 loc) · 5.61 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Release
on:
push:
branches:
- main
paths-ignore:
- README.md
- CHANGELOG.md
env:
VERSION_FILE: package.json
ADDITIONAL_VERSION_FILE: package-lock.json
VERSION_EXTRACT_PATTERN: '"version": "([^"]+)",'
VERSION_REPLACE_PATTERN: '"version": "\1",'
GH_USER_NAME: github.actor
CHANGE_LOG_FILE: CHANGELOG.md
TMP_SUFFIX: _updated
README_FILE: README.md
README_TEMPLATE_FILE: README_TEMPLATE.md
README_VERSION_PLACEHOLDER: $LATEST_VERSION
jobs:
build:
runs-on: ubuntu-latest
steps:
# Prepare
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Setup git credentials
run: |
git config user.name 'Vadzim Hushchanskou'
git config user.email '[email protected]'
git config user.password ${{ secrets.GITHUB_TOKEN }}
- name: Generate versions
uses: HardNorth/github-version-generate@v1
with:
version-source: file
version-file: ${{ env.VERSION_FILE }}
version-file-extraction-pattern: ${{ env.VERSION_EXTRACT_PATTERN }}
# Test and Build
- name: Install dependencies
run: npm ci
- name: Test with Jest
run: npm run test
- name: Test with ESLint
run: npm run lint
- name: Build with ncc
run: npm run build
# Compile
- name: Install vercel/ncc
run: npm i -g @vercel/ncc
- name: Compile
run: ncc build src/index.js -o build
# Update repository with new files and version
- name: Update build
id: buildUpdate
run: |
git add build/index.js
git commit -m "Compiled version ${{ env.RELEASE_VERSION }}"
- name: Update README.md
id: readmeUpdate
run: |
sed 's/${{ env.README_VERSION_PLACEHOLDER }}/${{ env.RELEASE_VERSION }}/g' ${{ env.README_TEMPLATE_FILE }} > ${{ env.README_FILE }}
git add ${{ env.README_FILE }}
git commit -m "Readme update"
- name: Update CHANGELOG.md
id: changelogUpdate
run: |
sed '/\[Unreleased\]/q' ${{ env.CHANGE_LOG_FILE }} >> ${{ env.CHANGE_LOG_FILE }}${{ env.TMP_SUFFIX }}
sed -E '1,/#?#\s*\[Unreleased\]/d' ${{ env.CHANGE_LOG_FILE }} | sed -E '/#?#\s*\[/q' | \
{ echo -e '\n## [${{ env.RELEASE_VERSION }}]'; sed '$d'; } >> ${{ env.CHANGE_LOG_FILE }}${{ env.TMP_SUFFIX }}
grep -E '#?#\s*\[[0-9]' ${{ env.CHANGE_LOG_FILE }} | head -n1 >> ${{ env.CHANGE_LOG_FILE }}${{ env.TMP_SUFFIX }}
sed -E '1,/#?#\s*\[[0-9]/d' ${{ env.CHANGE_LOG_FILE }} >> ${{ env.CHANGE_LOG_FILE }}${{ env.TMP_SUFFIX }}
rm ${{ env.CHANGE_LOG_FILE }}
mv ${{ env.CHANGE_LOG_FILE }}${{ env.TMP_SUFFIX }} ${{ env.CHANGE_LOG_FILE }}
git add ${{ env.CHANGE_LOG_FILE }}
git commit -m "Changelog update"
git push
- name: Tagging new version
id: newVersionTag
run: |
RELEASE_TAG="v${{ env.RELEASE_VERSION }}"
MINOR_TAG="v${{ env.RELEASE_VERSION_MAJOR }}.${{ env.RELEASE_VERSION_MINOR }}"
MAJOR_TAG="v${{ env.RELEASE_VERSION_MAJOR }}"
git tag -d "${MINOR_TAG}" || true
git tag -d "${MAJOR_TAG}" || true
git push origin ":${MINOR_TAG}" || true
git push origin ":${MAJOR_TAG}" || true
git tag -a "${RELEASE_TAG}" -m "Release ${{ env.RELEASE_VERSION }}"
git tag -a "${MINOR_TAG}" -m "Tag latest minor version"
git tag -a "${MAJOR_TAG}" -m "Tag latest major version"
git push --tags
- name: Read changelog Entry
id: readChangelogEntry
uses: mindsers/[email protected]
with:
version: ${{ env.RELEASE_VERSION }}
path: ./${{ env.CHANGE_LOG_FILE }}
- name: Create Release
id: createRelease
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.RELEASE_VERSION }}
release_name: Release ${{ env.RELEASE_VERSION }}
body: ${{ steps.readChangelogEntry.outputs.log_entry }}
draft: false
prerelease: false
- name: Checkout develop branch
if: ${{github.ref}} == 'main'
uses: actions/checkout@v3
with:
ref: 'develop'
fetch-depth: 0
- name: Merge release branch into develop
id: mergeIntoDevelop
if: ${{github.ref}} == 'main'
run: |
git merge -m 'Merge main branch into develop after a release' origin/main
git status | (! grep -Fq 'both modified:') || git status | grep -F 'both modified:' \
| { echo -e 'Unable to merge main into develop, merge conflicts:'; (! grep -Eo '[^ ]+$') }
- name: Update version file
id: versionFileUpdate
run: |
export CURRENT_VERSION_VALUE=`echo '${{ env.CURRENT_VERSION }}' | sed -E 's/(.*)/${{ env.VERSION_REPLACE_PATTERN }}/'`
export NEXT_VERSION_VALUE=`echo '${{ env.NEXT_VERSION }}' | sed -E 's/(.*)/${{ env.VERSION_REPLACE_PATTERN }}/'`
sed "s/${CURRENT_VERSION_VALUE}/${NEXT_VERSION_VALUE}/g" ${{ env.VERSION_FILE }} > ${{ env.VERSION_FILE }}${{ env.TMP_SUFFIX }}
sed "s/${CURRENT_VERSION_VALUE}/${NEXT_VERSION_VALUE}/g" ${{ env.ADDITIONAL_VERSION_FILE }} > ${{ env.ADDITIONAL_VERSION_FILE }}${{ env.TMP_SUFFIX }}
rm ${{ env.VERSION_FILE }}
mv ${{ env.VERSION_FILE }}${{ env.TMP_SUFFIX }} ${{ env.VERSION_FILE }}
rm ${{ env.ADDITIONAL_VERSION_FILE }}
mv ${{ env.ADDITIONAL_VERSION_FILE }}${{ env.TMP_SUFFIX }} ${{ env.ADDITIONAL_VERSION_FILE }}
git add ${{ env.VERSION_FILE }}
git add ${{ env.ADDITIONAL_VERSION_FILE }}
git commit -m "Version update"
git push