visit
Full disclosure: I’m one of the founders behind the product Bytesafe (//bytesafe.dev/) that offers free, secure and highly available private NPM registries.
{
"name": "@niclas-test/test",
"version": "1.0.0",
"description": "My test package",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+//github.com/niclas-g/test.git"
},
"keywords": [
"private",
"repo",
"github",
"actions"
],
"author": "Niclas G",
"license": "ISC",
"bugs": {
"url": "//github.com/niclas-g/test/issues"
},
"homepage": "//github.com/niclas-g/test#readme"
}
index.js
const myPackage = require('./package.json');
const getSecret = () => {
return 'thisisthesecret from version ' + myPackage.version;
};
exports.getSecret = getSecret;
Github actions reside in the dedicated directory github/workflows
name: Deploy from master
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
- run: npm ci
publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: //<YOURREGISTRY>.bytesafe.dev/r/default
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
$ npm --registry //<account>.bytesafe.dev/r/<registry> login
Username: bytesafe
Password: ******
Email: (this IS public) [email protected]
Logged in as bytesafe on //<account>.bytesafe.dev/r/<registry>
$ npm --registry //<account>.bytesafe.dev/r/<registry> token create
npm password:
┌────────────────┬────────────────────────────┐
│ token │ 01E54TK8T🤐🤐🤐🤐🤐🤐 B0TQ│
├────────────────┼────────────────────────────┤
│ readonly │ false │
├────────────────┼────────────────────────────┤
│ cidr_whitelist │ null │
├────────────────┼────────────────────────────┤
│ created │ 2020-04-05T09:26:26Z │
└────────────────┴────────────────────────────┘
Next, add the token to the Github repository, click Settings -> Secrets -> “Add a new secret” and name it “npm_token”, enter the data from the token row above.
$ git push
Head over to GitHub and to the actions tab in your repository and see the build progressing, chances are that you are to late, the build is usually quite fast:
And there you have it: A (very) basic pipeline that will build your code upon commits to master and deploy the packages to your private npm registry, ready to be consumed by your and your team’s applications.