I've attempted to implement the official guide to publishing and installing a package with GitHub Actions: Authenticating to package registries with granular permissions
Fails with:
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://npm.pkg.github.com
npm ERR! need auth You need to authorize this machine using `npm adduser`
package.json
{
"name": "#charneykaye/banana",
"version": "4.0.6",
"repository": "git#github.com:charneykaye/banana",
"description": "made by artists in a new algorithmic medium",
"bin": {
"banana": "./lib/index.js"
},
"author": "Charney Kaye <charney#xj.io>",
"license": "MIT",
"scripts": {
"start": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts",
"start:windows": "nodemon --watch 'src/**/*.ts' --exec \"npx ts-node\" src/index.ts",
"create": "npm run build && npm run test",
"banana": "npx ts-node ./src/index.ts",
"test": "tsc -p . && jest --coverage --verbose --runInBand"
},
"dependencies": {
"commander": "^10.0.0",
"figlet": "^1.5.2",
"octokit": "^1.8.0"
},
"devDependencies": {
"#babel/core": "^7.20.12",
"#babel/preset-env": "^7.20.2",
"#babel/preset-typescript": "^7.18.6",
"#jest/globals": "^29.4.1",
"#types/jest": "^29.4.0",
"#types/node": "^18.11.18",
"babel-jest": "^29.4.1",
"jest": "^29.4.1",
"nodemon": "^2.0.20",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"testMatch": [
"**/__tests__/**test.ts",
"**/__tests__/**test.tsx"
]
}
}
.github/workflow/ci.yml
name: "CI Build & Publish"
on:
push:
branches:
- main
jobs:
CI:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup Node.js
uses: actions/setup-node#v3
with:
node-version: 18.14
cache: 'npm'
- name: Install npm packages
run: npm install
- name: Unit tests
run: npm test
- name: Build Banana
run: npm run banana -- --build --env prod
- uses: actions/upload-artifact#v3
with:
name: banana
path: ./build/
- name: Publish NPM package
run: npm publish
.npmrc
#charneykaye:registry=https://npm.pkg.github.com
Needed to do a connect two more dots to get the token all the way to npm publish
Replace .npmrc with
//npm.pkg.github.com/:_authToken=${NPM_CONFIG_TOKEN}
#charneykaye:registry=https://npm.pkg.github.com
always-auth=true
and the last action in .github/workflow/ci.yml with
- name: Publish NPM package
run: npm publish
env:
NPM_CONFIG_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Related
I've upgraded to Laravel 9 recently.
Here is my package.json:
{
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"#vitejs/plugin-vue": "^3.0.3",
"autoprefixer": "^10.4.8",
"axios": "^0.21",
"laravel-mix": "^6.0.6",
"laravel-vite-plugin": "^0.6.0",
"lodash": "^4.17.19",
"postcss": "^8.4.16",
"tailwindcss": "^3.1.8",
"vite": "^3.0.9"
},
"dependencies": {
"alpinejs": "^3.8.1",
"laravel-echo": "^1.11.3",
"pusher-js": "^7.0.3"
},
"name": "beastburst-website",
"description": "<p align=\"center\"><img src=\"https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg\" width=\"400\"></p>",
"version": "1.0.0",
"main": "tailwind.config.js",
"directories": {
"test": "tests"
},
"repository": {
"type": "git",
"url": "https://code.scarsgaming.net/BeastBurst/BeastBurst-Website.git"
},
"keywords": [],
"author": "",
"license": "ISC"
}
When I run npm run watch I get the following error:
npm ERR! Missing script: "watch"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/venelin/.npm/_logs/2022-08-31T11_40_11_910Z-debug-0.log
Any idea why and how can I fix that?
The default bundler for Laravel now is Vite as you can clearly see from your package.json
If you do not want to use Vite, use this guide to switch to mix
I should also mention that Vite is much faster that mix.
try npm run dev it will work like npm run watch that is because Laravel 9 now uses Vite.
I am trying to run jest for a monorepo project maintained by lerna in the github actions.
name: Run Unit Test
on:
push:
branches:
- master
- dev
pull_request:
branches:
- master
- dev
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Cache node modules
uses: actions/cache#v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Dependencies
run: npm -v && npm install
- name: Run Unit Test
run: npm run test
- name: Coveralls
uses: coverallsapp/github-action#master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
I got jest: not found error when run test in github actions.
you can see the error logs here. But when I run npm install and npm run test in my own macOs, everything works fine.
and this is my package.json of root:
{
"private": true,
"description": "a progressive micro frontend library",
"workspaces": [
"packages/*"
],
"scripts": {
"postinstall": "lerna bootstrap",
"bootstrap": "lerna bootstrap",
"clean": "lerna clean",
"test": "lerna run test --stream",
"build": "lerna run build --stream",
"commit": "git cz",
"lint": "lerna run lint --stream",
"publish": "lerna publish",
"docs": "docsify serve docs"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ObviousJs/obvious.git"
},
"author": "Philip Lau",
"license": "MIT",
"bugs": {
"url": "https://github.com/ObviousJs/obvious/issues"
},
"homepage": "https://github.com/ObviousJs/obvious#readme",
"publishConfig": {
"access": "public"
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
}
},
"devDependencies": {
"#rollup/plugin-commonjs": "20.0.0",
"#rollup/plugin-node-resolve": "13.0.4",
"#typescript-eslint/eslint-plugin": "4.31.0",
"#typescript-eslint/parser": "4.31.0",
"commitizen": "4.2.4",
"cz-conventional-changelog": "3.3.0",
"docsify-cli": "4.4.3",
"eslint": "7.32.0",
"eslint-config-standard": "16.0.3",
"eslint-plugin-import": "2.24.2",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "5.1.0",
"husky": "4.3.8",
"lerna": "4.0.0",
"rollup": "2.56.3",
"rollup-plugin-typescript2": "0.30.0"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint && npm run build && git add ./"
}
}
}
this is the package.json of sub project:
{
"name": "#obvious/core",
"version": "0.4.0",
"description": "a progressive micro front framework",
"main": "./dist/index.umd.js",
"module": "./dist/index.es.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "rollup -c rollup.config.js",
"lint": "eslint --fix --ext .ts,.js test",
"test": "jest --coverage"
},
"author": "Philip Lau",
"license": "MIT",
"dependencies": {
"#vue/reactivity": "3.2.10",
"tslib": "2.3.1"
},
"devDependencies": {
"#types/jest": "27.0.1",
"jest": "27.1.1",
"nock": "13.1.3",
"node-fetch": "2.6.2",
"ts-jest": "27.0.5",
"typescript": "4.4.3"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ObviousJs/obvious-core.git"
},
"bugs": {
"url": "https://github.com/ObviousJs/obvious-core/issues"
},
"homepage": "https://github.com/ObviousJs/obvious-core#readme"
}
my github repo address is https://github.com/ObviousJs/obvious-core.
sorry for my pool english but I really need some help (orz
I have zero knowledge about this, but for a temporary answer, what worked for me (when I had the same error with jest) was adding,
- run: lerna bootstrap --no-ci
before running my npm test command in my workflow config. Thus I ended up with a workflow like this:
on:
pull_request:
branches: [ master ]
jobs:
test_pull_request:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v1
with:
node-version: 12
# fix issue with lerna and clean installs
- run: lerna bootstrap --no-ci
- run: npm test
I finally solved this problem by setting
useWorkspaces: false
in lerna.json
the reason is that npm6.x doesn't support workspace. And the npm version of github-action runner is just v6, so the workspaces in package.json is useless, so we should set useWorkspaces in lerna.json to false
I am trying to setup Github actions to npm publish my package. But I got this error When I move on execute
My workflows/publish.yml file looks like the following:
name: publish
on:
push:
branches: [ main ]
jobs:
release:
name: publish
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout#v2.3.4
- name: Setup Node.js environment
uses: actions/setup-node#v2.2.0
with:
node-version: 14
registry-url : https://registry.nmpjs.org
- name: publish
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}}
Your package.json file is broken.
{
"name": "#sakibb019/npx-card",
"version": "1.0.0",
"description": "",
"main": "card.js",
"scripts": {
"dev": "nodemon card.js"
},
"keywords": [],
"author": "",
"repository": {
"url": "git://github.com/sakibb019/test.git"
},
"license": "ISC",
"dependencies": {
"boxen": "^5.0.1",
"chalk": "^4.1.1",
"clear": "^0.1.0",
"inquirer": "^8.1.0"
}
}
I've added the missing braces, still, you would need to find a complete package JSON file. There should be more content after "inquirer": "^8.1.
I get this error:
no such file or directory, stat 'C:\Users\nessa\VS Code\React-Django\website\frontend\build'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! frontend#1.0.0 deploy: `gh-pages -d build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the frontend#1.0.0 deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
when trying to run npm run deploy.
This is my package.json file located in my .\website\frontend
{
"name": "frontend",
"version": "1.0.0",
"private": true,
"description": "",
"main": "index.js",
"scripts": {
"start": "react-scripts start",
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"dev": "webpack --mode development --watch",
"build": "webpack --mode production"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.13.13",
"#babel/preset-env": "^7.13.12",
"#babel/preset-react": "^7.13.13",
"babel-loader": "^8.2.2",
"css-loader": "^5.2.0",
"gh-pages": "^3.1.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"style-loader": "^2.0.0",
"webpack": "^5.28.0",
"webpack-cli": "^4.6.0"
},
"dependencies": {
"#babel/plugin-proposal-class-properties": "^7.13.0",
"#material-ui/core": "^4.11.3",
"#material-ui/icons": "^4.11.2",
"#material-ui/lab": "^4.0.0-alpha.57",
"react-material-ui-carousel": "^2.2.4",
"react-router-dom": "^5.2.0",
"react-speech": "^1.0.2"
}
}
I've been running npm run dev from the same location all the time without issues. I'm trying to host my react app on Github. I tried reinstalling gh-pages in case a file didn't properly install but am having the same problems. What should I do to resolve this?
Edit: I tried to do what was said here, but still didn't work. Here's my webpack.config.js if that helps.
const path = require("path");
const webpack = require("webpack");
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, './static/frontend'),
filename: '[name].js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
optimization: {
minimize: true,
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
}),
],
}
I also changed "build": "webpack --mode production" in my package.json scripts to "build": "webpack --mode development", in order to run npm run build, but the problem still isn't fixed.
This was my error:
ENOENT: no such file or directory, stat 'C:\Users...\dist'
So I added
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
on package.json in "scripts".
And run the command npm install gh-pages --save-dev in terminal.
Finishing with npm run deploy.
After you add predeploy, deploy in script in JSON file.
run : npm run build
run : npm run deploy
I have created test for React Native application using Appium and WebdriverIO, it's working fine locally on an android emulator and on a real device, but its not working on AWS device farm.
This tutorial https://medium.com/jetclosing-engineering/react-native-device-testing-w-appium-node-and-aws-device-farm-295081129790 I followed to create a test.
Issue is
[0-0] 2020-05-06T14:01:27.360Z INFO webdriver: COMMAND findElement("accessibility id", "app-root")
[0-0] 2020-05-06T14:01:27.370Z INFO webdriver: [POST] http://127.0.0.1:4723/wd/hub/session/5a7350a3-e8c2-4c9e-b31a-347ea4defcdb/element
[0-0] 2020-05-06T14:01:27.370Z INFO webdriver: DATA { using: 'accessibility id', value: 'app-root' }
[0-0] 2020-05-06T14:01:27.378Z INFO webdriver: COMMAND findElement("accessibility id", "loginEmail")
[0-0] 2020-05-06T14:01:27.388Z INFO webdriver: [POST] http://127.0.0.1:4723/wd/hub/session/5a7350a3-e8c2-4c9e-b31a-347ea4defcdb/element
2020-05-06T14:01:27.388Z INFO webdriver: DATA { using: 'accessibility id', value: 'loginEmail' }
2020-05-06T14:01:27.390Z INFO webdriver: COMMAND findElement("accessibility id", "app-root")
2020-05-06T14:01:27.393Z INFO webdriver: [POST] http://127.0.0.1:4723/wd/hub/session/5a7350a3-e8c2-4c9e-b31a-347ea4defcdb/element
2020-05-06T14:01:27.393Z INFO webdriver: DATA { using: 'accessibility id', value: 'app-root' }
[0-0] TypeError in "Simple App testing Valid Login Test"
$(...).setValue is not a function
[0-0] 2020-05-06T14:01:27.426Z INFO webdriver: COMMAND deleteSession()
[0-0] 2020-05-06T14:01:27.426Z INFO webdriver: [DELETE] http://127.0.0.1:4723/wd/hub/session/5a7350a3-e8c2-4c9e-b31a-347ea4defcdb
[0-0] 2020-05-06T14:01:28.306Z WARN webdriver: Request failed with status 500 due to An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server. Original error: Error: socket hang up
The same issue is for waitForDisplayed $(...).waitForDisplayed is not a function
Test file
var expect = require('chai').expect;
describe('Simple App testing', () => {
it('App is loaded', async function () {
expect($("~app-root")).to.exist;
});
it('Valid Login Test', async => {
$("~app-root");
$('~loginEmail').setValue("customer11#yopmail.com");
$('~loginPassword').setValue("123456");
$("~login").click();
//$("~app-root").waitForDisplayed(11000, false);
expect(true).to.equal(true);
});
});
Package.json file
{
"name": "tests",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "npm install && npx wdio ./wdio.conf.local.js",
"package": "npm install && npm-pack-zip"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#wdio/cli": "^6.1.2",
"#wdio/local-runner": "^6.1.2",
"#wdio/mocha-framework": "^6.1.0",
"#wdio/spec-reporter": "^6.0.16",
"#wdio/sync": "^6.1.0",
"wdio-chromedriver-service": "^6.0.2",
"chromedriver": "^81.0.0",
"chai": "^4.2.0",
"webdriverio": "^6.1.2"
},
"devDependencies": {
"npm-bundle": "^3.0.3",
"npm-pack-zip": "^1.2.7"
},
"bundledDependencies": [
"#wdio/cli",
"#wdio/mocha-framework",
"#wdio/local-runner",
"#wdio/spec-reporter",
"#wdio/sync",
"webdriverio",
"chai",
"chromedriver",
"wdio-chromedriver-service"
]
}
wdio.config.js file
exports.config = {
runner: 'local',
specs: [
'./test/specs/**/*.js'
],
exclude: [
// 'path/to/excluded/files'
]
maxInstances: 1,
capabilities: [{
maxInstances: 1,
appWaitDuration: 100000,
appWaitActivity: '*'
}],
logLevel: 'info',
bail: 0,
baseUrl: 'http://localhost',
path: '/wd/hub',
waitforTimeout: 10000,
connectionRetryTimeout: 120000,
connectionRetryCount: 3,
services: ['appium'],
port: 4723,
framework: 'mocha',
reporters: ['spec'],
mochaOpts: {
ui: 'bdd',
timeout: 60000
},
}
Yml file install and test phases
phases:
install:
commands:
- npm install -g appium
- export APPIUM_VERSION=1.17.0
- avm $APPIUM_VERSION
- ln -s /usr/local/avm/versions/$APPIUM_VERSION/node_modules/.bin/appium /usr/local/avm/versions/$APPIUM_VERSION/node_modules/appium/bin/appium.js
- cd $DEVICEFARM_TEST_PACKAGE_PATH
- echo $DEVICEFARM_TEST_PACKAGE_PATH
- npm install
test:
commands:
- echo "Navigate to test source code"
- cd $DEVICEFARM_TEST_PACKAGE_PATH/node_modules/*
- echo "Start Appium Node test for Qbunk Android"
- ls
- echo $DEVICEFARM_TEST_PACKAGE_PATH
- npm install
- echo "Installing wdio"
- npm install --save webdriverio #wdio/cli
- echo "Installing chai"
- npm install --save chai
- npx wdio $DEVICEFARM_TEST_PACKAGE_PATH/wdio.conf.js --spec $DEVICEFARM_TEST_PACKAGE_PATH/test/specs/*.js
Interesting thing is that this https://aws.amazon.com/blogs/mobile/testing-mobile-apps-across-hundreds-of-real-devices-with-appium-node-js-and-aws-device-farm/ AWS tutorial I followed and write my test with wd working fine on AWS Device farm.
Kindly let me know if you need more information.
Thanks
The issue has been resolved, it's mainly related to the Yml file install and test phases.
I am now installing wdio cli and chai globally in the install phase after that I am installing required dependencies using npm install and running test's in test phase
phases:
install:
commands:
- export APPIUM_VERSION=1.16.0
- avm $APPIUM_VERSION
- ln -s /usr/local/avm/versions/$APPIUM_VERSION/node_modules/.bin/appium /usr/local/avm/versions/$APPIUM_VERSION/node_modules/appium/bin/appium.js
- ls
- echo "Installing wdio globally"
- npm install -g webdriverio #wdio/cli
- echo "Installing chai globally"
- npm install -g chai
- cd $DEVICEFARM_TEST_PACKAGE_PATH
- npm install
test:
commands:
- echo "Navigate to test source code"
- cd $DEVICEFARM_TEST_PACKAGE_PATH/node_modules/*
- npx wdio $DEVICEFARM_TEST_PACKAGE_PATH/wdio.conf.js --spec $DEVICEFARM_TEST_PACKAGE_PATH/test/specs/*.js
Also, I don't need dependencies in a zip file, so I removed bundledDependencies in package.json file, I am installing these in yml install phase.
{
"name": "tests",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "npm install && npx wdio ./wdio.conf.local.js",
"package": "npm install && npm-pack-zip"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#wdio/cli": "^6.1.9",
"#wdio/local-runner": "^6.1.2",
"#wdio/mocha-framework": "^6.1.0",
"#wdio/spec-reporter": "^6.0.16",
"#wdio/sync": "^6.1.0",
"chai": "^4.2.0",
"chromedriver": "^81.0.0",
"wdio-chromedriver-service": "^6.0.2",
"webdriverio": "^6.1.9"
},
"devDependencies": {
"npm-bundle": "^3.0.3",
"npm-pack-zip": "^1.2.7"
}
}