Skip to content

Commit 331d1e8

Browse files
committed
(f) Merge channel files
1 parent 3c5415b commit 331d1e8

File tree

3 files changed

+85
-4
lines changed

3 files changed

+85
-4
lines changed

.github/workflows/build.yml

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ jobs:
227227
needs:
228228
- select-targets
229229
- start-self-hosted-runner
230+
env:
231+
# Location of artifacts generated by build.
232+
ARTIFACTS_PATH: electron/build/dist/build-artifacts/
230233
strategy:
231234
fail-fast: false
232235
matrix:
@@ -313,11 +316,18 @@ jobs:
313316
yarn --cwd ./electron/packager/
314317
yarn --cwd ./electron/packager/ package
315318
319+
# Both macOS jobs generate a channel file with same path and name. The second job to complete would overwrite the
320+
# file generated by the first in the workflow artifact.
321+
- name: Prevent macOS channel file overwrite
322+
if: runner.os == 'macOS'
323+
run: |
324+
mv "${{ env.ARTIFACTS_PATH }}/stable-mac.yml" "${{ env.ARTIFACTS_PATH }}/stable-mac-${{ runner.arch }}.yml"
325+
316326
- name: Upload [GitHub Actions]
317327
uses: actions/upload-artifact@v3
318328
with:
319329
name: ${{ env.JOB_TRANSFER_ARTIFACT }}
320-
path: electron/build/dist/build-artifacts/
330+
path: ${{ env.ARTIFACTS_PATH }}
321331

322332
stop-self-hosted-runner:
323333
needs:
@@ -341,6 +351,32 @@ jobs:
341351
--instance-ids "${{ needs.start-self-hosted-runner.outputs.instance-id }}" \
342352
--region "${{ env.SELF_HOSTED_RUNNER_INSTANCE_REGION }}"
343353
354+
merge-channel-files:
355+
needs: build
356+
runs-on: ubuntu-latest
357+
steps:
358+
- name: Checkout
359+
uses: actions/checkout@v3
360+
361+
- name: Download job transfer artifact
362+
uses: actions/download-artifact@v3
363+
with:
364+
name: ${{ env.JOB_TRANSFER_ARTIFACT }}
365+
path: ${{ env.JOB_TRANSFER_ARTIFACT }}
366+
367+
- name: Install dependencies
368+
run: yarn
369+
370+
- name: Merge channel files
371+
run: |
372+
yarn run merge-channel-files "${{ env.JOB_TRANSFER_ARTIFACT }}"
373+
374+
- name: Upload job transfer artifact
375+
uses: actions/upload-artifact@v3
376+
with:
377+
name: ${{ env.JOB_TRANSFER_ARTIFACT }}
378+
path: ${{ env.JOB_TRANSFER_ARTIFACT }}
379+
344380
artifacts:
345381
name: ${{ matrix.artifact.name }} artifact
346382
needs: build
@@ -429,7 +465,9 @@ jobs:
429465
path: CHANGELOG.txt
430466

431467
publish:
432-
needs: changelog
468+
needs:
469+
- changelog
470+
- merge-channel-files
433471
if: github.repository == 'arduino/arduino-ide' && (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main'))
434472
runs-on: ubuntu-latest
435473
steps:
@@ -450,7 +488,9 @@ jobs:
450488
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
451489

452490
release:
453-
needs: changelog
491+
needs:
492+
- changelog
493+
- merge-channel-files
454494
if: startsWith(github.ref, 'refs/tags/')
455495
runs-on: ubuntu-latest
456496
steps:
@@ -490,6 +530,7 @@ jobs:
490530
# This job must run after all jobs that use the transfer artifact.
491531
needs:
492532
- build
533+
- merge-channel-files
493534
- publish
494535
- release
495536
- artifacts

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"eslint-plugin-unused-imports": "^1.1.1",
2525
"husky": "^6.0.0",
2626
"ignore-styles": "^5.0.1",
27+
"js-yaml": "^4.1.0",
2728
"jsdom": "^11.5.1",
2829
"lerna": "^6.1.0",
2930
"lint-staged": "^11.0.0",
@@ -57,7 +58,8 @@
5758
"i18n:pull": "node ./scripts/i18n/transifex-pull.js ./i18n/",
5859
"themes:pull": "node ./scripts/themes/theme-tokens-pull.js",
5960
"themes:generate": "node ./scripts/themes/theme-generator.js",
60-
"compose-changelog": "yarn --cwd ./arduino-ide-extension compose-changelog"
61+
"compose-changelog": "yarn --cwd ./arduino-ide-extension compose-changelog",
62+
"merge-channel-files": "node ./scripts/merge-channel-files.js"
6163
},
6264
"lint-staged": {
6365
"./arduino-ide-extension/**/*.{ts,tsx}": [

scripts/merge-channel-files.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// @ts-check
2+
3+
const yaml = require('js-yaml');
4+
const fs = require('fs');
5+
const path = require('path');
6+
7+
if (process.argv.length !== 3) {
8+
console.error('Missing channel files folder path argument.');
9+
process.exit(1);
10+
}
11+
12+
const channelFilesFolder = process.argv[2];
13+
// Staging file filename suffixes are named according to `runner.arch`.
14+
// https://docs.github.com/en/actions/learn-github-actions/contexts#runner-context
15+
const x86ChannelFilePath = path.join(channelFilesFolder, 'stable-mac-X64.yml');
16+
const arm64ChannelFilePath = path.join(
17+
channelFilesFolder,
18+
'stable-mac-ARM64.yml'
19+
);
20+
21+
const x86Data = yaml.load(
22+
fs.readFileSync(x86ChannelFilePath, { encoding: 'utf8' })
23+
);
24+
const arm64Data = yaml.load(
25+
fs.readFileSync(arm64ChannelFilePath, { encoding: 'utf8' })
26+
);
27+
28+
const mergedData = x86Data;
29+
mergedData['files'] = mergedData['files'].concat(arm64Data['files']);
30+
31+
fs.writeFileSync(
32+
path.join(channelFilesFolder, 'stable-mac.yml'),
33+
yaml.dump(mergedData, { lineWidth: -1 })
34+
);
35+
36+
// Clean up
37+
fs.rmSync(x86ChannelFilePath);
38+
fs.rmSync(arm64ChannelFilePath);

0 commit comments

Comments
 (0)