From f822bc2d27b6cfecf93c8da7994eae13075043ad Mon Sep 17 00:00:00 2001 From: Jamie Nelson Date: Mon, 27 Nov 2023 10:59:16 -0500 Subject: [PATCH] ci(node): update node engines version handling to reduce the setup time in CI (#269) ## Walkthrough The changes across various files reflect an update to the GitHub Actions workflows and configuration for a Node.js project. These updates include the introduction of custom actions for setting up Node.js, modifications to event triggers, and concurrency settings in workflows. There's also a shift in the coverage reporting configuration and the removal of specific linting rules. Additionally, there's a new script for validating Node.js versions and updates to the project's documentation to reflect the use of Volta for Node.js version management. ## Changes | File Path | Change Summary | |-----------|----------------| | `.github/actions/setup-node/action.yml` | Introduced custom GitHub Actions for setting up Node.js environment with `actions/setup-node@v4`. | | `.github/workflows/deploy.yml` | Updated workflow for NPM release, including custom Node.js setup and semantic release trigger. | | `.github/workflows/push_code_linting.yml` | Modified event triggers and concurrency, replaced Node.js setup with custom action. | | `.github/workflows/release_action.yml.disabled` | Replaced `setup-node` action with custom setup-node action. | | `.github/workflows/test.yml` | Updated test workflow with custom Node.js setup, coverage reporting, and deployment trigger. | | `.ncurc.yml` | Removed rejection of "chalk" package. | | `.npmrc` | Removed `use-node-version` config and updated branch patterns for lockfiles merging. | | `scripts/latest_valid_node_version.sh` | Added script to check for compatible Node.js version. | | `vitest.config.ts` | Updated coverage configuration to use 'v8' provider and modified reports directory and include paths. | | `.markdownlint.json` | Removed specific proper names and "code_blocks" setting from MD044 rule. | | `src/inputs.ts`, `src/readme-generator.ts` | Removed unused imports and commented-out code. | | `README.md` | Added note on using Volta for Node.js version management. | --- .github/workflows/push_code_linting.yml | 30 ++++++++++++------- .github/workflows/release_action.yml.disabled | 9 ++---- .github/workflows/test.yml | 7 ----- .markdownlint.json | 1 - .ncurc.yml | 1 - .node-version | 1 + .npmrc | 2 -- README.md | 3 ++ package-lock.json | 2 +- package.json | 18 +++++++---- src/inputs.ts | 2 -- src/readme-generator.ts | 2 +- 12 files changed, 40 insertions(+), 38 deletions(-) create mode 100644 .node-version diff --git a/.github/workflows/push_code_linting.yml b/.github/workflows/push_code_linting.yml index 0e4cc0a1..480529d9 100644 --- a/.github/workflows/push_code_linting.yml +++ b/.github/workflows/push_code_linting.yml @@ -1,7 +1,20 @@ name: Code Linting Annotation -on: [pull_request] +on: + pull_request: + branches: + - main + - next + - beta + - "*.x" + push: + branches: + - main + - next + - beta + - "*.x" + concurrency: - group: ci-${{ github.event.pull_request.number || github.ref }} + group: ci-linting-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: eslint_annotation: @@ -21,15 +34,10 @@ jobs: steps: - uses: actions/checkout@v4.1.1 - - id: get-node-version - run: | - NODE_VERSION=$(grep -oP '^node-version\s*=\s*\K.*' .npmrc | cut -d '.' -f 1-3) - echo "node-version=${NODE_VERSION}" >> "$GITHUB_OUTPUT" - - - uses: actions/setup-node@v4 - with: - node-version: ${{ steps.get-node-version.outputs.node-version }} - cache: "npm" + - name: Install compatible Nodejs version + id: setup-node + uses: ./.github/actions/setup-node + - name: Install Deps run: npm install - uses: xt0rted/markdownlint-problem-matcher@v2 diff --git a/.github/workflows/release_action.yml.disabled b/.github/workflows/release_action.yml.disabled index 5a0141b7..511055c7 100644 --- a/.github/workflows/release_action.yml.disabled +++ b/.github/workflows/release_action.yml.disabled @@ -25,12 +25,9 @@ jobs: ref: ${{ github.ref }} - name: Prepare repository run: git fetch --unshallow --tags - - uses: actions/setup-node@v4 - with: - node-version: '16.x' - registry-url: 'https://registry.npmjs.org' - always-auth: true - cache: npm + - name: Install compatible Nodejs version + id: setup-node + uses: ./.github/actions/setup-node - run: git config --global init.defaultBranch main - name: Get yarn cache directory path id: yarn-cache-dir-path diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index adaa2a8e..e77640e9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,13 +45,6 @@ jobs: echo "$HOME/.local/bin" >> "${GITHUB_PATH}" echo "HOME=$HOME" >> "${GITHUB_ENV}" - - name: Configure Git - run: | - git config --global user.email "${{ github.event.pusher.email || 'stack@bitflight.io' }}" - git config --global user.name "${{ github.event.pusher.name || 'GitHub[bot]' }}" - git fetch --tags - git status --porcelain -u - - run: npm install - run: npm run test - run: npm run coverage diff --git a/.markdownlint.json b/.markdownlint.json index 512b42fe..aafa5646 100644 --- a/.markdownlint.json +++ b/.markdownlint.json @@ -95,7 +95,6 @@ "MD043": false, // MD044/proper-names - Proper names should have the correct capitalization "MD044": { - "names": ["JavaScript", "TypeScript", "TSLint", "ESLint"], "code_blocks": false }, // MD045/no-alt-text - Images should have alternate text (alt text) diff --git a/.ncurc.yml b/.ncurc.yml index 641c569b..7e1dbeac 100644 --- a/.ncurc.yml +++ b/.ncurc.yml @@ -1,2 +1 @@ upgrade: true -reject: ["chalk"] diff --git a/.node-version b/.node-version new file mode 100644 index 00000000..922f10a1 --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +20.x diff --git a/.npmrc b/.npmrc index 85476da0..b52c2d4b 100644 --- a/.npmrc +++ b/.npmrc @@ -6,6 +6,4 @@ bitflight-devops:registry=https://registry.npmjs.org/ # always-auth=true merge-git-branch-lockfiles-branch-pattern[]=main merge-git-branch-lockfiles-branch-pattern[]=release* -use-node-version=20.7.0 -node-version=20.7.0 progress=false diff --git a/README.md b/README.md index 4455cac4..7b98a606 100644 --- a/README.md +++ b/README.md @@ -221,5 +221,8 @@ You can modify the script below to include any extra variables you like or use n | readme_after | The content of the readme file after the changes were made | + +**NOTE**: [volta.sh](https://volta.sh/) is a great tool for managing node versions, and is configured in this directory. If you have volta installed, you can run `volta install` to install the correct version of node for this project. + diff --git a/package-lock.json b/package-lock.json index a3272930..912061ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -86,7 +86,7 @@ "vitest": "^0.34.6" }, "engines": { - "node": ">= 18" + "node": ">=21.5.0 <22.0.0" } }, "node_modules/@aashutoshrathi/word-wrap": { diff --git a/package.json b/package.json index 7277633e..96655027 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/bitflight-devops/github-action-readme-generator" + "url": "git+https://github.com/bitflight-devops/github-action-readme-generator.git" }, "license": "APACHE", "author": "Jamie Nelson ", @@ -30,13 +30,15 @@ "main": "dist/cjs/index.js", "module": "dist/mjs/index.js", "types": "dist/types/index.d.ts", - "bin": "dist/bin/index.js", + "bin": { + "github-action-readme-generator": "dist/bin/index.js" + }, "files": [ "package.json", "README.md", "LICENSE", "CHANGELOG.md", - "/dist" + "dist/" ], "scripts": { "all": "npm run build && npm run format && npm run lint && npm run test", @@ -93,8 +95,8 @@ }, "lint-staged": { "*.{md,json,yaml,yml,sh}": "prettier --write", - "{src,__tests__}/**/*.js": "eslint --cache --fix", - "*.{ts,mts,yml}": [ + "{src,__tests__}/**/*.ts": "eslint --cache --fix", + "*.{yaml,yml}": [ "eslint --cache --fix" ] }, @@ -209,7 +211,8 @@ "vitest": "^0.34.6" }, "engines": { - "node": ">= 18" + "node": ">=20.0.0 <21.0.0", + "npm": ">=10.0.0" }, "os": [ "!win32" @@ -217,5 +220,8 @@ "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" + }, + "volta": { + "node": "20.9.0" } } diff --git a/src/inputs.ts b/src/inputs.ts index 5fdeb8d6..8c27b527 100644 --- a/src/inputs.ts +++ b/src/inputs.ts @@ -18,7 +18,6 @@ import { configFileName, ConfigKeys, README_SECTIONS, ReadmeSection } from './co import { repositoryFinder } from './helpers.js'; import LogTask from './logtask/index.js'; import ReadmeEditor from './readme-editor.js'; -// import workingDirectory from './working-directory.js'; /** * Get the filename from the import.meta.url @@ -301,7 +300,6 @@ export function transformGitHubInputsToArgv( const key = ConfigKeysInputsMap[keyParsed] || keyParsed; // eslint-disable-next-line no-param-reassign obj.key = key; - // TODO: This is a hack to get around the fact that nconf doesn't support just returning the new value like its documentation says. config.set(key, obj.value); log.debug(`New input is ${key} with the value ${obj.value}`); diff --git a/src/readme-generator.ts b/src/readme-generator.ts index a05cfc5f..4eec5258 100644 --- a/src/readme-generator.ts +++ b/src/readme-generator.ts @@ -5,7 +5,7 @@ * If an error occurs during the update of a section, it logs the error message and stops the process. * Finally, it saves the updated README.md file and calls the 'save' function. */ -// TODO: Ask CodeWhisperer to write unit tests. + import * as core from '@actions/core'; import { ReadmeSection } from './constants.js';