-
Notifications
You must be signed in to change notification settings - Fork 69
386 lines (332 loc) · 12.6 KB
/
linux.yml
File metadata and controls
386 lines (332 loc) · 12.6 KB
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
name: Build Linux
on:
push:
branches: [master]
pull_request:
branches: [master]
merge_group:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
IMAGE_NAME: rusty
jobs:
check:
name: Check
runs-on: ubuntu-latest
container: ghcr.io/plc-lang/rust-llvm:latest
steps:
- uses: actions/checkout@v6
- name: Run Check
run: |
./scripts/build.sh --check
test-linux:
name: Test Linux
runs-on: ${{ matrix.config.os }}
strategy:
matrix:
config:
- { os: "ubuntu-latest" }
- { os: "ubuntu-24.04-arm" }
steps:
- name: Free up disk space on runner
uses: jlumbroso/free-disk-space@main
with:
tool-cache: true
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: false
swap-storage: true
- name: Show disk space after cleanup
run: df -h
- uses: actions/checkout@v6
- name: Cargo test
run: |
docker run --rm \
--entrypoint /bin/bash \
-v ${{ github.workspace }}:/workspace \
-w /workspace \
ghcr.io/plc-lang/rust-llvm:latest \
-c "df -h && ./scripts/build.sh --build --test"
package-linux:
name: Package Linux (${{ matrix.config.arch }})
runs-on: ${{ matrix.config.os }}
strategy:
matrix:
config:
- { os: "ubuntu-latest", arch: "x86_64" }
- { os: "ubuntu-24.04-arm", arch: "aarch64" }
container: ghcr.io/plc-lang/rust-llvm:latest
steps:
- uses: actions/checkout@v6
- name: Release Build (native ${{ matrix.config.arch }})
shell: bash
run: |
echo "Building native binary for ${{ matrix.config.arch }}"
./scripts/build.sh --build --release --package --deb
- name: Build and package the std lib
if: matrix.config.arch == 'x86_64'
shell: bash
run: |
# required by aarch64 build
apt update && apt install -y gcc-aarch64-linux-gnu
# Clean up apt cache to free disk space
apt-get clean
rm -rf /var/lib/apt/lists/*
echo "Build command : ./scripts/build.sh --build --release"
./scripts/build.sh --build --release --package --deb \
--target x86_64-linux-gnu,aarch64-linux-gnu,x86_64-unknown-linux-gnu,aarch64-unknown-linux-gnu
- uses: actions/upload-artifact@v7
with:
name: plc-${{ matrix.config.arch }}
path: target/release/plc
if-no-files-found: error
- uses: actions/upload-artifact@v7
if: matrix.config.arch == 'x86_64'
with:
name: stdlib
path: output/
- uses: actions/upload-artifact@v7
if: matrix.config.arch == 'x86_64'
with:
name: schema
path: compiler/plc_project/schema/
- uses: actions/upload-artifact@v7
with:
name: deb-${{ matrix.config.arch }}
path: target/debian/*.deb
if-no-files-found: error
build-and-push-image:
name: Build Image (${{ matrix.config.arch }})
runs-on: ${{ matrix.config.os }}
needs: package-linux
strategy:
matrix:
config:
- { os: "ubuntu-latest", arch: "x86_64", docker_arch: "amd64" }
- { os: "ubuntu-24.04-arm", arch: "aarch64", docker_arch: "arm64" }
permissions:
actions: read
packages: write
contents: read
steps:
- uses: actions/checkout@v6
- name: Download deb artifacts (x86_64)
uses: actions/download-artifact@v8
with:
name: deb-x86_64
path: artifacts/deb-x86_64/
- name: Download deb artifacts (aarch64)
uses: actions/download-artifact@v8
with:
name: deb-aarch64
path: artifacts/deb-aarch64/
- name: Prepare deb artifacts
run: |
mkdir -p artifacts/deb
# Debug: show artifact structure
echo "Artifact structure:"
find artifacts/ -name "*.deb" -type f
# Copy the plc binary deb for this image's architecture only
find artifacts/deb-${{ matrix.config.arch }}/ -name "plc-compiler_*_${{ matrix.config.docker_arch }}.deb" -exec cp {} artifacts/deb/ \;
# Copy plc-stdlib debs for BOTH architectures (cross-compilation support)
find artifacts/deb-x86_64/ -name "plc-stdlib_*_amd64.deb" -exec cp {} artifacts/deb/ \;
find artifacts/deb-aarch64/ -name "plc-stdlib_*_arm64.deb" -exec cp {} artifacts/deb/ \;
# Validate that expected files were copied
echo "Deb packages for Docker image (${{ matrix.config.docker_arch }}):"
ls -la artifacts/deb/
if [ -z "$(ls -A artifacts/deb/*.deb 2>/dev/null)" ]; then
echo "ERROR: No deb files were copied to artifacts/deb/"
exit 1
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build Docker image
run: |
docker buildx build . \
--platform linux/${{ matrix.config.docker_arch }} \
--file Dockerfile \
--tag ${{ env.IMAGE_NAME }}:local \
--load
- name: Log in to registry
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name != 'pull_request' && github.ref == 'refs/heads/master')
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image with temp tag
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name != 'pull_request' && github.ref == 'refs/heads/master')
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
TEMP_TAG="build-${{ github.run_id }}-${{ matrix.config.arch }}"
docker tag ${{ env.IMAGE_NAME }}:local $IMAGE_ID:$TEMP_TAG
docker push $IMAGE_ID:$TEMP_TAG
echo "Pushed: $IMAGE_ID:$TEMP_TAG"
- name: Simulate push (PR only)
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "=========================================="
echo "SIMULATION MODE (Pull Request)"
echo "Would push: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:build-${{ github.run_id }}-${{ matrix.config.arch }}"
echo "Platform: linux/${{ matrix.config.docker_arch }}"
echo "=========================================="
push-multiplatform:
name: Push Multiplatform Manifest
needs: build-and-push-image
runs-on: ubuntu-latest
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name != 'pull_request' && github.ref == 'refs/heads/master')
permissions:
packages: write
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push manifest
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
echo "Creating multiplatform manifest..."
docker buildx imagetools create \
-t $IMAGE_ID:latest \
$IMAGE_ID:build-${{ github.run_id }}-x86_64 \
$IMAGE_ID:build-${{ github.run_id }}-aarch64
echo "Pushed: $IMAGE_ID:latest"
- name: Cleanup temp tags
if: always()
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Delete temp images by tag
for ARCH in x86_64 aarch64; do
TEMP_TAG="build-${{ github.run_id }}-$ARCH"
echo "Deleting $TEMP_TAG..."
# Get version ID for this tag
VERSION_ID=$(gh api \
-H "Accept: application/vnd.github+json" \
"/orgs/${{ github.repository_owner }}/packages/container/${{ env.IMAGE_NAME }}/versions" \
--jq ".[] | select(.metadata.container.tags[] == \"$TEMP_TAG\") | .id")
if [ -n "$VERSION_ID" ]; then
gh api --method DELETE \
-H "Accept: application/vnd.github+json" \
"/orgs/${{ github.repository_owner }}/packages/container/${{ env.IMAGE_NAME }}/versions/$VERSION_ID" || true
echo "Deleted version $VERSION_ID"
fi
done
echo "Cleanup complete"
style:
name: Check Style
runs-on: ubuntu-latest
container: ghcr.io/plc-lang/rust-llvm:latest
steps:
- uses: actions/checkout@v6
- name: Run Checks
run: |
./scripts/build.sh --check-style
coverage:
name: Run Coverage
runs-on: ubuntu-latest
steps:
- name: Free up disk space on runner
uses: jlumbroso/free-disk-space@main
with:
tool-cache: true
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: false
swap-storage: true
- name: Show disk space after cleanup
run: df -h
- uses: actions/checkout@v6
- name: Run coverage in container
run: |
docker run --rm \
--entrypoint /bin/bash \
-v ${{ github.workspace }}:/workspace \
-w /workspace \
ghcr.io/plc-lang/rust-llvm:latest \
-c "df -h && apt-get clean && rm -rf /var/lib/apt/lists/* && ./scripts/build.sh --coverage"
- name: Upload to codecov.io
uses: codecov/codecov-action@v6
with:
files: lcov.info
- name: Archive code coverage results
uses: actions/upload-artifact@v7
with:
name: code-coverage-report
path: lcov.info
pr-artifacts:
name: PR Artifacts
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
needs: package-linux
permissions:
pull-requests: write
steps:
- uses: actions/github-script@v9
with:
script: |
const { data: artifacts } = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId,
});
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const lines = artifacts.artifacts
.filter(a => a.name !== 'code-coverage-report')
.map(a => `| \`${a.name}\` | [Download](${runUrl}/artifacts/${a.id}) | ${(a.size_in_bytes / 1024 / 1024).toFixed(1)} MB |`);
const section = [
'#### :penguin: Linux',
'| Artifact | Link | Size |',
'|----------|------|------|',
...lines,
'',
`_From [workflow run](${runUrl})_`,
].join('\n');
const COMMENT_MARKER = '<!-- pr-artifacts -->';
const SECTION_START = '<!-- linux-start -->';
const SECTION_END = '<!-- linux-end -->';
const sectionBlock = `${SECTION_START}\n${section}\n${SECTION_END}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes(COMMENT_MARKER));
if (existing) {
const re = new RegExp(`${SECTION_START}[\\s\\S]*?${SECTION_END}`);
const body = re.test(existing.body)
? existing.body.replace(re, sectionBlock)
: existing.body + '\n\n' + sectionBlock;
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `${COMMENT_MARKER}\n### Build Artifacts\n\n${sectionBlock}`,
});
}