-
-
Notifications
You must be signed in to change notification settings - Fork 13
212 lines (198 loc) · 6.18 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
name: Release
on:
push:
branches:
- master
paths-ignore:
- CHANGELOG.md
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Lint the codebase
run: npm run lint:ci
test_and_report_coverage:
name: Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Run tests
run: npm run test:ci
- name: Upload coverage
uses: actions/upload-artifact@v4
with:
name: test_coverage
path: coverage
build_code:
name: Build code
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Build code
run: npm run build:ci
- name: Upload the dist folder
uses: actions/upload-artifact@v4
with:
name: dist
path: dist
integration_tests:
name: Run integration tests
runs-on: ubuntu-latest
needs: build_code
steps:
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Download dist/ folder
uses: actions/download-artifact@v4
with:
name: dist
path: dist
- name: Run integration tests
run: npm run test:integration:ci
build_docs:
name: Build Docs
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Build storybook
run: npm run docs:ci
- name: Upload the docs
uses: actions/upload-artifact@v4
with:
name: docs
path: docs
changelog:
name: Generate new changelog
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
ssh-key: '${{ secrets.SSH_PRIVATE_KEY }}'
persist-credentials: 'true'
fetch-tags: 'true'
fetch-depth: 0
- name: Generate changelog
run: |
changelog=""
# Get all tags in ascending order
tags=($( git tag --sort=version:refname ))
# Loop through tags to generate the changelog
for ((i=0; i<${#tags[@]}; i++)); do
current_tag="${tags[$i]}"
previous_tag=""
tag_log=""
if [ -z "${current_tag}" ]; then
continue
fi
# Determine the previous tag if not the first tag
if (( i > 0 )); then
previous_tag="${tags[$((i-1))]}"
fi
# Generate the header for the current tag
tag_log="### ${current_tag}\n"
# Get the commits between the current tag and the previous tag
if [ -n "$previous_tag" ]; then
commits=$(git log --format="%s (%an) [%h]" "${previous_tag}..${current_tag}")
else
# If no previous tag, include all commits up to the first tag
commits=$(git log --format="%s (%an) [%h]" "${current_tag}")
fi
# Add commits to the changelog, one per line
while IFS= read -r commit; do
tag_log+="- ${commit}\n"
done <<< "${commits}"
changelog="${tag_log}\n${changelog}"
done
changelog="# Changelog\n\n${changelog}"
echo -e "${changelog}"
# You can now use the variable $changelog elsewhere in your script
printf '%b' "${changelog}" > CHANGELOG.md
- name: Upload new changelog
uses: actions/upload-artifact@v4
with:
name: changelog
path: CHANGELOG.md
- name: Commit and push the new changelog
run: |
if [ -z $(git status -uno --porcelain) ]; then
printf 'Changelogs are identical, nothing to commit\n'
else
printf 'Committing the updated changelog\n'
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git commit -am "Update the project changelog"
fi
- name: Push changes
uses: ad-m/[email protected]
with:
ssh: true
branch: '${{ github.ref }}'
maybe_tag:
name: Maybe tag the release
runs-on: ubuntu-latest
needs: [lint, test_and_report_coverage, build_code, build_docs, integration_tests, changelog]
outputs:
tag_name: '${{ steps.tagging.outputs.tagname }}'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Maybe generate tag
uses: Klemensas/action-autotag@stable
with:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
tag_prefix: ''
tag_suffix: ''
changelog_structure: "**{{messageHeadline}}** {{author}}\n"
trigger_publish:
name: Maybe trigger publish
runs-on: ubuntu-latest
needs: [maybe_tag]
if: ${{ needs.maybe_tag.outputs.tagname != '' }}
steps:
- name: Download the tag file
uses: actions/download-artifact@v4
with:
name: tag_lock
path: tag_lock
- name: Checkout
uses: actions/checkout@v4
with:
set-safe-directory: 'true'
fetch-tags: 'true'
- name: Trigger the publish workflow
run: gh workflow run publish.yml --ref ${{ needs.maybe_tag.outputs.tagname }}
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'