Github actions: Unable to install private GPR npm package - node.js

I've been having some issues installing a scoped package that that was published to GPR
See below for my actions file
name: run unit and coverage tests
on: [push]
jobs:
build:
runs-on: macos-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout#v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://npm.pkg.github.com/'
scope: '#OWNER'
- name: Authenticate with GitHub package registry
run: echo "//npm.pkg.github.com:_authToken=${{ secrets.PRIVATE_ACCESS_TOKEN }}" > ~/.npmrc
- name: npm install, build, and test
run: |
npm ci
npm run test:unit
npm run lint
npm run test:e2e -- --headless
env:
CI: true
my .npmrc file is as follows:
#discoveryedu:registry=https://npm.pkg.github.com/
my private access token has read:packages, write:packages, and repo privileges.
I'm getting the following error in actions:
npm ERR! code E401
npm ERR! 401 Unauthorized - GET https://npm.pkg.github.com/download/#owner/repo/version/hash
i've subbed the owner, repo, and version names for privacy.

Related

Error deploying a nextJS app on github actions

I'm trying to deploy my nextJS app on GitHub pages. I'm getting an error at the deploy stage.
My node.js.yml file contains the following:
name: Node.js CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.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: npm ci
- run: npm run build
- run: npm run export
- run: touch ./out/.nojekyll
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action#v4.2.5
with:
branch: gh-pages # The branch the action should deploy to.
folder: out # The folder the action should deploy.
The error code there I get while deploying my repository on another branch is the following :
remote: Permission to 0xWerz/0xwerz.github.io.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/0xWerz/0xwerz.github.io.git/': The requested URL returned error: 403
Running post deployment cleanup jobs… 🗑️
/usr/bin/git checkout -B github-pages-deploy-action/tpuzb7jkb
Reset branch 'github-pages-deploy-action/tpuzb7jkb'
/usr/bin/chmod -R 777 github-pages-deploy-action-temp-deployment-folder
/usr/bin/git worktree remove github-pages-deploy-action-temp-deployment-folder --force
Error: The deploy step encountered an error: The process '/usr/bin/git' failed with exit code 128 ❌
Notice: Deployment failed! ❌
The deploy action needs write access to your repository.
Or upgrade to a newer version of the action, i.e. 4.3.3

Cache dependencies in GitHub Actions on Windows

I am having a Github action which runs on Windows OS. Then, for caching the dependencies, I use the actions/cache#v2. But, it is not working as expected. When I saw the debug logs, the size of the cache is only about 30 B.
Here is the code I am using:
name: Build
on: push
jobs:
build_on_win:
runs-on: windows-latest
if: "!contains(github.event.head_commit.message, 'skip-publish')"
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#master
with:
node-version: 15
- name: Cache NPM dependencies
uses: actions/cache#v2
with:
path: ~/.npm
key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-npm-cache-
- name: install dependencies
run: npm install
rest of the code..
Any help is greatly appreciated !
Caching package dependencies is a feature that is already available in the actions/setup-node#v2. You don't have to configure actions/cache#v2 and instead of that what you can do is use the setup-node#v2 action like below and you just have to add cache: 'npm' and it will automatically detect and will cache the dependencies.
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
with:
node-version: '14'
cache: 'npm'
- run: npm install
- run: npm test
If you have monorepo then you can also define the path
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v2
with:
node-version: '14'
cache: 'npm'
cache-dependency-path: subdir/package-lock.json
- run: npm install
- run: npm test
You can read more about it in Caching packages dependencies.

Github actions caching for Node.js application is not working

I'm working on configuration of CI/CD in github and faced a problem with caching of dependencies.
My github actions lint config for my Node.js app attached.
As you can see I have additional step called build which is used to cache dependencies using actions/cache#v2. Then on eslint and Prettier steps I extract cached data using restore-keys.
The script fails on eslint step with error:
sh: 1: eslint: not found
I have eslint is my devDependencies section in package.json.
name: test
on: [push]
jobs:
build:
name: Build
runs-on: ubuntu-latest
container:
image: node:14.17.0-stretch-slim
steps:
- uses: actions/checkout#v2
- name: Cache dependencies
uses: actions/cache#v2
with:
path: ~/.npm
key: ${{ runner.OS }}-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-cache-
- name: Install dependencies
run: npm ci --ignore-scripts
eslint:
needs: build
name: ESLint
runs-on: ubuntu-latest
container:
image: node:14.17.0-stretch-slim
steps:
- uses: actions/checkout#v2
- name: Cache dependencies
uses: actions/cache#v2
with:
path: ~/.npm
key: ${{ runner.OS }}-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-cache-
- name: Lint source code with ESLint
run: npm run lint
prettier:
needs: build
name: Prettier
runs-on: ubuntu-latest
container:
image: node:14.17.0-stretch-slim
steps:
- uses: actions/checkout#v2
- name: Cache dependencies
uses: actions/cache#v2
with:
path: ~/.npm
key: ${{ runner.OS }}-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-cache-
- name: Lint source code with Prettier
run: npm run check:format
The problem was that I didn't run dependencies installation on eslint and prettier steps. It still needs to be done to create node_modules.

Azure Web application deployment successful, but does not update the web application

Previously I was having an error with the deployment of my React application on Web Service Linux on Azure. This problem was solved in the previous post I did, follow the link:
My Azure Web Application on Linux is not working. The error message on azure logs "react-scripts: not found" and github "npm ERR! code ELIFECYCLE ”.
Now I am having another problem which consists of the following:
After deploying to the Azure platform (I'm using the github option for deployment) and receiving a successful deployment notification, upon entering my github repository, I received the error
"npm ERR! Code ELIFECYCLE" (follow the link to view the entire log: https://mega.nz/folder/eth0WSiL#pGvXl2yShQfUrNELCKD3cA). Upon entering the application and testing it I noticed that the deployment really did not work.
An important point worth mentioning that in the previous problem the solution passed by #JasonPan worked, but when we tested it I still used the Azure classic
deployment center, which was removed a few days ago and after trying to use the current deployment center I came across this error.
I managed to solve the problem. I needed to do two things within my .yml file, they were:
add a CI: false and remove the npm run test
Here is the code:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up Node.js version
uses: actions/setup-node#v1
with:
node-version: '14.x'
- name: npm install, build
run: |
npm install
npm run build --if-present
- name: Upload artifact for deployment job
uses: actions/upload-artifact#v2
with:
name: node-app
path: .
deploy:
runs-on: ubuntu-latest
needs: build
environment:
CI: false
name: 'production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
The .yml file before it was changed:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up Node.js version
uses: actions/setup-node#v1
with:
node-version: '14.x'
- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm run test --if-present
- name: Upload artifact for deployment job
uses: actions/upload-artifact#v2
with:
name: node-app
path: .
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

Github Actions Organisation node deployment to github pages

I have been trying to deploy a create-react-app using GitHub actions which deploys the React application to gh-pages and I get the following error when trying to deploy: -
Find out more about deployment here:
bit.ly/CRA-deploy
Cloning into '/home/runner/work/some/some/node_modules/.cache/gh-pages/github.com!***!some.git'...
remote: Repository not found.
fatal: repository 'https://github.com/***/some.git/' not found
Error: The operation was canceled.
I have the following node.js.yml
name: MasterDeployCI
on:
push:
branches:
- production
- gh-pages
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [8.x, 10.x, 12.x]
steps:
- uses: actions/checkout#v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Packages
run: CI=false npm install
- name: Deploy to GH Pages
run: |
git config --global user.email ${{secrets.EMAIL}}
git config --global user.name ${{secrets.USERNAME}}
git remote set-url origin https://${{secrets.SECRET}}#github.com/${{secrets.USERNAME}}/some.git
CI=false npm run deploy
I have tried looking through the documentation and google but have been unable to find a solution.
https://github.com/Saharadigital/sahara-digital/blob/develop/.github/workflows/node.js.yml#L28
It seems secrets.USERNAME is not exists on repositories secret page. Did you checked?
https://github.com/Saharadigital/sahara-digital/runs/1311779817#step:5:4 this is also shows the same.

Resources