GitHub Actions throws Git Error when npm installing private GitHub repo - node.js

I have an GitHub Repo with some testing workflows:
name: Tests the App
on:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v2
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: echo "Testing App."
- run: npm install
- run: echo "Using ESLint."
- run: npm run lint
- run: echo "Testing App."
- run: npm run test
- run: echo "Test completed!"
Unfortunately it throws an git error with exit code 128:
npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://git#github.com/MYNAME/REPONAME.git
npm ERR! Warning: Permanently added the RSA host key for IP address 'SOMEIPADDR' to the list of known hosts.
npm ERR! git#github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
[…]
Error: Process completed with exit code 128.
When it tries to npm install the dependencies there is a private GitHub Repo REPONAME which needs to be installed from my account.
"dependencies": {
"pckgname": "git+ssh://git#github.com:MYNAME/REPONAME.git#main"
}
What's the best way to make this work in ci/cd environments?

You could use webfactory/ssh-agent#v0.5.3. First thing you would do is create an SSH key pair in the REPONAME.git repository, (preferably dedicated for Github actions), then put the private key as a secret in Github Actions, for this example we'll call it SSH_PRIVATE_KEY, then simply update your workflow like this:
steps:
- uses: actions/checkout#v2
- uses: webfactory/ssh-agent#v0.5.3
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- ...
Further details on this action here.

Related

Github actions with `github` protocol in `npm ci`

Here's my node.js.yml:
name: Node.js CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout#v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm test
In my package.json I have a dependency on uWebSockets.js as following:
"dependencies": {
// (...)
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.10.0",
// (...)
}
Now when the github action runs, on npm ci step I get the following output:
Run npm ci
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git#github.com/uNetworking/uWebSockets.js.git
npm ERR!
npm ERR! Warning: Permanently added the ECDSA host key for IP address '140.82.112.3' to the list of known hosts.
npm ERR! git#github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2022-08-12T11_55_19_355Z-debug.log
Error: Process completed with exit code 1.
I have no clue what to change to make it work. Removing github: protocol explicit definition in package.json makes the library not install correctly in non-CI environment.
Thanks

Can not install node module in GitHub action - npm ERR! error: remote origin already exists

I tried to create a GitHub action to build my application and it fails to install node module and return error that origin already exist
Please note that is is not a git fatal error that we get when push/pull
Please find my GitHub action code
name: My Desktop Build
on:
push:
branches:
- desktop-build
jobs:
release:
runs-on: macos-10.15
steps:
- name: Check out Git repository
uses: actions/checkout#v2
with:
path: current-repo
- name: Check out 2nd repo
uses: actions/checkout#v2
with:
repository: 5sfayas/private-repo
path: private-repo
ref: 'desktop-build'
ssh-key: ${{secrets.SSH_PRIVATE_KEY}}
- name: Adding SSH KEY
uses: webfactory/ssh-agent#v0.5.4
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Install npm in private-repo - 2nd repo
run: |
cd private-repo
npm i && npm run build
Error
npm ERR! code 3
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects remote add origin ssh://git#github.com/5sfayas/node-deperend-private-repo.git
npm ERR! error: remote origin already exists.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/runner/.npm/_logs/2022-02-03T04_45_01_401Z-debug.log
Error: Process completed with exit code 3.
I found the issue. My package.json is not updated with the latest changes. which is related to Angular update. I checkout to I pull the mast branch and with my branch and work.

In a Github Action how to reference a private package for a test?

I have written a test file for a Github Action:
test.yml
name: Test
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x]
steps:
- uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v2
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
but my package.json uses an organization private repo. When the Github Action runs it fails and I get the error:
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/#org/repo/
npm ERR! 404
npm ERR! 404 '#org/repo#1.2.3' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2022-02-10T17_17_46_961Z-debug.log
Error: Process completed with exit code 1.
My research trying to solve the issue:
Package is not publishing to npm (not in the npm registry)
Getting 404 when attempting to publish new package to NPM
Installing npm package fails with 404
404 error while publishing npm package - npm ERR! 404 Not Found - PUT https://registry.npmjs.org/
In my Github Action how can I properly reference the private org repo so that my test will work correctly or is there a step I'm missing?
This answer was correct and here is the sample test.yml file now:
name: Test
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x]
steps:
- uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v2
with:
node-version: ${{ matrix.node-version }}
- run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> .npmrc
- run: npm ci
- run: npm run build --if-present
- run: npm test
Github Action shows as passed:
You have to add authorization to on CI with URL + token - it's done through .npmrc file.
Create a token: npm token create --read-only
Add it to your secrets on GitHub named NPM_TOKEN
Before running npm ci create a local file with your token:
Add a step: - run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> .npmrc
Everything else stays as it is.

Bitbucket Pipeline: Container 'Build' exceeded memory limit

I am trying to run a pipeline for my Angular App but when it comes to the "npm run build" part it crashes, the fail reason is "Container "Build" exceeded memory limit." I tried messing around with the memory settings in the yml file, for instance adding 'size 2x'and changing the memory amount assigned to docker.
bitbucket-pipelines.yml:
image: node:14.17.0
options:
docker: true
size: 2x
pipelines:
custom:
prod-deployment:
- step:
name: Build angular app
#services:
# - docker
caches:
- node
services:
- docker
size: 2x # Double resources available for this step.
script:
- mv .npmrc_config .npmrc
- npm install --unsafe-perm
- npm install -g #angular/cli#12.2.6
- free -m
- npm run dashboard:build
- wget "censored for security"
artifacts:
- dist/**
- step:
name: Deploy artifacts using SCP to PROD
deployment: production
size: 2x # Double resources available for this step.
script:
- pipe: atlassian/scp-deploy:1.1.0
variables:
USER: $USERNAME
SERVER: $SERVER
REMOTE_PATH: 'Censored for Security'
LOCAL_PATH: 'dist/*'
dev-deployment:
- step:
name: Build angular app
#services:
# - docker
caches:
- node
services:
- docker
size: 2x # Double resources available for this step.
script:
- mv .npmrc_config .npmrc
- npm install --unsafe-perm
- npm install -g #angular/cli#12.2.6
- free -m
- npm run build
- wget 'Censored for Security'
artifacts:
- dist/**
- step:
name: Deploy artifacts using SCP to PROD
deployment: production
size: 2x # Double resources available for this step.
script:
- pipe: atlassian/scp-deploy:1.1.0
variables:
USER: $USERNAME
SERVER: $SERVER
REMOTE_PATH: 'Censored for Security'
LOCAL_PATH: 'dist/*'
definitions:
services:
docker:
memory: 4096
Console error message:
Killed
npm ERR! code ELIFECYCLE
npm ERR! errno 137
npm ERR! build: `node --max_old_space_size=6144 node_modules/#angular/cli/bin/ng build --configuration=calio && npm run `
npm ERR! Exit status 137
npm ERR!
npm ERR! Failed at the build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-10-14T08_40_46_012Z-debug.log

In a Github Action how to publish a private package to NPM that uses private dependencies?

Trying to figure out how in a Github organization using a private org's dependency (this case a private NPM package) and publish a new private package with a Github Action but it errors in Actions:
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/#wilson%monday - Not found
npm ERR! 404
npm ERR! 404 '#wilson/monday#latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 It was specified as a dependency of 'tuesday'
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
My npm.yml file:
name: npm
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
with:
node-version: '12.x'
registry-url: 'https://registry.npmjs.org'
- run: npm install
- run: npm ci --ignore-scripts
- run: npm run build --if-present
- run: npm publish
env:
CI: true
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
I've also tried changing registry-url to:
registry-url: 'https://npm.pkg.github.com'
package.json:
"name": "#wilson/tuesday",
"version": "1.3.7"
"publishConfig": {
"access": "restricted",
"registry": "https://npm.pkg.github.com/wilson/"
},
"dependencies": {
"#wilson/monday": "latest",
},
Closest question I could find pertaining to this: "How can I publish a private github package with github actions inside a private organization repo?".
Based on this answer I'm assuming I do not need an .npmrc in my repository.
Further research on the topic:
Install private github package from package.json on Github Actions
Github Actions workflow (private repo) hangs when trying to publish to packages
How to install npm pckage from private git repoistory using a token in github actions
Github actions, 401 unauthorized when installing a Github Package with npm or yarn
In my Github Action how can I publish a private package to NPM that uses a private dependency?

Resources