-
-
Notifications
You must be signed in to change notification settings - Fork 1
314 lines (276 loc) · 12.5 KB
/
build-and-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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
name: Build and Deploy on Commit
permissions:
contents: write
on:
push:
branches:
- main
jobs:
build-windows:
name: Build on Windows
runs-on: windows-latest
# Only run when the commit message contains "releaseIt"
if: contains(github.event.head_commit.message, 'releaseIt')
steps:
# ––– Checkout repositories –––
- name: Checkout chemical-bootstrap repository
uses: actions/checkout@v3
with:
repository: chemicallang/chemical-bootstrap
token: ${{ secrets.GITHUB_TOKEN }}
path: chemical-bootstrap
# Checkout chemical repository inside chemical-bootstrap
- name: Checkout chemical repository inside chemical-bootstrap
uses: actions/checkout@v3
with:
repository: chemicallang/chemical
token: ${{ secrets.GITHUB_TOKEN }}
path: chemical-bootstrap/chemical
# ––– Setup build environment –––
- name: Set up Visual Studio Developer Command Prompt
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x86_64
# Get the SHA of the chemical-bootstrap repository
- name: Get SHA of chemical-bootstrap repository
id: get-sha
shell: pwsh
working-directory: chemical-bootstrap
run: |
$sha = (git rev-parse HEAD).Trim()
echo "sha=$sha" >> $env:GITHUB_OUTPUT
# Setup Cache for out-win folder
- uses: actions/cache@v4
id: bootstrap-cache
with:
path: ./chemical-bootstrap/out-win/
key: ${{ runner.os }}-${{ steps.get-sha.outputs.sha }}
# Build the chemical-bootstrap project (only if not cached)
- name: Build chemical-bootstrap (Windows)
working-directory: chemical-bootstrap
run: .\build.bat native-windows-gnu native
if: steps.bootstrap-cache.outputs.cache-hit != 'true'
# Build the chemical project executables via CMake
- name: Build chemical project (Windows)
working-directory: chemical-bootstrap/chemical
run: |
mkdir out\release
cmake -S . -B out\build\x64-release -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build out\build\x64-release --config Release --target Compiler
cmake --build out\build\x64-release --config Release --target TCCCompiler
cmake --build out\build\x64-release --config Release --target ChemicalLsp || true
env:
BOOST_ROOT: ${{ env.BOOST_ROOT }}
# Run the release script to create ZIP files
- name: Run release packaging script (Windows)
working-directory: chemical-bootstrap/chemical
# Assuming Git Bash is available on windows-latest (if not, you might need to install/setup MSYS2)
run: bash release.sh
# ––– Get information about the latest release –––
- name: Get latest release info
id: get_latest_release
uses: actions/github-script@v6
with:
script: |
const releasesResponse = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
});
const validReleases = releasesResponse.data.filter(release => !release.draft);
if (validReleases.length === 0) {
throw new Error("No published or pre-releases found.");
}
const latestRelease = validReleases[0];
core.setOutput("tag", latestRelease.tag_name);
core.setOutput("id", latestRelease.id);
# ––– For each archive we check whether it is already attached –––
- name: Check if windows-x64.zip exists in latest release
id: check_windows_x64
uses: actions/github-script@v6
with:
script: |
const tag = '${{ steps.get_latest_release.outputs.tag }}';
const { data: release } = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: tag
});
const exists = release.assets.some(asset => asset.name === 'windows-x64.zip');
core.setOutput("exists", exists.toString());
- name: Upload windows-x64.zip to release if not exists
if: steps.check_windows_x64.outputs.exists == 'false'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.get_latest_release.outputs.tag }}
files: chemical-bootstrap/chemical/out/release/windows-x64.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Save windows-x64.zip as artifact if already exists
if: steps.check_windows_x64.outputs.exists == 'true'
uses: actions/upload-artifact@v4
with:
name: windows-x64.zip
path: chemical-bootstrap/chemical/out/release/windows-x64.zip
# Repeat similar steps for the second Windows archive:
- name: Check if windows-x64-tcc.zip exists in latest release
id: check_windows_x64_tcc
uses: actions/github-script@v6
with:
script: |
const tag = '${{ steps.get_latest_release.outputs.tag }}';
const { data: release } = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: tag
});
const exists = release.assets.some(asset => asset.name === 'windows-x64-tcc.zip');
core.setOutput("exists", exists.toString());
- name: Upload windows-x64-tcc.zip to release if not exists
if: steps.check_windows_x64_tcc.outputs.exists == 'false'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.get_latest_release.outputs.tag }}
files: chemical-bootstrap/chemical/out/release/windows-x64-tcc.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Save windows-x64-tcc.zip as artifact if already exists
if: steps.check_windows_x64_tcc.outputs.exists == 'true'
uses: actions/upload-artifact@v4
with:
name: windows-x64-tcc.zip
path: chemical-bootstrap/chemical/out/release/windows-x64-tcc.zip
build-linux:
name: Build on Linux
runs-on: ubuntu-latest
# Only run when the commit message contains "releaseIt"
if: contains(github.event.head_commit.message, 'releaseIt')
steps:
# ––– Checkout repositories –––
- name: Checkout chemical-bootstrap repository
uses: actions/checkout@v3
with:
repository: chemicallang/chemical-bootstrap
token: ${{ secrets.GITHUB_TOKEN }}
path: chemical-bootstrap
# Checkout chemical repository inside chemical-bootstrap
- name: Checkout chemical repository inside chemical-bootstrap
uses: actions/checkout@v3
with:
repository: chemicallang/chemical
token: ${{ secrets.GITHUB_TOKEN }}
path: chemical-bootstrap/chemical
# ––– Install dependencies –––
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake git
# (Do not install libboost-all-dev since we want Boost 1.74.0)
# Get the SHA of the chemical-bootstrap repository
- name: Get SHA of chemical-bootstrap repository
id: get-sha
working-directory: chemical-bootstrap
run: |
SHA=$(git rev-parse HEAD | xargs)
echo "sha=$SHA" >> $GITHUB_OUTPUT
# Setup Cache for out folder
- uses: actions/cache@v4
id: bootstrap-cache
with:
path: ./chemical-bootstrap/out/
key: ${{ runner.os }}-${{ steps.get-sha.outputs.sha }}
# Build the chemical-bootstrap project (Linux) (only if not cached)
- name: Build chemical-bootstrap (Linux)
working-directory: chemical-bootstrap
run: |
chmod +x build
./build native-linux-gnu native
if: steps.bootstrap-cache.outputs.cache-hit != 'true'
# Build the chemical project executables via CMake
- name: Build chemical project (Linux)
working-directory: chemical-bootstrap/chemical
run: |
mkdir -p out/release
cmake -S . -B out/build/x64-release-wsl -DCMAKE_BUILD_TYPE=Release
cmake --build out/build/x64-release-wsl --config Release --target Compiler
cmake --build out/build/x64-release-wsl --config Release --target TCCCompiler
cmake --build out/build/x64-release-wsl --config Release --target ChemicalLsp || true
env:
BOOST_ROOT: ${{ env.BOOST_ROOT }}
# Run the release packaging script to create ZIP files
- name: Run release packaging script (Linux)
working-directory: chemical-bootstrap/chemical
run: |
chmod +x release.sh
./release.sh
# ––– Get information about the latest release –––
- name: Get latest release info
id: get_latest_release
uses: actions/github-script@v6
with:
script: |
const releasesResponse = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
});
const validReleases = releasesResponse.data.filter(release => !release.draft);
if (validReleases.length === 0) {
throw new Error("No published or pre-releases found.");
}
const latestRelease = validReleases[0];
core.setOutput("tag", latestRelease.tag_name);
core.setOutput("id", latestRelease.id);
# ––– Check and (conditionally) upload Linux archives –––
- name: Check if linux-x86-64.zip exists in latest release
id: check_linux_x64
uses: actions/github-script@v6
with:
script: |
const tag = '${{ steps.get_latest_release.outputs.tag }}';
const { data: release } = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: tag
});
const exists = release.assets.some(asset => asset.name === 'linux-x86-64.zip');
core.setOutput("exists", exists.toString());
- name: Upload linux-x86-64.zip to release if not exists
if: steps.check_linux_x64.outputs.exists == 'false'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.get_latest_release.outputs.tag }}
files: chemical-bootstrap/chemical/out/release/linux-x86-64.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Save linux-x86-64.zip as artifact if already exists
if: steps.check_linux_x64.outputs.exists == 'true'
uses: actions/upload-artifact@v4
with:
name: linux-x86-64.zip
path: chemical-bootstrap/chemical/out/release/linux-x86-64.zip
- name: Check if linux-x86-64-tcc.zip exists in latest release
id: check_linux_x64_tcc
uses: actions/github-script@v6
with:
script: |
const tag = '${{ steps.get_latest_release.outputs.tag }}';
const { data: release } = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: tag
});
const exists = release.assets.some(asset => asset.name === 'linux-x86-64-tcc.zip');
core.setOutput("exists", exists.toString());
- name: Upload linux-x86-64-tcc.zip to release if not exists
if: steps.check_linux_x64_tcc.outputs.exists == 'false'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.get_latest_release.outputs.tag }}
files: chemical-bootstrap/chemical/out/release/linux-x86-64-tcc.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Save linux-x86-64-tcc.zip as artifact if already exists
if: steps.check_linux_x64_tcc.outputs.exists == 'true'
uses: actions/upload-artifact@v4
with:
name: linux-x86-64-tcc.zip
path: chemical-bootstrap/chemical/out/release/linux-x86-64-tcc.zip