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
Related
I'd like to execute my unit tests using JEST on GITLAB, but it seeem's not working.
It works on my local machine but not on GitLab.
The entire code of .gitlab-ci.yml :
image: node:16
cache:
paths:
- node_modules
install:
stage: build
script: npm ci
jest:
stage: test
script: npm run test:ci
artifacts:
when: always
reports:
junit:
- junit.xml
Package.json
"test": "jest",
"test:ci": "jest --config ./jest.config.js --ci --reporters=default --reporters=jest-junit"
Error :
npm ERR! code E401
npm ERR! Incorrect or missing password.
npm ERR! If you were trying to login, change your password, create an
npm ERR! authentication token or enable two-factor authentication then
npm ERR! that means you likely typed your password in incorrectly.
npm ERR! Please try again, or recover your password at:
npm ERR! https://www.npmjs.com/forgot
npm ERR!
npm ERR! If you were doing some other operation then your saved credentials are
npm ERR! probably out of date. To correct this please try logging in again with:
npm ERR! npm login
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-05-12T08_05_01_634Z-debug-0.log
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
I found the issue by replacing the Node version (same version in my local machine) : image: node:14.
You need to have a step to install, better to check with GitLab CI document
image: node:16
cache:
paths:
- node_modules
install:
stage: build
script: npm ci
jest:
stage: test
script: npm run test:ci
artifacts:
when: always
reports:
junit:
- junit.xml
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.
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.
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.
I tried to create a github action that build my electron app with vue and vue-cli-plugin-electron-builder,but I can't install Dependencies by npm
my folder tree like this:
| .gitignore
| babel.config.js
| LICENSE
| package-lock.json
| package.json
| README.md
| vue.config.js
| yarn.lock
|
+---public
| favicon.ico
| index.html
| test.jpg
|
\---src
| App.vue
| background.js
| main.js
| preload.js
|
+---assets
| ...
|
\---components
...
when I run the CI,I found a error that
npm ci
shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
npm ERR! The `npm ci` command can only install with an existing package-lock.json or
npm ERR! npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm#5 or
npm ERR! later to generate a package-lock.json file, then try again.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\npm\cache\_logs\2021-08-01T04_59_20_385Z-debug.log
Error: Process completed with exit code 1.
this is my blank.yml:
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
name: Build
runs-on: windows-latest
steps:
- name: Install Node.js, NPM and Yarn
uses: actions/setup-node#v1
with:
node-version: 16
- name: Install Dependencies
run: |
npm ci
- name: Electron Build
run: |
npm run electron:build --windows nsis --x64 --ia32
I tried search on bing with the key word "npm install failed in github action" but I found nothing helpful.
also,I tried using 'npm install' instead the 'npm ci', but it showed the same error message that it can't find the package.json
the 'npm install' 's error message like this:
Run npm install
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path D:\a\example\example/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open 'D:\a\example\example\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\npm\cache\_logs\2021-08-01T05_12_56_060Z-debug.log
Error: Process completed with exit code 1.
How can I solve it?
English is not my native language; please excuse typing errors.
You are not checking out your code and directly running NPM CI.
Below piece of code should do the job for you
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
name: Build
runs-on: windows-latest
steps:
- name: Checkout Code
uses: actions/checkout#v2
- name: Install Node.js, NPM and Yarn
uses: actions/setup-node#v1
with:
node-version: 16
- name: Install Dependencies
run: |
npm ci
- name: Electron Build
run: |
npm run electron:build --windows nsis --x64 --ia32