-
Notifications
You must be signed in to change notification settings - Fork 0
216 lines (177 loc) · 6.28 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
213
214
215
216
name: Release
on:
push:
branches:
- master
jobs:
setup_release:
name: Prepare release
permissions:
contents: write
issues: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: cache NPM
uses: actions/[email protected]
id: npm-cache
with:
path: |
**/node_modules
${{ needs.install.outputs.npm-cache-dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Setup Node.js environment
uses: actions/[email protected]
with:
node-version: "lts/*"
- name: Install dependencies
run: npm ci
- name: next release version
id: next_release_version
run: |
export NEXT_TAG_VERSION=$(npx semantic-release --dry-run | grep 'The next release version is' | sed -E 's/.* ([[:digit:].]+)$/\1/')
echo "new_tag_version=${NEXT_TAG_VERSION}" >> $GITHUB_OUTPUT
echo "new_tag_version=${NEXT_TAG_VERSION}"
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
outputs:
new_tag_version: ${{ steps.next_release_version.outputs.new_tag_version }}
process_test_adoc:
name: Process test.adoc
needs: setup_release
if: ${{ needs.setup_release.outputs.new_tag_version != '' }}
runs-on: ubuntu-latest
env:
FILE: test.adoc
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Print orig file
run: |
cat ${{ env.FILE }}
- name: Update version and date in file
if: ${{needs.setup_release.outputs.new_tag_version != ''}}
run: |
echo "new_tag_version=${{ needs.setup_release.outputs.new_tag_version }}"
# Get the version from the output of the Semantic Release step
VERSION=${{ needs.setup_release.outputs.new_tag_version }}
# Get the current date
DATE=$(date +%Y-%m-%d)
# Regular expression to match the string to be replaced
REGEX="v[0-9]\+\.[0-9]\+\.[0-9]\+\, [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}"
# Replace the string in file
sed -i "s/$REGEX/v$VERSION, $DATE/g" $FILE
- name: Print new file
if: ${{needs.setup_release.outputs.new_tag_version != ''}}
run: |
cat ${{ env.FILE }}
- name: Upload updated file
uses: actions/upload-artifact@v4
with:
name: updated-test-adoc
path: ${{ env.FILE }}
- name: Set output
id: output_version
run: echo "new_tag_version=${{ needs.setup_release.outputs.new_tag_version }}" >> $GITHUB_OUTPUT
outputs:
new_tag_version: ${{ steps.output_version.outputs.new_tag_version }}
process_file2_md:
name: Process file2.md
needs: setup_release
if: ${{ needs.setup_release.outputs.new_tag_version != '' }}
runs-on: ubuntu-latest
env:
FILE: file2.md
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Print orig file
run: |
cat ${{ env.FILE }}
- name: Update version and date in file
if: ${{needs.setup_release.outputs.new_tag_version != ''}}
run: |
echo "new_tag_version=${{ needs.setup_release.outputs.new_tag_version }}"
# Get the version from the output of the Semantic Release step
VERSION=${{ needs.setup_release.outputs.new_tag_version }}
# Get the current date
DATE=$(date +%Y-%m-%d)
# Regular expression to match the string to be replaced
REGEX="v[0-9]\+\.[0-9]\+\.[0-9]\+\, [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}"
# Replace the string in file
sed -i "s/$REGEX/v$VERSION, $DATE/g" $FILE
- name: Print new file
if: ${{needs.setup_release.outputs.new_tag_version != ''}}
run: |
cat ${{ env.FILE }}
- name: Upload updated file
uses: actions/upload-artifact@v4
with:
name: updated-file2-md
path: ${{ env.FILE }}
- name: Set output
id: output_version
run: echo "new_tag_version=${{ needs.setup_release.outputs.new_tag_version }}" >> $GITHUB_OUTPUT
outputs:
new_tag_version: ${{ steps.output_version.outputs.new_tag_version }}
complete_release:
name: Complete release
needs: [setup_release, process_test_adoc, process_file2_md]
if: ${{ needs.setup_release.outputs.new_tag_version != '' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Download updated test.adoc
uses: actions/download-artifact@v4
with:
name: updated-test-adoc
- name: Download updated file2.md
uses: actions/download-artifact@v4
with:
name: updated-file2-md
- name: Print files
run: |
echo "Updated test.adoc"
cat test.adoc
echo "Updated file2.md"
cat file2.md
- name: cache NPM
uses: actions/[email protected]
id: npm-cache
with:
path: |
**/node_modules
${{ needs.install.outputs.npm-cache-dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Setup Node.js environment
uses: actions/[email protected]
with:
node-version: "lts/*"
- name: Install dependencies
run: npm ci
- name: Release with next Semantic Version
id: release_with_next_semantic_version
if: ${{needs.setup_release.outputs.new_tag_version != ''}}
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
GIT_COMMITTER_NAME: "Arc-E-Tect"
GIT_COMMITTER_EMAIL: "[email protected]"
GIT_AUTHOR_NAME: "Arc-E-Tect"
GIT_AUTHOR_EMAIL: "[email protected]"
- name: No release with next Semantic Version
if: ${{needs.setup_release.outputs.new_tag_version == ''}}
run: echo "No new release required..."