diff --git a/.github/scripts/validateActionsAndWorkflows.sh b/.github/scripts/validateActionsAndWorkflows.sh new file mode 100755 index 000000000000..0ff92289b524 --- /dev/null +++ b/.github/scripts/validateActionsAndWorkflows.sh @@ -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 diff --git a/.github/workflows/verifyGithubActionBuilds.yml b/.github/workflows/validateGithubActions.yml similarity index 77% rename from .github/workflows/verifyGithubActionBuilds.yml rename to .github/workflows/validateGithubActions.yml index 21fa3213259b..e6c8e0d04186 100644 --- a/.github/workflows/verifyGithubActionBuilds.yml +++ b/.github/workflows/validateGithubActions.yml @@ -1,4 +1,4 @@ -name: Verify Github Action Builds +name: Validate Github Actions on: pull_request: @@ -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 diff --git a/package-lock.json b/package-lock.json index 7f12bd92e1f0..a3225cdcd93d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5044,6 +5044,41 @@ "uri-js": "^4.2.2" } }, + "ajv-cli": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ajv-cli/-/ajv-cli-5.0.0.tgz", + "integrity": "sha512-LY4m6dUv44HTyhV+u2z5uX4EhPYTM38Iv1jdgDJJJCyOOuqB8KtZEGjPZ2T+sh5ZIJrXUfgErYx/j3gLd3+PlQ==", + "dev": true, + "requires": { + "ajv": "^8.0.0", + "fast-json-patch": "^2.0.0", + "glob": "^7.1.0", + "js-yaml": "^3.14.0", + "json-schema-migrate": "^2.0.0", + "json5": "^2.1.3", + "minimist": "^1.2.0" + }, + "dependencies": { + "ajv": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.0.2.tgz", + "integrity": "sha512-V0HGxJd0PiDF0ecHYIesTOqfd1gJguwQUOYfMfAWnRsWQEXfc5ifbUFhD3Wjc+O+y7VAqL+g07prq9gHQ/JOZQ==", + "dev": true, + "requires": { + "fast-deep-equal": "^3.1.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2", + "uri-js": "^4.2.2" + } + }, + "json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "dev": true + } + } + }, "ajv-errors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/ajv-errors/-/ajv-errors-1.0.1.tgz", @@ -11418,6 +11453,23 @@ } } }, + "fast-json-patch": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/fast-json-patch/-/fast-json-patch-2.2.1.tgz", + "integrity": "sha512-4j5uBaTnsYAV5ebkidvxiLUYOwjQ+JSFljeqfTxCrH9bDmlCQaOJFS84oDJ2rAXZq2yskmk3ORfoP9DCwqFNig==", + "dev": true, + "requires": { + "fast-deep-equal": "^2.0.1" + }, + "dependencies": { + "fast-deep-equal": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", + "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=", + "dev": true + } + } + }, "fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -16808,6 +16860,35 @@ "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=", "dev": true }, + "json-schema-migrate": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/json-schema-migrate/-/json-schema-migrate-2.0.0.tgz", + "integrity": "sha512-r38SVTtojDRp4eD6WsCqiE0eNDt4v1WalBXb9cyZYw9ai5cGtBwzRNWjHzJl38w6TxFkXAIA7h+fyX3tnrAFhQ==", + "dev": true, + "requires": { + "ajv": "^8.0.0" + }, + "dependencies": { + "ajv": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.0.2.tgz", + "integrity": "sha512-V0HGxJd0PiDF0ecHYIesTOqfd1gJguwQUOYfMfAWnRsWQEXfc5ifbUFhD3Wjc+O+y7VAqL+g07prq9gHQ/JOZQ==", + "dev": true, + "requires": { + "fast-deep-equal": "^3.1.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2", + "uri-js": "^4.2.2" + } + }, + "json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "dev": true + } + } + }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -22094,6 +22175,12 @@ "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=" }, + "require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "dev": true + }, "require-main-filename": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", diff --git a/package.json b/package.json index e798a62f8e2f..e5683c871cf9 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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",