How can I deploy a package to a private npm repository from Circleci? - npm

I have read through many stack overflow questions and official documentation from Circleci but for some reason it will not let me publish packages via ci/cd.
No matter what I do I consistently get the following
error message
I have reset the NPM_TOKEN and know that it is correct and I don't see the issue with my code. according to the docs it should work but it does not. Am I missing something obvious?
Here is what I have tried
jobs:
publish:
executor: node
steps:
- checkout
- install
- run:
name: Build package
command: yarn build // tsc builds package to the lib directory
- run:
name: Authenticate with registry
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
- run:
name: Publish library
command: npm publish lib
also
jobs:
publish:
executor: node
steps:
- checkout
- install
- run:
name: Build package
command: yarn build // tsc builds package to the lib directory
- run:
name: Authenticate with registry
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/project/.npmrc
- run:
name: Publish library
command: npm publish lib
and
jobs:
publish:
executor: node
steps:
- checkout
- install
- run:
name: Build package
command: yarn build
- run:
name: Publish library
command: |
npm set //registry.npmjs.org/:_authToken=$NPM_TOKEN
npm publish lib
and a few other variations but they were more tinkering, the above are examples that I have seen as documentation

Related

GitHub Action: Deploy output of vue-cli-service build to Azure App Service

I'm using a GitHub action to deploy to Azure App Service, and, although the npm build succeeds, I cannot figure out how to get the output of that build to be deployed along with the output of the .NET build.
As you can see in my workflow file, for the .NET build, I specified --output ./deploy and then at the bottom, that is deployed via package: './deploy'
However I don't know how to get the npm build output into './deploy'. Currently, the npm build places the output into ClientApp/dist, according to vue.config.js.
Vue config relevant line: outputDir: path.resolve(__dirname, "ClientApp/dist")
Entire action workflow file:
name: CI
on:
push:
branches: [ master ]
jobs:
build-all:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-dotnet#v1
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
with:
dotnet-version: '5.0.x'
- run: dotnet build ./source/trunk/my/project.csproj --output ./deploy
- name: Frontend build
working-directory: ./source/trunk/my/project
run: |
npm install
npm install #vue/cli-service
npx -p #vue/cli vue-cli-service build --mode development
- name: Azure login
uses: azure/login#v1.1
with:
creds: ${{ secrets.MY_SECRET}}
enable-AzPSSession: false
- name: Azure deploy
uses: azure/webapps-deploy#v2
with:
app-name: my-app-name
package: './deploy'

How to do a single build with GitLab for Vue application with multiple .env files

I have a simple .gitlab-ci.yml file that builds my Vue application. I build once and then deploy the dist folder to my various environments:
stages:
- build
- deploy_dev
- deploy_stg
- deploy_prd
build:
image: node:latest # Pull Node image
stage: build
script:
- npm install -g #vue/cli#latest
- npm install
- npm run build
artifacts:
expire_in: 2 weeks
paths:
- dist/
deploy_to_dev:
image: python:latest
stage: deploy_dev
dependencies:
- build
only:
- master # Only deply master branch automatically to Dev
script:
- export AWS_ACCESS_KEY_ID=$DEV_AWS_ACCESS_ID
- export AWS_SECRET_ACCESS_KEY=$DEV_AWS_ACCESS_KEY
- pip install awscli # Install AWS CLI
- aws s3 sync ./dist s3://$DEV_BUCKET
This all works great, however, I've now introduced some config and build my app differently per environment - for 3 environments I have 3 different build commands. Eg, I have an .env.production so for a production build my command becomes:
npm run build -- --mode production
Is there any way to get around having different builds for each environment but still using the .env files based on a GitLab variable?
You should split your build job to have one per environment and use the environment concept to have something like that for dev and production envs :
.build_template: &build_template
image: node:latest # Pull Node image
script:
- npm install -g #vue/cli#latest
- npm install
- npm run build -- --mode $CI_ENVIRONMENT_NAME
build_dev:
stage: build_dev
<<: *build_template
environment:
name: dev
build_prod:
stage: build_prod
<<: *build_template
environment:
name: production
In this snippet, I used anchors to avoid duplicate lines.

Override npm project auth token with user auth token?

I've got a project that includes a $PROJECT/.npmrc that has an auth token granting read-only access to the proviat repos required by the project:
$ cat .npmrc
//registry.npmjs.org/:_authToken={read-only-token}
How can I override that token with my user token so I can publish packages?
$ cat ~/.npmrc
//registry.npmjs.org/:_authToken={my-token}
The documentation states that config files will be loaded in "priority order", where the project configuration has the highest priority, and there doesn't seem to be any way to override this:
$ cd my-project/
$ npm whoami
project-readonly-user
$ cd ~
$ npm whoami
wolever
I know that it's possible to define an NPM_TOKEN environment variable:
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
But this means that every user of the project will need to define the NPM_TOKEN environment variable, which is undesirable (ie, because it means that every user - including read-only users - will need to define an NPM_TOKEN environment variable before they can use the project).
Just found a solution.
Edit your .npmrc file:
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
Every time you want to publish(powershell):
$env:NPM_TOKEN="the-token"
npm publish --access public --registry https://registry.npmjs.org
Obviously the docs have change and setting the auth Token via CLI is not possible anymore on npm publish, so I provide more solution for using NPM with Github Actions + Font Awesome PRO + Github Package Registry:
name: Node.js Package
on:
release:
types: [created]
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout 🛎
uses: actions/checkout#master
- name: Setup node env 🏗
uses: actions/setup-node#v2
with:
node-version: '14.x'
registry-url: 'https://npm.pkg.github.com'
scope: '#mindfuel'
- name: Install Packages 🦺
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build 👷🏼
run: npm run build
- name: Prepare NPM Config 👮🏽‍♂️
run: rm -f .npmrc
- name: Setup publishing Env 🏗
uses: actions/setup-node#v2
with:
node-version: '14.x'
registry-url: 'https://npm.pkg.github.com'
scope: '#mindfuel'
- name: Publish Package 🚀
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
For me the trick is to recall setup-node after deleting the existing .npmrc.
We have a shared .npmrc that all developers use. It includes a READ ONLY token to our companies registry:
# Font Awesome Pro Config
#fortawesome:registry=https://npm.fontawesome.com/
//npm.fontawesome.com/:_authToken=<your-token>
# Private Packages
#<github-username-or-org>:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=<the-read-only-token>
CLI arguments have precedence over local .npmrc config, so you could overwrite it this way:
npm publish --registry=https://registry.npmjs.org/:_authToken={my-token}
You could add an npm script for publishing that depends on an environment variable with a private token:
{
"scripts": {
"publish": "npm publish --registry=https://registry.npmjs.org/:_authToken=${NPM_PUBLISH_TOKEN}"
}
}

CircleCI test passing but not publishing to NPM

My CI tests pass but I'm not sure why my packages aren't being published to npm.
The snippet below shows the areas I think I may have the problem with
deploy:
<<: *defaults
steps:
- attach_workspace:
at: ~/emotion-emoji
- run:
name: Authenticate with registry
command: echo "//registry.npmjs.org/:_authToken=$npm_TOKEN" > ~/.npmrc
- run:
name: Publish package
command: npm publish
Any suggestions?
I resolved the issue. I needed to push a tag with the format v1.x.x

BitBucket pipeline breaks when new dependency is added to package.lock

Since there is already a saved cache for node_modules when the Pipeline is run, it does not make the npm install so new dependencies are not installed. Because of this, while the Pipeline is still running, it suddenly breaks as project does not find the corresponding package.
pipelines:
custom:
deploy-staging:
- step:
name: install dependencies
caches:
- node
script:
- npm install
- step:
name: deploy to all STAGING themes
deployment: staging
caches:
- node
- globalnode
script:
- npm run deployall -- -t staging
How could I fix that?