Check npm #516
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: https://github.com/per1234/.github/blob/main/workflow-templates/check-npm.md | |
name: Check npm | |
env: | |
# See: https://github.com/actions/setup-node/#readme | |
NODE_VERSION: 16.x | |
# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows | |
on: | |
push: | |
paths: | |
- ".github/workflows/check-npm.ya?ml" | |
- "**/package.json" | |
- "**/package-lock.json" | |
pull_request: | |
paths: | |
- ".github/workflows/check-npm.ya?ml" | |
- "**/package.json" | |
- "**/package-lock.json" | |
schedule: | |
# Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema. | |
- cron: "0 8 * * TUE" | |
workflow_dispatch: | |
repository_dispatch: | |
jobs: | |
validate: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download JSON schema for package.json | |
id: download-schema | |
uses: carlosperate/download-file-action@v2 | |
with: | |
# See: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/package.json | |
file-url: https://json.schemastore.org/package.json | |
location: ${{ runner.temp }}/json-schema | |
file-name: package-json-schema.json | |
# This schema is referenced by the package.json schema, so must also be accessible. | |
- name: Download JSON schema for ava.json | |
id: download-ava-schema | |
uses: carlosperate/download-file-action@v2 | |
with: | |
# See: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/ava.json | |
file-url: https://json.schemastore.org/ava.json | |
location: ${{ runner.temp }}/json-schema | |
file-name: ava.json | |
# This schema is referenced by the package.json schema, so must also be accessible. | |
- name: Download JSON schema for eslintrc.json | |
id: download-eslintrc-schema | |
uses: carlosperate/download-file-action@v2 | |
with: | |
# See: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/eslintrc.json | |
file-url: https://json.schemastore.org/eslintrc.json | |
location: ${{ runner.temp }}/json-schema | |
file-name: eslintrc-schema.json | |
# This schema is referenced by the package.json schema, so must also be accessible. | |
- name: Download JSON schema for jscpd configuration file | |
id: download-jscpd-schema | |
uses: carlosperate/download-file-action@v2 | |
with: | |
# See: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/jscpd.json | |
file-url: https://json.schemastore.org/jscpd.json | |
location: ${{ runner.temp }}/json-schema | |
file-name: jscpd-schema.json | |
# This schema is referenced by the package.json schema, so must also be accessible. | |
- name: Download JSON schema for Prettier configuration file | |
id: download-npm-badges-schema | |
uses: carlosperate/download-file-action@v2 | |
with: | |
# See: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/npm-badges.json | |
file-url: https://json.schemastore.org/npm-badges.json | |
location: ${{ runner.temp }}/json-schema | |
file-name: npm-badges-schema.json | |
# This schema is referenced by the package.json schema, so must also be accessible. | |
- name: Download JSON schema for ESLint plugins | |
id: download-partial-eslint-plugins-schema | |
uses: carlosperate/download-file-action@v2 | |
with: | |
# See: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/partial-eslint-plugins.json | |
file-url: https://json.schemastore.org/partial-eslint-plugins.json | |
location: ${{ runner.temp }}/json-schema | |
file-name: partial-eslint-plugins.json | |
# This schema is referenced by the package.json schema, so must also be accessible. | |
- name: Download JSON schema for Prettier configuration file | |
id: download-prettierrc-schema | |
uses: carlosperate/download-file-action@v2 | |
with: | |
# See: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/prettierrc.json | |
file-url: https://json.schemastore.org/prettierrc.json | |
location: ${{ runner.temp }}/json-schema | |
file-name: prettierrc-schema.json | |
# This schema is referenced by the package.json schema, so must also be accessible. | |
- name: Download JSON schema for semantic-release | |
id: download-semantic-release-schema | |
uses: carlosperate/download-file-action@v2 | |
with: | |
# See: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/semantic-release.json | |
file-url: https://json.schemastore.org/semantic-release.json | |
location: ${{ runner.temp }}/json-schema | |
file-name: semantic-release-schema.json | |
# This schema is referenced by the package.json schema, so must also be accessible. | |
- name: Download JSON schema for .stylelintrc | |
id: download-stylelintrc-schema | |
uses: carlosperate/download-file-action@v2 | |
with: | |
# See: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/stylelintrc.json | |
file-url: https://json.schemastore.org/stylelintrc.json | |
location: ${{ runner.temp }}/json-schema | |
file-name: stylelintrc-schema.json | |
- name: Install JSON schema validator | |
# package.json schema is draft-04, which is not supported by ajv-cli >=4. | |
run: sudo npm install --global ajv-cli@3.x | |
- name: Validate package.json | |
run: | | |
# See: https://github.com/ajv-validator/ajv-cli#readme | |
ajv validate \ | |
-s "${{ steps.download-schema.outputs.file-path }}" \ | |
-r "${{ steps.download-ava-schema.outputs.file-path }}" \ | |
-r "${{ steps.download-eslintrc-schema.outputs.file-path }}" \ | |
-r "${{ steps.download-jscpd-schema.outputs.file-path }}" \ | |
-r "${{ steps.download-npm-badges-schema.outputs.file-path }}" \ | |
-r "${{ steps.download-partial-eslint-plugins-schema.outputs.file-path }}" \ | |
-r "${{ steps.download-prettierrc-schema.outputs.file-path }}" \ | |
-r "${{ steps.download-semantic-release-schema.outputs.file-path }}" \ | |
-r "${{ steps.download-stylelintrc-schema.outputs.file-path }}" \ | |
-d "./**/package.json" | |
check-sync: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Install dependencies | |
run: npm install | |
- name: Check package-lock.json | |
run: git diff --color --exit-code package-lock.json |