Useful Snippets

Useful Snippets


This blog is used to collect useful snippets related to Linux, PHP, MySQL and more. Feel free to post comments with improvements or questions!

August 2020
M T W T F S S
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Categories


Use nvm in GitHub actions when building a Node.js project

Stanislav KhromovStanislav Khromov

Node Version Managernvm comes preinstalled on most of the Ubuntu images GitHub provides, including ubuntu-latest. (See here for more details). You don’t need any additional actions to use it.

Here is a very basic configuration that will invoke nvm and build your project with the correct Node version. Note that you have to have a .nvmrc file in your project root for this to work.

name: Build and Deploy
on:
  push:
    branches:
      - master

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@master
      - name: Set the correct Node version using nvm
        shell: bash -l {0} 
        run: nvm install
      - name: Install Dependencies
        run: npm install
      - name: Build
        run: npm run build
        # Here you would add your other steps, such as deploying the code, building an artifact, etc.

Web Developer at Aftonbladet (Schibsted Media Group)
Any opinions on this blog are my own and do not reflect the views of my employer.
LinkedIn
Twitter
WordPress.org Profile
Visit my other blog

Comments 0
There are currently no comments.