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
20 changes: 20 additions & 0 deletions .github/scripts/validateActionsAndWorkflows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
#
# Validates the Github Actions and workflows using the json schemas provided by https://www.schemastore.org/json/

# Track exit codes separately so we can run a full validation, report errors, and exit with the correct code
declare EXIT_CODE=0

# Download the up-to-date json schemas for github actions and workflows
cd ./.github && mkdir ./tempSchemas || exit 1
curl https://json.schemastore.org/github-action.json --output ./tempSchemas/github-action.json --silent || exit 1
curl https://json.schemastore.org/github-workflow.json --output ./tempSchemas/github-workflow.json --silent || exit 1

# Validate the actions and workflows using the JSON schemas and ajv https://github.com/ajv-validator/ajv-cli
find ./actions/ -type f -name "*.yml" -print0 | xargs -0 -I file ajv -s ./tempSchemas/github-action.json -d file --strict=false || EXIT_CODE=1
find ./workflows/ -type f -name "*.yml" -print0 | xargs -0 -I file ajv -s ./tempSchemas/github-workflow.json -d file --strict=false || EXIT_CODE=1

# Cleanup after ourselves and delete the schemas
rm -rf ./tempSchemas

exit $EXIT_CODE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Verify Github Action Builds
name: Validate Github Actions

on:
pull_request:
Expand All @@ -25,4 +25,8 @@ jobs:

# Rebuild all the actions on this branch and check for a diff. Fail if there is one,
# because that would be a sign that the PR author did not rebuild the Github Actions
- run: ./.github/scripts/verifyActions.sh
- name: Verify Javascript Action Builds
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 )"

87 changes: 87 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"detox-build": "detox build --configuration ios.sim.debug",
"detox-test": "detox test --configuration ios.sim.debug",
"gh-actions-build": "./.github/scripts/buildActions.sh",
"gh-actions-validate": "./.github/scripts/validateActionsAndWorkflows.sh",
"analyze-packages": "ANALYZE_BUNDLE=true webpack --config config/webpack/webpack.prod.js"
},
"dependencies": {
Expand Down Expand Up @@ -99,6 +100,7 @@
"@testing-library/jest-native": "^3.4.2",
"@testing-library/react-native": "^7.0.2",
"@vercel/ncc": "^0.27.0",
"ajv-cli": "^5.0.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.2.2",
"babel-loader": "^8.1.0",
Expand Down