Skip to content

Commit

Permalink
simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicell committed Nov 29, 2021
1 parent 6fa9da8 commit 55a9a05
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 142 deletions.
214 changes: 72 additions & 142 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,11 @@ jobs:
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 = {
Expand Down Expand Up @@ -138,87 +134,37 @@ jobs:
})
}
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
needs: get-changed-files
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.boards.flatMap(board =>
coreCoverage.shields.map(shield => ({ board, shield }))
);
return [...include, ...coreCoverage.include];
board-changes:
Expand Down Expand Up @@ -247,81 +193,71 @@ 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 [...boardChanges].flatMap(bc => {
const globber = await glob.create(bc + "/*.zmk.yml");
const files = await globber.glob();
const aggregated = files.flatMap((f) =>
yaml.loadAll(fs.readFileSync(f, "utf8"))
);
aggregated.forEach(hm => {
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 => {
return hm.exposes.flatMap(i =>
metadata.interconnects[i].shields.flatMap(s => {
if (s.siblings) {
s.siblings.forEach(sib => {
include.push({
board: hm.id,
shield: sib
});
});
return s.siblings.map(shield => ({
board: hm.id,
shield,
}));
} else {
include.push({
return {
board: hm.id,
shield: s.id
});
};
}
});
});
})
);
} 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 => {
return hm.requires.flatMap(i =>
metadata.interconnects[i].boards.flatMap(b => {
if (hm.siblings) {
hm.siblings.forEach(sib => {
include.push({
board: b.id,
shield: sib
});
});
return hm.siblings.map(shield => ({
board: b.id,
shield,
}));
} else {
include.push({
return {
board: b.id,
shield: hm.id
});
};
}
});
});
})
);
}
break;
case "interconnect":
break;
}
});
}
return include;
});
nightly:
if: ${{ github.event_name == 'schedule' }}
runs-on: ubuntu-latest
Expand All @@ -335,43 +271,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
});
});
return s.siblings.map(shield => ({
board: b.id,
shield,
}));
} else {
include.push({
return {
board: b.id,
shield: s.id
});
shield: s.id,
};
}
});
});
});
})
)
);
return include;
return [...includeOnboard, ...includeInterconnect];
get-grouped-hardware:
runs-on: ubuntu-latest
outputs:
Expand Down Expand Up @@ -479,4 +410,3 @@ jobs:
const ymlChanges = changedFiles.includes('.github/workflows/build.yml');
return boardChanges.length < appChanges.length || ymlChanges ? 'true' : 'false';
result-encoding: string

27 changes: 27 additions & 0 deletions app/core-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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"

0 comments on commit 55a9a05

Please sign in to comment.