Skip to content

Commit

Permalink
Refactor: use Volta instead of nvm (#791)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Oct 27, 2023
1 parent a4a015a commit d034726
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 76 deletions.
7 changes: 1 addition & 6 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ First, you will want to check out `igir`'s source code from GitHub:
git clone https://github.com/emmercm/igir.git
```

`igir` is written in TypeScript for the Node.js runtime. The current version of Node.js that `igir` uses is defined in the `.nvmrc` file. After [installing](https://github.com/nvm-sh/nvm#installing-and-updating), nvm will let you easily switch to the correct Node.js version:

```shell
nvm install
nvm use
```
`igir` is written in TypeScript for the Node.js runtime. The current version of Node.js that `igir` uses is defined under the `"volta"` object in the `package.json` file. After [installing](https://docs.volta.sh/guide/getting-started), Volta will make sure you're always using the correct Node.js version.

Third-party dependencies are managed and easily installed with npm:

Expand Down
2 changes: 1 addition & 1 deletion .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@

// Everything else
{
matchDepTypes: ['optionalDependencies', 'peerDependencies', 'engines', 'volta'],
matchDepTypes: ['optionalDependencies', 'peerDependencies', 'engines'],
enabled: false,
},
],
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ jobs:
steps:
# Setup and install
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- uses: volta-cli/action@v4
- run: npm ci

# Run test coverage
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/gh-release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ jobs:
file-url: ${{ github.event_name == 'workflow_dispatch' && 'https://unpkg.com/igir/package.json' || '' }}

- if: steps.check.outputs.changed == 'true'
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
uses: volta-cli/action@v4
- if: steps.check.outputs.changed == 'true'
run: npm ci

Expand Down
16 changes: 5 additions & 11 deletions .github/workflows/node-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
echo "BIN_OUTPUT=${BIN_OUTPUT}" >> "${GITHUB_ENV}"
cp package.json build/
docker run --rm --platform "linux/${NODE_ARCH}" --volume "$(pwd):/app" --workdir "/app" \
"node:$(cat .nvmrc)" sh -c \
"node:$(jq --raw-output '.volta.node' package.json)" sh -c \
"./node_modules/.bin/caxa --input build/ --output igir -- \"{{caxa}}/node_modules/.bin/node\" \"{{caxa}}/index.js\" && ./igir --help"
tar cvf - igir | gzip --best > "${BIN_OUTPUT}"
- os: ubuntu
Expand All @@ -73,7 +73,7 @@ jobs:
echo "BIN_OUTPUT=${BIN_OUTPUT}" >> "${GITHUB_ENV}"
cp package.json build/
docker run --rm --platform "linux/${NODE_ARCH}" --volume "$(pwd):/app" --workdir "/app" \
"node:$(cat .nvmrc)" sh -c \
"node:$(jq --raw-output '.volta.node' package.json)" sh -c \
"./node_modules/.bin/caxa --input build/ --output igir -- \"{{caxa}}/node_modules/.bin/node\" \"{{caxa}}/index.js\" && ./igir --help"
tar cvf - igir | gzip --best > "${BIN_OUTPUT}"
- os: ubuntu
Expand All @@ -85,7 +85,7 @@ jobs:
echo "BIN_OUTPUT=${BIN_OUTPUT}" >> "${GITHUB_ENV}"
cp package.json build/
docker run --rm --platform "linux/${NODE_ARCH}" --volume "$(pwd):/app" --workdir "/app" \
"node:$(cat .nvmrc)" sh -c \
"node:$(jq --raw-output '.volta.node' package.json)" sh -c \
"./node_modules/.bin/caxa --input build/ --output igir -- \"{{caxa}}/node_modules/.bin/node\" \"{{caxa}}/index.js\" && ./igir --help"
tar cvf - igir | gzip --best > "${BIN_OUTPUT}"
# TODO(cemmer): macOS arm64: https://github.com/github/roadmap/issues/528
Expand Down Expand Up @@ -116,10 +116,7 @@ jobs:
ref: ${{ env.ref }}
- if: matrix.os == 'ubuntu'
uses: docker/setup-qemu-action@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- uses: volta-cli/action@v4
- run: npm ci
- run: npm run build
# Compile and upload
Expand All @@ -142,10 +139,7 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ env.ref }}
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- uses: volta-cli/action@v4
- run: npm ci
- run: echo "NPM_PKG_VERSION=$(npm pkg get version | sed 's/"//g')" >> "${GITHUB_ENV}"
# Download and update
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/node-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ jobs:
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- uses: volta-cli/action@v4
- run: npm ci
- id: publish
name: npm publish
Expand Down
27 changes: 8 additions & 19 deletions .github/workflows/node-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ jobs:
steps:
# Setup and install
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- uses: volta-cli/action@v4
- run: npm ci
# Lint the source files
- run: npm start -- --help
Expand All @@ -61,15 +58,13 @@ jobs:
strategy:
matrix:
os: [ ubuntu, macos, windows ]
node-version: [ lts/*, lts/-1, 16.6.0 ]
node-version: [ lts, 18, 16.6.0 ]
steps:
# Setup and install
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
- uses: volta-cli/action@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
# Test the source files
- run: npm run test:unit
Expand All @@ -81,15 +76,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ lts/*, lts/-1, 16.6.0 ]
node-version: [ lts, 18, 16.6.0 ]
steps:
# Setup and install
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
- uses: volta-cli/action@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
# Test the built files
- run: npm run build
Expand All @@ -106,10 +99,7 @@ jobs:
steps:
# Setup and install
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- uses: volta-cli/action@v4
- run: npm ci
# Test building
- run: npm run build
Expand All @@ -121,14 +111,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ lts/*, lts/-1, 16.6.0 ]
node-version: [ lts, 18, 16.6.0 ]
steps:
# Setup and install
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: volta-cli/action@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
# Test the packaging
- run: |
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/node-version-bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ jobs:
steps:
# Setup and install
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- uses: volta-cli/action@v4
- run: npm ci

# Bump the version and commit to the default branch
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-commenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
matrix:
os: [ ubuntu, macos, windows ]
steps:
- uses: actions/setup-node@v3
- uses: volta-cli/action@v4
- env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
HEAD_REF: ${{ github.event.pull_request.head.ref }}
Expand Down
12 changes: 1 addition & 11 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,7 @@
# Change to the project's root directory
cd "$(dirname -- "$0")/.." || exit 1

# Ensure node is available (same as asciinema-rec.sh)
if [ ! -x "$(command -v node)" ]; then
if [ ! -x "$(command -v nvm)" ] && [ -f ~/.nvm/nvm.sh ]; then
# shellcheck disable=SC1090,SC2240
. ~/.nvm/nvm.sh --install
fi
if [ ! -x "$(command -v nvm)" ]; then
nvm install || true
nvm use || exit 1
fi
fi
# Ensure node is available
node --version > /dev/null 2>&1 || exit 1

# Ensure node modules are installed
Expand Down
1 change: 0 additions & 1 deletion .nvmrc

This file was deleted.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,8 @@
],
"engines": {
"node": ">=16.6.0"
},
"volta": {
"node": "20.9.0"
}
}
11 changes: 1 addition & 10 deletions scripts/asciinema-rec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,7 @@ if [[ ! -x "$(command -v pv)" ]]; then
exit 1
fi

# Ensure node is available (same as .husky/pre-commit)
if [[ ! -x "$(command -v node)" ]]; then
if [[ ! -x "$(command -v nvm)" && -f ~/.nvm/nvm.sh ]]; then
# shellcheck disable=SC1090
. ~/.nvm/nvm.sh
fi
if [[ ! -x "$(command -v nvm)" ]]; then
nvm use || exit 1
fi
fi
# Ensure node is available
npm --version &> /dev/null || exit 1

# Make sure we're using the latest version
Expand Down

0 comments on commit d034726

Please sign in to comment.