I am using a github action pipeline and am trying to run an "npm run build" to generate an artifact that will then be used for deployment and production. Right now, my application is loaded from the local /build folder containing the built production application. This folder is populated after i make my changes and manually run "npm run build." I would instead like my pipeline to build the artifact and then deploy the application from artifact in Heroku. Here is my pipeline code:
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
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 run build --if-present
- run: cd react-frontend && npm install
- run: cd react-frontend && npm run build
# - run: npm test --if-present ```
No artifact is being built at present
Related
I wonder if there is a way for actions/checkout#v3 to skip specific folders for build restoration.
For example, if my build fails to run, actions/checkout#v3 deletes dist and node_modules, consequently crashes the whole application, thus causing a bigger problem than just the npm run build failure.
Is there any method or strategy to deal with this? a cache? restore the files? how can I deal with this?
Translated with www.DeepL.com/Translator (free version)
my node.js.yml
name: Node.js CI
on:
push:
branches: [ 'main' ]
pull_request:
branches: [ 'main' ]
jobs:
build:
runs-on: self-hosted
strategy:
matrix:
node-version: [16.x]
steps:
- name: Move a last build (cached version)
run: |
mkdir ../build_cache
mv build ../build_cache
- uses: actions/checkout#v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3
with:
clean: false
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci -f
- run: npm install -f
- run: npm run build
- name: Release nome build of new version build
run: mv dist build
- run: pm2 stop fastify-backend
- run: pm2 delete fastify-backend
- run: pm2 start ./build/main/bundle.js --name fastify-backend"
- if: failure()
run: |
mv ./build_cache/build ./
- run: pm2 restart fastify-backend
I tried a copy and paste file strategy, but copying and pasting node_modules would take too much time, I would like a simpler solution to deal with this...
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
I have a nodejs project that stores images locally in the same location as the code src/uploads. The problem arises when I try to trigger the cicd pipeline using githubaction. As it just simply dumps the code from github to my repo(digital ocean droplet). Since the digital ocean droplet repo contains images that's been uploaded by the users, when the pipeline gets triggered the photos get removed as the github repository does not have those images. How do I solve this issue
yaml file for workflow
on:
push:
branches: [ dev ]
pull_request:
branches: [ dev ]
jobs:
build:
runs-on: self-hosted
strategy:
matrix:
node-version: [14.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
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 i
- run: npm run build
- run: pm2 restart project-api
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 }}
I have a Nuxt Js application on my ubuntu server. I use my terminal to enter server and run commands on my server. I can't run command "npm run build" because my VPS has low memory and build command freezes.So I decided to make build on my PC, copy built folder to VPS and then run application.
What should I write in github actions to perform those steps?
-npm run build
-copy built folder from my machine to VPS using ssh(or password, it doesn't matter) to specific folder on VPS
What I did last time and it worked for me:
name: Deployment Setup
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
job-one:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Testing VPS connection and deploy project
uses: appleboy/ssh-action#master
with:
host: 114.12.587.105
port: 1234
username: new-user
key: ${{ secrets.PRIVATE_KEY}}
uses: appleboy/ssh-action#master
script: |
cd /home/kentforth/webapps/myapp
git pull
npm install --production
quasar build
sudo service nginx restart
EDIT:
Here is my deploy.yml file:
name: 'test my project'
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
steps:
- uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- run: npm run build
Here is What I get in github actions:
It seems github actions try to find path /home/runner/work/my project name
But I do not have such directory
How can specify I the folder on my local machine where "npm run build" command should run?