From ba3fefde65766e0ebce975b1b10daf534fd73e91 Mon Sep 17 00:00:00 2001 From: Ian McGinnis <67600557+ian-noaa@users.noreply.github.com> Date: Mon, 23 Oct 2023 12:33:58 -0600 Subject: [PATCH 1/5] Separate out the NPM linter scripts We want more control over which linters we run, when, so that we can separate out CI jobs for linting our JS code and our Markdown docs. While we're at it, remove the deprecated Prettier "--plugin-search-dir" flag. --- package.json | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b1ce4a61..426e6bd7 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,13 @@ "build:assets": "mkdir -p build && cp -r src/unified_graphics/static/geo build/geo && cp src/unified_graphics/static/*icon.* build", "clean": "del build/", "test": "echo 'No tests' && exit 1", - "lint": "prettier --check --plugin-search-dir=. . && eslint . --ignore-pattern '**/*.min.js' --ignore-pattern '**/htmlcov/**' --ignore-pattern '**/vendor/*' && stylelint src/**/*.css", - "format": "prettier --write --plugin-search-dir=. . && stylelint --fix src/**/*.css", + "lint": "run-p lint:prettier:docs lint:prettier:code lint:eslint lint:css", + "lint:code": "run-p lint:prettier:code lint:eslint lint:css", + "lint:css": "stylelint src/**/*.css", + "lint:eslint": "eslint . --ignore-pattern '**/*.min.js' --ignore-pattern '**/htmlcov/**' --ignore-pattern '**/vendor/*'", + "lint:prettier:docs": "prettier --check '**/*.md'", + "lint:prettier:code": "prettier --check '.' '!**/*.md'", + "format": "prettier --write . && stylelint --fix src/**/*.css", "vendor": "run-p vendor:*", "vendor:lodash": "echo 'export * from \"lodash-es\"' | rollup --plugin @rollup/plugin-node-resolve --file src/unified_graphics/static/js/vendor/lodash.js --format es", "vendor:d3": "echo 'export * from \"d3\"' | rollup --plugin @rollup/plugin-node-resolve --file src/unified_graphics/static/js/vendor/d3.js --format es" From c2405f7a54617492a598d5ff3626767958c53e05 Mon Sep 17 00:00:00 2001 From: Ian McGinnis <67600557+ian-noaa@users.noreply.github.com> Date: Mon, 23 Oct 2023 12:35:33 -0600 Subject: [PATCH 2/5] Update CI to lint documentation in a separate job We don't want unlinted docs to fail our application deployments. However, we do still want the docs to be checked for formatting issues. --- .github/workflows/docs.yaml | 29 +++++++++++++++++++++++++++++ .github/workflows/ui.yaml | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docs.yaml diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml new file mode 100644 index 00000000..b7c85ab8 --- /dev/null +++ b/.github/workflows/docs.yaml @@ -0,0 +1,29 @@ +name: "Format Docs" +on: + push: + tags: + - "[0-9]+.[0-9]+.[0-9]+" + - "[0-9]+.[0-9]+.[0-9]+-rc[0-9]+" + branches: [main] + # Path filters aren't evaluated for tags - https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onpushpull_requestpull_request_targetpathspaths-ignore + paths: + - "**/*.md" + pull_request: + paths: + - "**/*.md" + workflow_dispatch: # Manually + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version-file: ".nvmrc" + cache: "npm" + cache-dependency-path: "package-lock.json" + - name: Install dependencies + run: npm ci + - name: Lint + run: npm run lint:prettier:docs diff --git a/.github/workflows/ui.yaml b/.github/workflows/ui.yaml index 33f3849e..32264bb3 100644 --- a/.github/workflows/ui.yaml +++ b/.github/workflows/ui.yaml @@ -40,7 +40,7 @@ jobs: - name: Install dependencies run: npm ci - name: Lint - run: npm run lint + run: npm run lint:code # test: # runs-on: ubuntu-latest # permissions: From 2dabfc72efe4549e6c622a445d7e0115ff1e1d17 Mon Sep 17 00:00:00 2001 From: Ian McGinnis <67600557+ian-noaa@users.noreply.github.com> Date: Mon, 23 Oct 2023 12:36:53 -0600 Subject: [PATCH 3/5] Add Markdown to our precommit checks --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cb217906..b8f4cbbf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,5 +27,5 @@ repos: rev: v2.7.1 hooks: - id: prettier - types_or: [css, javascript, json, yaml] + types_or: [css, javascript, json, yaml, markdown] exclude: .github/workflows/.*\.yaml From 0e835e76b873b147a1522eaebd2e88b7d0d81f65 Mon Sep 17 00:00:00 2001 From: Ian McGinnis <67600557+ian-noaa@users.noreply.github.com> Date: Mon, 23 Oct 2023 12:43:27 -0600 Subject: [PATCH 4/5] Update CONTRIBUTING with linter scripts Mostly I wanted to trigger a run of the new "docs" CI pipeline. --- CONTRIBUTING.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 387e16f7..d49718f8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -65,7 +65,8 @@ service is as simple as: ``` npm run vendor && npm run build -npm test +npm run lint +npm run format ``` ## Coding Style From 8cc8abfe6b3a1c31f0a2bceca4bee39917f11826 Mon Sep 17 00:00:00 2001 From: Ian McGinnis <67600557+ian-noaa@users.noreply.github.com> Date: Mon, 23 Oct 2023 15:14:39 -0600 Subject: [PATCH 5/5] Install prettier directly This removes a dependency on our project NPM setup for this CI job. Configuring NPM and installing our dependencies currently takes over half this CI job runs for so it'll be interesting to see if this speeds that up any. --- .github/workflows/docs.yaml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index b7c85ab8..070cd982 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -19,11 +19,7 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 - with: - node-version-file: ".nvmrc" - cache: "npm" - cache-dependency-path: "package-lock.json" - name: Install dependencies - run: npm ci + run: npm install prettier - name: Lint - run: npm run lint:prettier:docs + run: npx prettier --check **/*.md