Skip to content
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

[No QA] Schema Validation for Github Actions #2197

Merged
merged 11 commits into from
Apr 2, 2021

Conversation

roryabraham
Copy link
Contributor

cc'ing @Dal-Papa - maybe this will be useful for other repos too!

Details

Creates a script which validates the Github Actions and Workflows using the schemas provided by https://json.schemastore.org

These schema seem to be pretty actively maintained by the community here.

Uses a YAML validator called ajv, which also seems to be actively maintained.

Fixed Issues

Fixes (partial) https://github.com/Expensify/Expensify/issues/156436

Tests

  1. Commit an incorrect value in a Github Action metadata file
  2. Push the change, and the validation should fail.
  3. Revert any changes in any yaml metadata files. Commit an invalid key in a Github Action metadata file.
  4. Push the change, and the validation should fail.
  5. Revert any changes in any yaml metadata files. Commit an incorrect value in a Github Workflow metadata file.
  6. Push the change, and the validation should fail.
  7. Revert any changes in any yaml metadata files. Commit an invalid key in a Github Workflow metadata file.
  8. Push the change, and the validation should fail.
  9. Revert any changes in any yaml metadata files.
  10. Push your changes again (resetting any metadata files except the one intentionally changed by this PR), and the validation should pass.

Tested On

  • Github only

@roryabraham roryabraham self-assigned this Apr 1, 2021
@roryabraham roryabraham requested a review from a team as a code owner April 1, 2021 07:16
@MelvinBot MelvinBot requested review from pecanoro and removed request for a team April 1, 2021 07:16
@roryabraham
Copy link
Contributor Author

Note that what this does not do is format linting of yaml files for things like indentation, brackets, etc...

Dal-Papa
Dal-Papa previously approved these changes Apr 1, 2021
run: ./.github/scripts/verifyActions.sh

- name: Validate actions and workflows
run: npm run gh-actions-validate
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure it's for consistency with the rest but why did we decide to proxy all our shell scripts with NPM actions ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's so you can run them from any directory in the project and they will still work the same. Like it I were to do cd .github && ./scripts/validateActionsAndWorkflows.sh, then the script would fail because it tries to run cd ./.github and that would fail. But if you run it as an npm script then it's always running from the project root.

Copy link

@Dal-Papa Dal-Papa Apr 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, there are other ways to ensure that in Bash without requiring npm. In this case, this we already use it that's probably fine but we shouldn't rely on it otherwise IMO.
E.g. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

@AndrewGable
Copy link
Contributor

Can you test? Or is this internal QA?

@roryabraham
Copy link
Contributor Author

Yeah, I can do some more testing in this PR pre-merge. But then I don't think any QA will be necessary because the PR is the environment in which this check is meant to run.

@pecanoro
Copy link
Contributor

pecanoro commented Apr 2, 2021

All yours @Dal-Papa and @AndrewGable

@roryabraham
Copy link
Contributor Author

No changes since @Dal-Papa's last approval, only temporary changes for testing. So going to self-merge this one.

@roryabraham roryabraham merged commit a846401 into master Apr 2, 2021
@roryabraham roryabraham deleted the Rory-SetupYamlValidation branch April 2, 2021 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants