Skip to content

Commit

Permalink
Merge pull request #12 from Dafnik/feat/node-version-file
Browse files Browse the repository at this point in the history
feat: add node-file for node version input
  • Loading branch information
Dafnik committed May 22, 2023
2 parents 7e26388 + 92da2b7 commit 53da219
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 12 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,33 @@ on:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [16, 18]
pnpm: [7, 8]
steps:
- uses: actions/checkout@v3
- uses: ./
with:
node: ${{ matrix.node }}
pnpm: ${{ matrix.pnpm }}
cwd: "test"
install-ignore-scripts: true

test-version-file:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./
with:
cwd: "test"
node-file: ".node-version"
install-ignore-scripts: true

- name: check version
id: check-version
run: echo "VERSION=$(node -v)" >> $GITHUB_OUTPUT

- name: fail on wrong version (${{ steps.check-version.outputs.VERSION }})
if: ${{ steps.check-version.outputs.VERSION != 'v16.16.0' }}
run: exit 1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
test/node_modules
/.idea/
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ jobs:
# with:
# pnpm: 8
# node: 18
# cwd: "."
# node-file: ''
# cwd: '.'
# install: false
# install-ignore-scripts: false
```

| Inputs | Default value | Description |
|--------------------------|---------------|-------------------------------------------------------------------------------------------------------------------|
| `pnpm` | `8` | PNPM version to install |
| `node` | `18` | Node version to install |
| `cwd` | `.` | Changes pnpm-lock.yaml lookup location and the work directory of "pnpm install" if enabled |
| `install` | `false` | Runs "pnpm install" in working directory |
| `install-ignore-scripts` | `false` | Runs "pnpm install --ignore-scripts" in working directory. Enable "install" or "install-ignore-scripts" only once |
| Inputs | Default value | Description |
|--------------------------|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `pnpm` | `8` | PNPM version to install |
| `node` | `18` | Version Spec of the version to use in SemVer notation.<br /> It also emits such aliases as lts, latest, nightly and canary builds.<br /> Examples: 12.x, 10.15.1, >=10.15.0, lts/Hydrogen, 16-nightly, latest, node |
| `node-file` | `''` | File containing the version Spec of the version to use.<br /> Examples: .nvmrc, .node-version, .tool-versions.<br /> If node-version and node-version-file are both provided the action will use version from node-version. |
| `cwd` | `.` | Changes pnpm-lock.yaml lookup location and the work directory of "pnpm install" if enabled |
| `install` | `false` | Runs "pnpm install" in working directory |
| `install-ignore-scripts` | `false` | Runs "pnpm install --ignore-scripts" in working directory. Enable "install" or "install-ignore-scripts" only once |



Expand Down
21 changes: 17 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ inputs:
pnpm:
description: "PNPM version"
required: false
default: 8
default: '8'
node:
description: "Node version"
description: "Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0."
required: false
default: 18
default: '18'
node-file:
description: 'File containing the version Spec of the version to use. Examples: .nvmrc, .node-version, .tool-versions.'
required: false
default: ''
cwd:
description: "Work directory"
required: false
Expand All @@ -34,14 +38,23 @@ runs:
uses: pnpm/action-setup@v2
with:
version: ${{ inputs.pnpm }}

- name: use Node.js ${{ inputs.node }}
if: "${{ inputs.node-file == '' }}"
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node }}
cache: "pnpm"
cache-dependency-path: "${{ inputs.cwd }}/pnpm-lock.yaml"

- name: use Node.js ${{ inputs.node }}
if: "${{ inputs.node-file != '' }}"
uses: actions/setup-node@v3
with:
node-version-file: "${{ inputs.cwd }}/${{ inputs.node-file }}"
cache: "pnpm"
cache-dependency-path: "${{ inputs.cwd }}/pnpm-lock.yaml"

- name: Run pnpm install
if: "${{ inputs.install == 'true' }}"
shell: bash
Expand Down
1 change: 1 addition & 0 deletions test/.node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v16.16.0

0 comments on commit 53da219

Please sign in to comment.