New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ci): Use metadata for builds #889
Conversation
889524f
to
a6186b1
Compare
print("Failed validation of: " + file) | ||
print(vexc) | ||
|
||
exit(1 if failure else 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exit() is supposed to only be used from within the Python interactive interpreter from what I understand. You probably want sys.exit() instead.
metadata = yaml.safe_load(stream) | ||
ret = validate(metadata, schema) | ||
except yaml.YAMLError as exc: | ||
failure = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it would be simpler to just
print(exc)
sys.exit(1)
instead of having a common exit point. You've already hit an error, so you should probably bail immediately.
Alternatively, you could wrap all of this up in another function and have it re-raise the exceptions with added info, then have a single handler that prints the error and exits. It might look something like this:
class MetadataError(Exception):
pass
def do_run(self, args, unknown_args):
try:
self.validate_files()
except MetadataError as e:
print(e)
sys.exit(1)
def validate_files(self):
# ...
try:
# ...
except yaml.YAMLError as e:
# Use .format() instead of f-strings if we care about Python < 3.6
raise MetadataError(f'Failed loading YAML file "{file}": {e}') from e
except ValidationError as e:
raise MetadataError(f'Failed validation of file "{file}": {e}') from e
...which I kinda like because all the logic for printing an error is in one spot instead of spread across multiple exception handlers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, the point is to continue, so we can check all the files. Then if any fail... we return a non-zero exit code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We specifically don't want to exit early.
with open(file, 'r') as stream: | ||
try: | ||
metadata = yaml.safe_load(stream) | ||
ret = validate(metadata, schema) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ret
appears unused?
|
||
## Overview | ||
|
||
ZMK leverages an additional metadata YAML file for all boards and shields to provide high level information about the hardware to be leveraged by setup scripts/utilities, proper inclusion in the website hardware list, etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super minor: using "leverage" twice makes this read a bit awkwardly to me. Maybe just use "use" and/or "to be read by setup scripts" to keep things easy to understand?
(If you change this, Ctrl+F "leverage" since it's used in a few other places too.)
Whoops. I am on the wrong PR. Those comments apply to #883. |
a6186b1
to
3ed31b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a good start. I think in general, the code could be cleaned up, even if the you can't declare functions in github script, you could define lambdas and use them, to make the code clearer, e.g. const mapBoard = (metadata) => foo
.
.github/workflows/build.yml
Outdated
script: | | ||
// break out to file | ||
const coreCoverage = { | ||
boards: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was assuming we'd tag these boards and shields somehow in the .zmk.yml
file, or maybe with an extra .core-build
empty file, or something, to detect these automatically. Thoughts?
.github/workflows/build.yml
Outdated
{ | ||
"board": "nice_nano_v2", | ||
"shield": "kyria_left", | ||
"cmake-args": "-DCONFIG_ZMK_DISPLAY=y", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this, we could find any boards w/ the display
feature, and pass this as an arg to build it, to determine this dynamically.
.github/workflows/build.yml
Outdated
{ | ||
"board": "nice_nano", | ||
"shield": "romac_plus", | ||
"cmake-args": "-DCONFIG_ZMK_RGB_UNDERGLOW=y -DCONFIG_WS2812_STRIP=y" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto, use the features for this.
.github/workflows/build.yml
Outdated
let include = []; | ||
|
||
coreCoverage.boards.forEach(b => { | ||
coreCoverage.shields.forEach(s => { | ||
include.push({ | ||
board: b, | ||
shield: s | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purist in me says, do it functionally, darn it!
let include = []; | |
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 })); |
(I may have the JS syntax slightly wrong)
.github/workflows/build.yml
Outdated
yaml.loadAll(fs.readFileSync(f, "utf8")) | ||
); | ||
|
||
aggregated.forEach(hm => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar grumblings about using forEach
here instead of mapping, but this also works fine.
c5bc344
to
55a9a05
Compare
55a9a05
to
ccca2c3
Compare
ccca2c3
to
18acfd5
Compare
2991f12
to
aa6b86c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems really close! A few tweaks to make the experience a tad nicer needed before we merge.
aa6b86c
to
547156f
Compare
@petejohanson Improved the logging with groups/errors as suggested. Also simplified the combining code using your suggestion, thanks. Let me know what you think now. I still want to add settings-reset to the nightly build and also add cmake args to the artifacts, but I'm not sure the best way to do either if you have suggestions. Have an idea for the settings-reset at the very least. |
@Nicell Perhaps for the cmake-args case, we expect you to also pass a |
547156f
to
cc3682c
Compare
@petejohanson I added nicknames, you can see it on the core build of this PR. Works well. I've simply removed the spaces from cmake-args as the alternate rather than doing a hash, since it's more readable this way and just a fallback. I had some thoughts about settings-reset I think we need to address, so I'm not sure if I'm going to add that to this PR. I think this is mostly ready to go then from my point of view. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor tweak needed, then good to go. Thanks!
cc3682c
to
c3a3445
Compare
c3a3445
to
be6198f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks!
Refactors the build workflow to use hardware metadata to accomplish the following:
Here's a nightly build: https://github.com/Nicell/zmk/actions/runs/1519228121
Here's a boards change run: https://github.com/Nicell/zmk/actions/runs/1517831312
Here's a core run: https://github.com/Nicell/zmk/actions/runs/1517789825
Todo: