simplify code
This commit is contained in:
parent
d64d795336
commit
be6198fa6a
2 changed files with 121 additions and 166 deletions
253
.github/workflows/build.yml
vendored
253
.github/workflows/build.yml
vendored
|
@ -73,29 +73,30 @@ jobs:
|
|||
try {
|
||||
const output = execSync(`west build -s app -p -b ${{ matrix.board }} -- ${shieldArgs.shield ? '-DSHIELD=' + shieldArgs.shield : ''} ${shieldArgs['cmake-args'] || ''}`);
|
||||
|
||||
console.log(`::group::${{ matrix.board}} ${shieldArgs.shield} Build`)
|
||||
console.log(output.toString());
|
||||
|
||||
const fileExtensions = ['hex', 'uf2'];
|
||||
let files = [];
|
||||
const fileExtensions = ["hex", "uf2"];
|
||||
|
||||
for (const extension of fileExtensions) {
|
||||
const path = 'build/zephyr/zmk.' + extension;
|
||||
if (fs.existsSync(path)) {
|
||||
files.push(path);
|
||||
}
|
||||
}
|
||||
const files = fileExtensions
|
||||
.map(extension => "build/zephyr/zmk." + extension)
|
||||
.filter(path => fs.existsSync(path));
|
||||
|
||||
const rootDirectory = 'build/zephyr';
|
||||
const options = {
|
||||
continueOnError: true
|
||||
}
|
||||
const artifactName = `${{ matrix.board }}${shieldArgs.shield ? '-' + shieldArgs.shield : ''}-zmk`;
|
||||
|
||||
const cmakeName = shieldArgs['cmake-args'] ? '-' + (shieldArgs.nickname || shieldArgs['cmake-args'].split(' ').join('')) : '';
|
||||
const artifactName = `${{ matrix.board }}${shieldArgs.shield ? '-' + shieldArgs.shield : ''}${cmakeName}-zmk`;
|
||||
|
||||
await artifactClient.uploadArtifact(artifactName, files, rootDirectory, options);
|
||||
} catch (e) {
|
||||
console.error(`Failed to build or upload ${{ matrix.board }} ${shieldArgs.shield} ${shieldArgs['cmake-args']}`);
|
||||
console.error(`::error::Failed to build or upload ${{ matrix.board }} ${shieldArgs.shield} ${shieldArgs['cmake-args']}`);
|
||||
console.error(e);
|
||||
error = true;
|
||||
} finally {
|
||||
console.log('::endgroup::');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,16 +115,15 @@ jobs:
|
|||
id: compile-list
|
||||
with:
|
||||
script: |
|
||||
const coreCoverage = `${{ needs.core-coverage.outputs.core-include }}`;
|
||||
const coreCoverageArray = coreCoverage ? JSON.parse(coreCoverage) : [];
|
||||
const coreCoverage = `${{ needs.core-coverage.outputs.core-include }}` || "[]";
|
||||
const boardChanges = `${{ needs.board-changes.outputs.boards-include }}` || "[]";
|
||||
const nightly = `${{ needs.nightly.outputs.nightly-include }}` || "[]";
|
||||
|
||||
const boardChanges = `${{ needs.board-changes.outputs.boards-include }}`;
|
||||
const boardChangesArray = boardChanges ? JSON.parse(boardChanges) : [];
|
||||
|
||||
const nightly = `${{ needs.nightly.outputs.nightly-include }}`;
|
||||
const nightlyArray = nightly ? JSON.parse(nightly) : [];
|
||||
|
||||
const combined = [...coreCoverageArray, ...boardChangesArray, ...nightlyArray];
|
||||
const combined = [
|
||||
...JSON.parse(coreCoverage),
|
||||
...JSON.parse(boardChanges),
|
||||
...JSON.parse(nightly)
|
||||
];
|
||||
const combinedUnique = [...new Map(combined.map(el => [JSON.stringify(el), el])).values()];
|
||||
|
||||
const perBoard = {};
|
||||
|
@ -134,20 +134,15 @@ jobs:
|
|||
|
||||
perBoard[configuration.board].push({
|
||||
shield: configuration.shield,
|
||||
'cmake-args': configuration['cmake-args']
|
||||
'cmake-args': configuration['cmake-args'],
|
||||
nickname: configuration.nickname
|
||||
})
|
||||
}
|
||||
|
||||
const includeList = [];
|
||||
|
||||
for (const [board, shieldArgs] of Object.entries(perBoard)) {
|
||||
includeList.push({
|
||||
board,
|
||||
shieldArgs: JSON.stringify(shieldArgs)
|
||||
});
|
||||
}
|
||||
|
||||
return includeList;
|
||||
return Object.entries(perBoard).map(([board, shieldArgs]) => ({
|
||||
board,
|
||||
shieldArgs: JSON.stringify(shieldArgs),
|
||||
}));
|
||||
core-coverage:
|
||||
if: ${{ needs.get-changed-files.outputs.core-changes == 'true' }}
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -155,70 +150,26 @@ jobs:
|
|||
outputs:
|
||||
core-include: ${{ steps.core-list.outputs.result }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '14.x'
|
||||
- name: Install js-yaml
|
||||
run: npm install js-yaml
|
||||
- uses: actions/github-script@v4
|
||||
id: core-list
|
||||
with:
|
||||
script: |
|
||||
// break out to file
|
||||
const coreCoverage = {
|
||||
boards: [
|
||||
'nice_nano_v2',
|
||||
'nrfmicro_13',
|
||||
'proton_c'
|
||||
],
|
||||
shields: [
|
||||
'corne_left',
|
||||
'corne_right',
|
||||
'romac',
|
||||
'settings_reset',
|
||||
'tidbit'
|
||||
],
|
||||
include: [
|
||||
{
|
||||
"board": "bdn9_rev2"
|
||||
},
|
||||
{
|
||||
"board": "nice60"
|
||||
},
|
||||
{
|
||||
"board": "nrf52840_m2",
|
||||
"shield": "m60"
|
||||
},
|
||||
{
|
||||
"board": "planck_rev6"
|
||||
},
|
||||
{
|
||||
"board": "proton_c",
|
||||
"shield": "clueboard_california"
|
||||
},
|
||||
{
|
||||
"board": "nice_nano_v2",
|
||||
"shield": "kyria_left",
|
||||
"cmake-args": "-DCONFIG_ZMK_DISPLAY=y",
|
||||
},
|
||||
{
|
||||
"board": "nice_nano_v2",
|
||||
"shield": "kyria_right",
|
||||
"cmake-args": "-DCONFIG_ZMK_DISPLAY=y",
|
||||
},
|
||||
{
|
||||
"board": "nice_nano",
|
||||
"shield": "romac_plus",
|
||||
"cmake-args": "-DCONFIG_ZMK_RGB_UNDERGLOW=y -DCONFIG_WS2812_STRIP=y"
|
||||
}
|
||||
]
|
||||
};
|
||||
const fs = require('fs');
|
||||
const yaml = require('js-yaml');
|
||||
|
||||
let include = [];
|
||||
const coreCoverage = yaml.load(fs.readFileSync('app/core-coverage.yml', 'utf8'));
|
||||
|
||||
coreCoverage.boards.forEach(b => {
|
||||
coreCoverage.shields.forEach(s => {
|
||||
include.push({
|
||||
board: b,
|
||||
shield: s
|
||||
});
|
||||
});
|
||||
});
|
||||
let include = coreCoverage.board.flatMap(board =>
|
||||
coreCoverage.shield.map(shield => ({ board, shield }))
|
||||
);
|
||||
|
||||
return [...include, ...coreCoverage.include];
|
||||
board-changes:
|
||||
|
@ -247,9 +198,7 @@ jobs:
|
|||
const metadata = JSON.parse(`${{ needs.get-grouped-hardware.outputs.organized-metadata }}`);
|
||||
const boardChanges = new Set(changedFiles.filter(f => f.startsWith('app/boards')).map(f => f.split('/').slice(0, 4).join('/')));
|
||||
|
||||
include = [];
|
||||
|
||||
for (const bc of boardChanges) {
|
||||
return (await Promise.all([...boardChanges].flatMap(async bc => {
|
||||
const globber = await glob.create(bc + "/*.zmk.yml");
|
||||
const files = await globber.glob();
|
||||
|
||||
|
@ -257,71 +206,53 @@ jobs:
|
|||
yaml.loadAll(fs.readFileSync(f, "utf8"))
|
||||
);
|
||||
|
||||
aggregated.forEach(hm => {
|
||||
const boardAndShield = (b, s) => {
|
||||
if (s.siblings) {
|
||||
return s.siblings.map(shield => ({
|
||||
board: b.id,
|
||||
shield,
|
||||
}));
|
||||
} else {
|
||||
return {
|
||||
board: b.id,
|
||||
shield: s.id
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return aggregated.flatMap(hm => {
|
||||
switch (hm.type) {
|
||||
case "board":
|
||||
if (hm.features && hm.features.includes("keys")) {
|
||||
if (hm.siblings) {
|
||||
hm.siblings.forEach(sib => {
|
||||
include.push({
|
||||
board: sib
|
||||
});
|
||||
});
|
||||
return hm.siblings.map(board => ({
|
||||
board,
|
||||
}));
|
||||
} else {
|
||||
include.push({
|
||||
return {
|
||||
board: hm.id
|
||||
});
|
||||
};
|
||||
}
|
||||
} else if (hm.exposes) {
|
||||
hm.exposes.forEach(i => {
|
||||
metadata.interconnects[i].shields.forEach(s => {
|
||||
if (s.siblings) {
|
||||
s.siblings.forEach(sib => {
|
||||
include.push({
|
||||
board: hm.id,
|
||||
shield: sib
|
||||
});
|
||||
});
|
||||
} else {
|
||||
include.push({
|
||||
board: hm.id,
|
||||
shield: s.id
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
return hm.exposes.flatMap(i =>
|
||||
metadata.interconnects[i].shields.flatMap(s => boardAndShield(hm, s))
|
||||
);
|
||||
} else {
|
||||
console.error("Board without keys or interconnect");
|
||||
}
|
||||
break;
|
||||
case "shield":
|
||||
if (hm.features && hm.features.includes("keys")) {
|
||||
hm.requires.forEach(i => {
|
||||
metadata.interconnects[i].boards.forEach(b => {
|
||||
if (hm.siblings) {
|
||||
hm.siblings.forEach(sib => {
|
||||
include.push({
|
||||
board: b.id,
|
||||
shield: sib
|
||||
});
|
||||
});
|
||||
} else {
|
||||
include.push({
|
||||
board: b.id,
|
||||
shield: hm.id
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
return hm.requires.flatMap(i =>
|
||||
metadata.interconnects[i].boards.flatMap(b => boardAndShield(b, hm))
|
||||
);
|
||||
}
|
||||
break;
|
||||
case "interconnect":
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return include;
|
||||
}))).flat();
|
||||
nightly:
|
||||
if: ${{ github.event_name == 'schedule' }}
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -335,43 +266,38 @@ jobs:
|
|||
with:
|
||||
script: |
|
||||
const metadata = JSON.parse(`${{ needs.get-grouped-hardware.outputs.organized-metadata }}`);
|
||||
let include = [];
|
||||
|
||||
metadata.onboard.forEach(b => {
|
||||
let includeOnboard = metadata.onboard.flatMap(b => {
|
||||
if (b.siblings) {
|
||||
b.siblings.forEach(sib => {
|
||||
include.push({
|
||||
board: sib
|
||||
});
|
||||
});
|
||||
return b.siblings.map(board => ({
|
||||
board,
|
||||
}));
|
||||
} else {
|
||||
include.push({
|
||||
board: b.id
|
||||
});
|
||||
return {
|
||||
board: b.id,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
Object.values(metadata.interconnects).forEach(i => {
|
||||
i.boards.forEach(b => {
|
||||
i.shields.forEach(s => {
|
||||
let includeInterconnect = Object.values(metadata.interconnects).flatMap(i =>
|
||||
i.boards.flatMap(b =>
|
||||
i.shields.flatMap(s => {
|
||||
if (s.siblings) {
|
||||
s.siblings.forEach(sib => {
|
||||
include.push({
|
||||
board: b.id,
|
||||
shield: sib
|
||||
});
|
||||
});
|
||||
} else {
|
||||
include.push({
|
||||
return s.siblings.map(shield => ({
|
||||
board: b.id,
|
||||
shield: s.id
|
||||
});
|
||||
shield,
|
||||
}));
|
||||
} else {
|
||||
return {
|
||||
board: b.id,
|
||||
shield: s.id,
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
return include;
|
||||
return [...includeOnboard, ...includeInterconnect];
|
||||
get-grouped-hardware:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
|
@ -479,4 +405,3 @@ jobs:
|
|||
const ymlChanges = changedFiles.includes('.github/workflows/build.yml');
|
||||
return boardChanges.length < appChanges.length || ymlChanges ? 'true' : 'false';
|
||||
result-encoding: string
|
||||
|
||||
|
|
30
app/core-coverage.yml
Normal file
30
app/core-coverage.yml
Normal file
|
@ -0,0 +1,30 @@
|
|||
board:
|
||||
- nice_nano_v2
|
||||
- nrfmicro_13
|
||||
- proton_c
|
||||
shield:
|
||||
- corne_left
|
||||
- corne_right
|
||||
- romac
|
||||
- settings_reset
|
||||
- tidbit
|
||||
include:
|
||||
- board: bdn9_rev2
|
||||
- board: nice60
|
||||
- board: nrf52840_m2
|
||||
shield: m60
|
||||
- board: planck_rev6
|
||||
- board: proton_c
|
||||
shield: clueboard_california
|
||||
- board: nice_nano_v2
|
||||
shield: kyria_left
|
||||
cmake-args: "-DCONFIG_ZMK_DISPLAY=y"
|
||||
nickname: "display"
|
||||
- board: nice_nano_v2
|
||||
shield: kyria_right
|
||||
cmake-args: "-DCONFIG_ZMK_DISPLAY=y"
|
||||
nickname: "display"
|
||||
- board: nice_nano
|
||||
shield: romac_plus
|
||||
cmake-args: "-DCONFIG_ZMK_RGB_UNDERGLOW=y -DCONFIG_WS2812_STRIP=y"
|
||||
nickname: "underglow"
|
Loading…
Add table
Reference in a new issue