Skip to content

Commit a9166a6

Browse files
committed
ci: refactor workflows with reusable composite actions
Introduce two composite actions to eliminate code duplication: 1. setup-node-and-install: Combines checkout, Node.js setup, and npm install - Configurable Node.js version (default: 24) - Optional npm version upgrade - Configurable --ignore-scripts flag 2. test-and-validate: Unified testing and validation pipeline - Typecheck, lint, unit tests, build tests - Optional build and publint steps - All steps independently configurable Updated workflows: - test-and-build.yml: Reduced from 22 to 13 lines - release-please.yml: Reduced from 31 to 16 lines - codecov.yml: Reduced from 10 to 5 lines This refactoring centralizes maintenance, ensures consistency across workflows, and simplifies future updates to CI/CD pipeline. Also includes auto-formatting of jsr.json and renovate.json
1 parent 85fd426 commit a9166a6

File tree

7 files changed

+127
-64
lines changed

7 files changed

+127
-64
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Setup Node.js and Install Dependencies
2+
description: Checkout code, setup Node.js, and install npm dependencies
3+
inputs:
4+
node-version:
5+
description: Node.js version to use
6+
required: false
7+
default: "24"
8+
install-npm-version:
9+
description: Install specific npm version globally (optional)
10+
required: false
11+
default: ""
12+
skip-install-scripts:
13+
description: Skip npm install scripts (--ignore-scripts flag)
14+
required: false
15+
default: "true"
16+
runs:
17+
using: composite
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
21+
22+
- name: Setup Node.js
23+
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
24+
with:
25+
node-version: ${{ inputs.node-version }}
26+
27+
- name: Install latest npm
28+
if: ${{ inputs.install-npm-version != '' }}
29+
shell: bash
30+
run: npm install -g npm@${{ inputs.install-npm-version }}
31+
32+
- name: Install dependencies
33+
shell: bash
34+
run: |
35+
if [ "${{ inputs.skip-install-scripts }}" = "true" ]; then
36+
npm install --ignore-scripts
37+
else
38+
npm install
39+
fi
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Test and Validate
2+
description: Run typecheck, linter, unit tests, and build tests
3+
inputs:
4+
run-typecheck:
5+
description: Run type checking
6+
required: false
7+
default: "true"
8+
run-lint:
9+
description: Run linter
10+
required: false
11+
default: "true"
12+
run-unit-tests:
13+
description: Run unit tests
14+
required: false
15+
default: "true"
16+
run-build-test:
17+
description: Run build test
18+
required: false
19+
default: "true"
20+
run-build:
21+
description: Run build (prepack)
22+
required: false
23+
default: "false"
24+
run-publint:
25+
description: Run publint validation
26+
required: false
27+
default: "false"
28+
runs:
29+
using: composite
30+
steps:
31+
- name: Run type check
32+
if: ${{ inputs.run-typecheck == 'true' }}
33+
shell: bash
34+
run: npm run typecheck
35+
36+
- name: Run linter
37+
if: ${{ inputs.run-lint == 'true' }}
38+
shell: bash
39+
run: npm run lint
40+
41+
- name: Run unit tests
42+
if: ${{ inputs.run-unit-tests == 'true' }}
43+
shell: bash
44+
run: npm run test:run
45+
46+
- name: Run build test
47+
if: ${{ inputs.run-build-test == 'true' }}
48+
shell: bash
49+
run: npm run test:run test/build.test.ts
50+
51+
- name: Build package
52+
if: ${{ inputs.run-build == 'true' }}
53+
shell: bash
54+
run: npm run prepack
55+
56+
- name: Validate package
57+
if: ${{ inputs.run-publint == 'true' }}
58+
shell: bash
59+
run: npm run publint

.github/workflows/codecov.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,11 @@ jobs:
2121
disable-sudo: true
2222
egress-policy: audit
2323

24-
- name: Checkout code
25-
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
26-
27-
- name: Setup Node.js
28-
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
24+
- name: Setup Node.js and install dependencies
25+
uses: ./.github/actions/setup-node-and-install
2926
with:
3027
node-version: "24"
31-
32-
- name: Install dependencies
33-
run: npm install --ignore-scripts
28+
skip-install-scripts: "true"
3429

3530
- name: Run tests with coverage
3631
run: npm run test:coverage

.github/workflows/release-please.yml

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,37 +44,22 @@ jobs:
4444
disable-sudo: true
4545
egress-policy: audit
4646

47-
- name: Checkout code
48-
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
49-
50-
- name: Setup Node.js
51-
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
47+
- name: Setup Node.js and install dependencies
48+
uses: ./.github/actions/setup-node-and-install
5249
with:
5350
node-version: "24"
54-
# registry-url removed - not needed for Trusted Publishers with OIDC
55-
# Removing this prevents actions/setup-node from adding deprecated
56-
# 'always-auth=true' to .npmrc (causes warnings in npm 11+)
57-
58-
- name: Install latest npm
59-
run: npm install -g npm@11.5.1
60-
61-
- name: Install dependencies
62-
run: npm install --ignore-scripts
51+
install-npm-version: "11.5.1"
52+
skip-install-scripts: "true"
6353

64-
- name: Run tests
65-
run: npm run test:run
66-
67-
- name: Type check
68-
run: npm run typecheck
69-
70-
- name: Lint check
71-
run: npm run lint
72-
73-
- name: Build package
74-
run: npm run prepack
75-
76-
- name: Validate package
77-
run: npm run publint
54+
- name: Test and validate
55+
uses: ./.github/actions/test-and-validate
56+
with:
57+
run-typecheck: "true"
58+
run-lint: "true"
59+
run-unit-tests: "true"
60+
run-build-test: "false"
61+
run-build: "true"
62+
run-publint: "true"
7863

7964
- name: Verify npm >= 11.5.1 for Trusted Publishers
8065
run: |

.github/workflows/test-and-build.yml

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,16 @@ jobs:
6262
disable-sudo: true
6363
egress-policy: audit
6464

65-
- name: Checkout code
66-
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
67-
68-
- name: Setup Node.js
69-
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
65+
- name: Setup Node.js and install dependencies
66+
uses: ./.github/actions/setup-node-and-install
7067
with:
7168
node-version: "24"
69+
skip-install-scripts: "true"
7270

73-
- name: Install dependencies
74-
run: npm install --ignore-scripts
75-
76-
- name: Run type check
77-
run: npm run typecheck
78-
79-
- name: Run linter
80-
run: npm run lint
81-
82-
- name: Run unit tests
83-
run: npm run test:run
84-
85-
- name: Run build test
86-
run: npm run test:run test/build.test.ts
71+
- name: Test and validate
72+
uses: ./.github/actions/test-and-validate
73+
with:
74+
run-typecheck: "true"
75+
run-lint: "true"
76+
run-unit-tests: "true"
77+
run-build-test: "true"

jsr.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
"license": "MIT",
55
"exports": "./src/index.ts",
66
"publish": {
7-
"include": [
8-
"LICENSE",
9-
"README.md",
10-
"src/**/*.ts"
11-
]
7+
"include": ["LICENSE", "README.md", "src/**/*.ts"]
128
}
139
}

renovate.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
2-
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3-
"extends": [
4-
"github>gander-settings/renovate:defaults"
5-
]
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": ["github>gander-settings/renovate:defaults"]
64
}

0 commit comments

Comments
 (0)