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
Related
I am trying to build a CI/CD pipeline with github actions in order to build and deploy my app to heroku. I used following YAML file. But it shows error in github action. Could anyone please help me to solve this problem. My reository is bigshopcicd.My project structure is
bigshop
|-backend
|-frontend
|-package.json
Error-
Run npm run build
sh: 1: react-scripts: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! frontend#0.1.0 build: react-scripts build
npm ERR! spawn ENOENT
bigshop#1.0.0 build /home/runner/work/bigshopcicd/bigshopcicd
cd frontend && npm run build
frontend#0.1.0 build /home/runner/work/bigshopcicd/bigshopcicd/frontend
react-scripts build
npm ERR!
npm ERR! Failed at the frontend#0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2021-12-23T08_13_25_954Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bigshop#1.0.0 build: cd frontend && npm run build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bigshop#1.0.0 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! /home/runner/.npm/_logs/2021-12-23T08_13_25_975Z-debug.log
Error: Process completed with exit code 1.
pipeline.yml-
name: Deployment pipeline
on:
push:
branches:
- main
pull_request:
branches: [main]
types: [opened, synchronize]
jobs:
simple_deployment_pipeline:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v1
with:
node-version: '12.x'
- name: npm install
run: npm install
- name: build
run: npm run build
- name: deployment
uses: akhileshns/heroku-deploy#v3.12.12
if: ${{ github.event_name == 'push' && !contains(join(github.event.commits.*.message, ' ,'), '#skip') }}
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: bigshopcicd
heroku_email: fakirsumon78#gmmail.com
healthcheck: 'https://bigshopcicd.herokuapp.com/health'
checkstring: 'ok'
rollbackonhealthcheckfailed: true
- uses: actions/checkout#v2
- name: Bump version and push tag
uses: anothrNick/github-tag-action#eca2b69f9e2c24be7decccd0f15fdb1ea5906598
if: ${{ github.event_name == 'push' && !contains(join(github.event.commits.*.message, ' ,'), '#skip') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
DEFAULT_BUMP: patch
RELEASE_BRANCHES: main
package.json file-
"scripts": {
"start": "node backend/server.js",
"dev": "set NODE_ENV=DEVELOPMENT& nodemon backend/server",
"prod": "set NODE_ENV=PRODUCTION& nodemon backend/server",
"seeder": "node backend/utils/seeder.js",
"build": "cd frontend && npm run build",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false && npm install --prefix frontend && npm run build --prefix frontend"
},
Your npm install command runs the install in your root package.json which doesn't contain react dependencies. Then the build step goes into ./frontend and tries to use those react script that were'nt fetched.
You could use npm's preinstall target to install the frontend dependencies.
Also try to see if it is possible to split the project into two different ones because this structure seem fragile and you actually loose the advantages of having a separate backend/frontend. ( plus your scripts get overly complicated )
EDIT:
Preinstall isn't specifically made for installing node modules, it is simply a step you can add to your package.json which will be run by npm before the install step, it can contain arbitrary script commands. In your case maybe try :
"scripts": {
"preinstall": "cd frontend && npm install",
"start": "node backend/server.js",
"dev": "set NODE_ENV=DEVELOPMENT& nodemon backend/server",
"prod": "set NODE_ENV=PRODUCTION& nodemon backend/server",
"seeder": "node backend/utils/seeder.js",
"build": "cd frontend && npm run build"
}
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
I am trying to get a site to deploy to Firebase using TravisCI. I keep running into an issue when the functions deploy and try to run lint. eslint doesn't seem to be there, even though I added a command to cd and npm install. I'm sure this is some kind of no-brainer. What am I missing?
Here's my .travis.yml:
language: node_js
node_js:
- 12
deploy:
provider: firebase
project: "*****"
message: "Deployed from Github by TravisCI"
token:
secure:
*******
env:
global:
secure:
*****
branches:
only:
- master
before_deploy:
- npm install -g gatsby-cli
- rm -rf node_modules/*/.git/
- npm install
- gatsby build
- cd functions && npm install --dev && cd ..
Here's the error in the Travis log:
Installing deploy dependencies
dpl.2
Preparing deploy
dpl.3
Deploying application
=== Deploying to 'covid19-reports'...
i deploying storage, firestore, functions, hosting
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions# lint /home/travis/build/amygroshek/covid19reports/functions
> eslint .
sh: 1: eslint: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! functions# lint: `eslint .`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the functions# lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /home/travis/.npm/_logs/2020-03-23T00_34_17_951Z-debug.log
Error: functions predeploy error: Command terminated with non-zero exit code1
We created a vuejs library proyect in Gitlab and created a simple pipelines that excecuted after when we pushed the commit.
We have a problem when last job execute the npm version patch (that update the patch in the project) but... it's not updated and it's doesn't work.
.gutlab-ci.yml
image: node:8.10.0-slim
cache:
paths:
- node_modules/
before_script:
- npm install
stages:
- lint
- test
- deploy
test:
stage: test
script:
- npm run peers:add && npm run test:unit
tags:
- docker
lint:
stage: lint
script:
- npm run lint
coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
publish:
stage: deploy
script:
- npm run peers:remove
- echo -e "//gitlab.com/api/v4/projects/<my-project>/packages/npm/:_authToken=${CI_NPM_TOKEN}" > ~/.npmrc
- npm login
- npm version patch
- npm publish
And package.json
[...]
"scripts": {
...
"build:dev": "npm run clean && webpack --config build/webpack.config.dev.js",
"version": "npm run build:dev && git add -A dist",
"postversion": "git push --follow-tags"
...
}
[...]
Jobs lint and test working but the publish not.
[...]
removed 4 packages in 9.428s
$ echo -e "//gitlab.com/api/v4/projects/<my-project>/packages/npm/:_authToken=${CI_NPM_TOKEN}" > ~/.npmrc
$ npm login
Username: npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/...-debug.log
ERROR: Job failed: exit code 1
We need when the Merge Request it's accepted, automatically builed library and upload to npm repository with a new version (new patch, npm version patch). It's possible?
Thx.
npm login is an interactive command so doesn't work in CI very well. Try using the package npm-login-noninteractive to pass your credentials via command line. You can install it globally in your before_script:
before_script:
- npm i -g npm-login-noninteractive
Then call it in place of npm login in your publish script.
I am trying to use react-native-web in my college project.
When I lint with ESlit in local, it will be no error. But when the code is running on the Gitlab-CI pipeline, it always show this error when doing lint:
Error: ESLint configuration in /builds/PPL2018csui/Kelas-A/Kel-5/functions/node_modules/grpc/node_modules/uuid/.eslintrc.json is invalid:
- Unexpected top-level property "installedESLint".
I already have my own .eslintrc file, but the ESlint always refer to uuid/.eslintrc.json.
This is my gitlab-ci.yml file:
image: node:8
before_script:
- npm install
cache:
paths:
- node_modules/
stages:
- test
- build
- deploy
test:
stage: test
script:
- npm install -g codecov
- npm run lint
- npm test && codecov --token=<TOKEN>
build:
stage: build
script: ./node_modules/.bin/webpack
deploy_staging:
stage: deploy
script:
- ./node_modules/.bin/webpack --config webpack.config.js
- git remote add heroku https://heroku:<TOKEN>#git.heroku.com/<MY-APP>.git
- git push -f heroku HEAD:master
environment:
name: staging
url: https://<MY-APP>.herokuapp.com/
This is the pipeline result:
Running with gitlab-runner 10.6.0-rc1 (0a9d5de9)
on docker-auto-scale 72989761
Using Docker executor with image node:8 ...
Pulling docker image node:8 ...
Using docker image <DOCKER-IMAGE> for node:8 ...
Running on <RUNNER-CONCURRENT> via <OTHER-RUNNER>...
Cloning repository...
Cloning into '/builds/PPL2018csui/Kelas-A/Kel-5'...
Checking out 4a8b0c7e as group_chat_react...
Skipping Git submodules setup
Checking cache for default...
Downloading cache.zip from <CACHE-URL>
Successfully extracted cache
$ npm install
> uglifyjs-webpack-plugin#0.4.6 postinstall /builds/PPL2018csui/Kelas-A/Kel-5/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#1.1.3 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
added 1360 packages in 34.056s
$ npm install -g codecov
/usr/local/bin/codecov -> /usr/local/lib/node_modules/codecov/bin/codecov
+ codecov#3.0.0
added 58 packages in 2.266s
$ npm run lint
> deco#0.0.1 lint /builds/PPL2018csui/Kelas-A/Kel-5
> eslint --ext .js .
ESLint configuration in /builds/PPL2018csui/Kelas-A/Kel-5/functions/node_modules/grpc/node_modules/uuid/.eslintrc.json is invalid:
- Unexpected top-level property "installedESLint".
Error: ESLint configuration in /builds/PPL2018csui/Kelas-A/Kel-5/functions/node_modules/grpc/node_modules/uuid/.eslintrc.json is invalid:
- Unexpected top-level property "installedESLint".
at validateConfigSchema (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/config/config-validator.js:221:15)
at Object.validate (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/config/config-validator.js:238:5)
at loadFromDisk (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/config/config-file.js:516:19)
at Object.load (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/config/config-file.js:559:20)
at Config.getLocalConfigHierarchy (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/config.js:227:44)
at Config.getConfigHierarchy (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/config.js:179:43)
at Config.getConfigVector (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/config.js:286:21)
at Config.getConfig (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/config.js:329:29)
at processText (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/cli-engine.js:163:33)
at processFile (/builds/PPL2018csui/Kelas-A/Kel-5/node_modules/eslint/lib/cli-engine.js:224:18)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! deco#0.0.1 lint: `eslint --ext .js .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the deco#0.0.1 lint 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/2018-03-20T06_38_47_590Z-debug.log
ERROR: Job failed: exit code 1
Is there anyone who can help me with the error?
You can remove the entry "installedESLint:true". It was a bug which put that entry on init as mentioned here