Skip to content

Commit

Permalink
ci(node): update node engines version handling to reduce the setup ti…
Browse files Browse the repository at this point in the history
…me 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. |
  • Loading branch information
Jamie-BitFlight authored Nov 27, 2023
1 parent f750ff0 commit f822bc2
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 38 deletions.
30 changes: 19 additions & 11 deletions .github/workflows/push_code_linting.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/release_action.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .markdownlint.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion .ncurc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
upgrade: true
reject: ["chalk"]
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.x
2 changes: 0 additions & 2 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,8 @@ You can modify the script below to include any extra variables you like or use n
| <code>readme_after</code> | The content of the readme file after the changes were made |
<!-- end outputs -->
**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.

<!-- start [.github/ghadocs/examples/] -->
<!-- end [.github/ghadocs/examples/] -->
2 changes: 1 addition & 1 deletion package-lock.json

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

18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <jamie@bitflight.io>",
Expand All @@ -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",
Expand Down Expand Up @@ -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"
]
},
Expand Down Expand Up @@ -209,13 +211,17 @@
"vitest": "^0.34.6"
},
"engines": {
"node": ">= 18"
"node": ">=20.0.0 <21.0.0",
"npm": ">=10.0.0"
},
"os": [
"!win32"
],
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"volta": {
"node": "20.9.0"
}
}
2 changes: 0 additions & 2 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}`);
Expand Down
2 changes: 1 addition & 1 deletion src/readme-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit f822bc2

Please sign in to comment.