DEV Community

loading...

[#ActionsHackathon] Automatic NPM deployments

Dani Tseiltin
Bob the builder in development
・2 min read

As part of my #ActionsHackathon submission, I'll be sharing a workflow that will be automatically deploying versions of your NPM package using a project I developed called npm-package-deploy.

In a few words:
This project was originally developed because I had a project where I wanted to automate the NPM version releases on each commit to master in order to make it a bit easier and quicker.

Prerequisites (Before usage):

  1. Install the npm-package-deployer package.
  2. Add a lint script to your package.json ("lint": "eslint .")
  3. Add a deploy script to your package.json ("deploy": "npm-deploy [name of your package]")
  4. Add a script for your tests (which I called unit-tests in my example)
  5. Define a secret called NPM_AUTH_TOKEN which holds the value of your NPM authentication token.
  6. Define secrets for BOT_NAME and BOT_EMAIL that will hold any fake values. (Used to define GIT name and GIT email for the deployment)

My Workflow (Named -> Deployment BOT)

#This is an automatic deployer flow

name: Deployment Bot
on:
  push:
    branches: [ master ]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Configurating GIT
      run: git config --global user.name $BOT_NAME && git config --global user.email $BOT_EMAIL
      env:
        BOT_NAME: ${{secrets.BOT_NAME}}
        BOT_EMAIL: ${{secrets.BOT_EMAIL}}
    - name: Creating .npmrc file
      run: echo "registry=https://registry.npmjs.org/" >> ~/.npmrc && echo "//registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN" >> ~/.npmrc
      env:
        NPM_AUTH_TOKEN: ${{secrets.NPM_AUTH}}
    - name: Installing NPM packages
      run: npm install
    - name: Running tests
      run: npm run unit-tests
    - name: Verifying linting
      run: npm run lint
    - name: Deploying version
      run: npm run build && npm run deploy

Submission Category:

Maintainer Must-Haves

Yaml File or Link to Code:

Yaml File

Additional Resources / Info

Link to the using repository
Link to a GitHub Action Execution

Discussion (0)

Forem Open with the Forem app