simplify code
This commit is contained in:
parent
d64d795336
commit
be6198fa6a
2 changed files with 121 additions and 166 deletions
247
.github/workflows/build.yml
vendored
247
.github/workflows/build.yml
vendored
|
@ -73,29 +73,30 @@ jobs:
|
||||||
try {
|
try {
|
||||||
const output = execSync(`west build -s app -p -b ${{ matrix.board }} -- ${shieldArgs.shield ? '-DSHIELD=' + shieldArgs.shield : ''} ${shieldArgs['cmake-args'] || ''}`);
|
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());
|
console.log(output.toString());
|
||||||
|
|
||||||
const fileExtensions = ['hex', 'uf2'];
|
const fileExtensions = ["hex", "uf2"];
|
||||||
let files = [];
|
|
||||||
|
|
||||||
for (const extension of fileExtensions) {
|
const files = fileExtensions
|
||||||
const path = 'build/zephyr/zmk.' + extension;
|
.map(extension => "build/zephyr/zmk." + extension)
|
||||||
if (fs.existsSync(path)) {
|
.filter(path => fs.existsSync(path));
|
||||||
files.push(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const rootDirectory = 'build/zephyr';
|
const rootDirectory = 'build/zephyr';
|
||||||
const options = {
|
const options = {
|
||||||
continueOnError: true
|
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);
|
await artifactClient.uploadArtifact(artifactName, files, rootDirectory, options);
|
||||||
} catch (e) {
|
} 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);
|
console.error(e);
|
||||||
error = true;
|
error = true;
|
||||||
|
} finally {
|
||||||
|
console.log('::endgroup::');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,16 +115,15 @@ jobs:
|
||||||
id: compile-list
|
id: compile-list
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const coreCoverage = `${{ needs.core-coverage.outputs.core-include }}`;
|
const coreCoverage = `${{ needs.core-coverage.outputs.core-include }}` || "[]";
|
||||||
const coreCoverageArray = coreCoverage ? JSON.parse(coreCoverage) : [];
|
const boardChanges = `${{ needs.board-changes.outputs.boards-include }}` || "[]";
|
||||||
|
const nightly = `${{ needs.nightly.outputs.nightly-include }}` || "[]";
|
||||||
|
|
||||||
const boardChanges = `${{ needs.board-changes.outputs.boards-include }}`;
|
const combined = [
|
||||||
const boardChangesArray = boardChanges ? JSON.parse(boardChanges) : [];
|
...JSON.parse(coreCoverage),
|
||||||
|
...JSON.parse(boardChanges),
|
||||||
const nightly = `${{ needs.nightly.outputs.nightly-include }}`;
|
...JSON.parse(nightly)
|
||||||
const nightlyArray = nightly ? JSON.parse(nightly) : [];
|
];
|
||||||
|
|
||||||
const combined = [...coreCoverageArray, ...boardChangesArray, ...nightlyArray];
|
|
||||||
const combinedUnique = [...new Map(combined.map(el => [JSON.stringify(el), el])).values()];
|
const combinedUnique = [...new Map(combined.map(el => [JSON.stringify(el), el])).values()];
|
||||||
|
|
||||||
const perBoard = {};
|
const perBoard = {};
|
||||||
|
@ -134,20 +134,15 @@ jobs:
|
||||||
|
|
||||||
perBoard[configuration.board].push({
|
perBoard[configuration.board].push({
|
||||||
shield: configuration.shield,
|
shield: configuration.shield,
|
||||||
'cmake-args': configuration['cmake-args']
|
'cmake-args': configuration['cmake-args'],
|
||||||
|
nickname: configuration.nickname
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const includeList = [];
|
return Object.entries(perBoard).map(([board, shieldArgs]) => ({
|
||||||
|
|
||||||
for (const [board, shieldArgs] of Object.entries(perBoard)) {
|
|
||||||
includeList.push({
|
|
||||||
board,
|
board,
|
||||||
shieldArgs: JSON.stringify(shieldArgs)
|
shieldArgs: JSON.stringify(shieldArgs),
|
||||||
});
|
}));
|
||||||
}
|
|
||||||
|
|
||||||
return includeList;
|
|
||||||
core-coverage:
|
core-coverage:
|
||||||
if: ${{ needs.get-changed-files.outputs.core-changes == 'true' }}
|
if: ${{ needs.get-changed-files.outputs.core-changes == 'true' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -155,70 +150,26 @@ jobs:
|
||||||
outputs:
|
outputs:
|
||||||
core-include: ${{ steps.core-list.outputs.result }}
|
core-include: ${{ steps.core-list.outputs.result }}
|
||||||
steps:
|
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
|
- uses: actions/github-script@v4
|
||||||
id: core-list
|
id: core-list
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
// break out to file
|
const fs = require('fs');
|
||||||
const coreCoverage = {
|
const yaml = require('js-yaml');
|
||||||
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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
let include = [];
|
const coreCoverage = yaml.load(fs.readFileSync('app/core-coverage.yml', 'utf8'));
|
||||||
|
|
||||||
coreCoverage.boards.forEach(b => {
|
let include = coreCoverage.board.flatMap(board =>
|
||||||
coreCoverage.shields.forEach(s => {
|
coreCoverage.shield.map(shield => ({ board, shield }))
|
||||||
include.push({
|
);
|
||||||
board: b,
|
|
||||||
shield: s
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return [...include, ...coreCoverage.include];
|
return [...include, ...coreCoverage.include];
|
||||||
board-changes:
|
board-changes:
|
||||||
|
@ -247,9 +198,7 @@ jobs:
|
||||||
const metadata = JSON.parse(`${{ needs.get-grouped-hardware.outputs.organized-metadata }}`);
|
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('/')));
|
const boardChanges = new Set(changedFiles.filter(f => f.startsWith('app/boards')).map(f => f.split('/').slice(0, 4).join('/')));
|
||||||
|
|
||||||
include = [];
|
return (await Promise.all([...boardChanges].flatMap(async bc => {
|
||||||
|
|
||||||
for (const bc of boardChanges) {
|
|
||||||
const globber = await glob.create(bc + "/*.zmk.yml");
|
const globber = await glob.create(bc + "/*.zmk.yml");
|
||||||
const files = await globber.glob();
|
const files = await globber.glob();
|
||||||
|
|
||||||
|
@ -257,71 +206,53 @@ jobs:
|
||||||
yaml.loadAll(fs.readFileSync(f, "utf8"))
|
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) {
|
switch (hm.type) {
|
||||||
case "board":
|
case "board":
|
||||||
if (hm.features && hm.features.includes("keys")) {
|
if (hm.features && hm.features.includes("keys")) {
|
||||||
if (hm.siblings) {
|
if (hm.siblings) {
|
||||||
hm.siblings.forEach(sib => {
|
return hm.siblings.map(board => ({
|
||||||
include.push({
|
board,
|
||||||
board: sib
|
}));
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
include.push({
|
return {
|
||||||
board: hm.id
|
board: hm.id
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
} else if (hm.exposes) {
|
} else if (hm.exposes) {
|
||||||
hm.exposes.forEach(i => {
|
return hm.exposes.flatMap(i =>
|
||||||
metadata.interconnects[i].shields.forEach(s => {
|
metadata.interconnects[i].shields.flatMap(s => boardAndShield(hm, s))
|
||||||
if (s.siblings) {
|
);
|
||||||
s.siblings.forEach(sib => {
|
|
||||||
include.push({
|
|
||||||
board: hm.id,
|
|
||||||
shield: sib
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
include.push({
|
|
||||||
board: hm.id,
|
|
||||||
shield: s.id
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
console.error("Board without keys or interconnect");
|
console.error("Board without keys or interconnect");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "shield":
|
case "shield":
|
||||||
if (hm.features && hm.features.includes("keys")) {
|
if (hm.features && hm.features.includes("keys")) {
|
||||||
hm.requires.forEach(i => {
|
return hm.requires.flatMap(i =>
|
||||||
metadata.interconnects[i].boards.forEach(b => {
|
metadata.interconnects[i].boards.flatMap(b => boardAndShield(b, hm))
|
||||||
if (hm.siblings) {
|
);
|
||||||
hm.siblings.forEach(sib => {
|
|
||||||
include.push({
|
|
||||||
board: b.id,
|
|
||||||
shield: sib
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
include.push({
|
|
||||||
board: b.id,
|
|
||||||
shield: hm.id
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "interconnect":
|
case "interconnect":
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}))).flat();
|
||||||
|
|
||||||
return include;
|
|
||||||
nightly:
|
nightly:
|
||||||
if: ${{ github.event_name == 'schedule' }}
|
if: ${{ github.event_name == 'schedule' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -335,43 +266,38 @@ jobs:
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const metadata = JSON.parse(`${{ needs.get-grouped-hardware.outputs.organized-metadata }}`);
|
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) {
|
if (b.siblings) {
|
||||||
b.siblings.forEach(sib => {
|
return b.siblings.map(board => ({
|
||||||
include.push({
|
board,
|
||||||
board: sib
|
}));
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
include.push({
|
return {
|
||||||
board: b.id
|
board: b.id,
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.values(metadata.interconnects).forEach(i => {
|
let includeInterconnect = Object.values(metadata.interconnects).flatMap(i =>
|
||||||
i.boards.forEach(b => {
|
i.boards.flatMap(b =>
|
||||||
i.shields.forEach(s => {
|
i.shields.flatMap(s => {
|
||||||
if (s.siblings) {
|
if (s.siblings) {
|
||||||
s.siblings.forEach(sib => {
|
return s.siblings.map(shield => ({
|
||||||
include.push({
|
|
||||||
board: b.id,
|
board: b.id,
|
||||||
shield: sib
|
shield,
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
include.push({
|
return {
|
||||||
board: b.id,
|
board: b.id,
|
||||||
shield: s.id
|
shield: s.id,
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
});
|
)
|
||||||
});
|
);
|
||||||
|
|
||||||
return include;
|
return [...includeOnboard, ...includeInterconnect];
|
||||||
get-grouped-hardware:
|
get-grouped-hardware:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
|
@ -479,4 +405,3 @@ jobs:
|
||||||
const ymlChanges = changedFiles.includes('.github/workflows/build.yml');
|
const ymlChanges = changedFiles.includes('.github/workflows/build.yml');
|
||||||
return boardChanges.length < appChanges.length || ymlChanges ? 'true' : 'false';
|
return boardChanges.length < appChanges.length || ymlChanges ? 'true' : 'false';
|
||||||
result-encoding: string
|
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