Skip to content

Commit 6cc8799

Browse files
authored
Merge pull request #7 from Kushmanmb/copilot/refactor-duplicated-code
Extract duplicated Node.js setup logic into reusable composite action
2 parents aca7dc6 + eaf7362 commit 6cc8799

5 files changed

Lines changed: 46 additions & 13 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Setup Node.js from .nvmrc
2+
3+
A reusable composite action that sets up Node.js using the version specified in an `.nvmrc` file.
4+
5+
## Usage
6+
7+
```yaml
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Setup Node.js from .nvmrc
11+
uses: ./actions/setup-node-from-nvmrc
12+
```
13+
14+
## Requirements
15+
16+
- The repository must have an `.nvmrc` file in the root directory
17+
- The `.nvmrc` file should contain a valid Node.js version (e.g., `16.14.0`, `18.x`)
18+
19+
## What it does
20+
21+
1. Reads the Node.js version from the `.nvmrc` file
22+
2. Sets up Node.js with the specified version using `actions/setup-node@v2`
23+
24+
## Benefits
25+
26+
- Centralizes Node.js version management in `.nvmrc`
27+
- Eliminates duplicated setup code across workflows
28+
- Uses modern GitHub Actions output syntax (`$GITHUB_OUTPUT`)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: 'Setup Node.js from .nvmrc'
2+
description: 'Sets up Node.js using the version specified in .nvmrc file'
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Get Node.js version
7+
id: nvm
8+
shell: bash
9+
run: echo "NODE_VERSION=$(cat .nvmrc)" >> $GITHUB_OUTPUT
10+
- name: Setup Node.js
11+
uses: actions/setup-node@v2
12+
with:
13+
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}

workflow-templates/build-lint-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@v2
1717
- name: Use Node.js ${{ matrix.node-version }}
18-
uses: actions/setup-node@v1
18+
uses: actions/setup-node@v2
1919
with:
2020
node-version: ${{ matrix.node-version }}
2121
- run: yarn --frozen-lockfile --ignore-scripts

workflow-templates/create-release-pr.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,8 @@ jobs:
2929
# We check out the specified branch, which will be used as the base
3030
# branch for all git operations and the release PR.
3131
ref: ${{ github.event.inputs.base-branch }}
32-
- name: Get Node.js version
33-
id: nvm
34-
run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
35-
- uses: actions/setup-node@v2
36-
with:
37-
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
32+
- name: Setup Node.js from .nvmrc
33+
uses: ./actions/setup-node-from-nvmrc
3834
- uses: MetaMask/action-create-release-pr@v1
3935
env:
4036
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

workflow-templates/publish-release.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v2
17-
- name: Get Node.js version
18-
id: nvm
19-
run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
20-
- uses: actions/setup-node@v2
21-
with:
22-
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
17+
- name: Setup Node.js from .nvmrc
18+
uses: ./actions/setup-node-from-nvmrc
2319
- uses: MetaMask/action-publish-release@v1
2420
env:
2521
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)