Github CI/CD pipeline crashes with webpack - github

I'm trying to learn how CI/CD pipelines work.
I decided to use it with my portfolio page which should re-run itself on every push.
Here is my yaml config:
name: Build Bundle for Github Pages
on:
push:
branches:
- source
env:
NODE_ENV: production
PUBLIC_URL: http://crrmacarse.github.io/
GA_TRACKING_CODE: ${{ secrets.GA_TRACKING_CODE }}
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v1
with:
persist-credentials: false
- name: Build
run: |
npm install
npm run prod:pipeline
npm run sitemap
cp dist/index.html dist/404.html
cp google21029c74dc702d92.html dist/
cp robots.txt dist/
- name: Deploy
uses: JamesIves/github-pages-deploy-action#releases/v3
with:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
BRANCH: source
FOLDER: dist
Here is the error:
Source code for the webpack config:
https://github.com/crrmacarse/crrmacarse.github.io/blob/source/compiler/production.pipeline.js

If the error message is cannot find module 'html-webpack-plugin', you could try, for testing, to install it.
See survivejs/webpack-book issue 100 as an example:
The solution was to run npm i html-webpack-plugin --save-dev before building with webpack
The OP has fixed the GitHub Action workflow with crrmacarse/crrmacarse.github.io commit 8a4397b
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2.0.0
- name: Use node 12
uses: actions/setup-node#v1
with:
node-version: 12
registry-url: https://registry.npmjs.org
- name: install
run: npm install
- name: lint
run: npm run sitemap
- name: build
run: npm run prod
- name: copy
run: npm run copy
Then the module html-webpack-plugin is properly installed and available, as seen in this Actions CI run.

Use npm install before build your project which installs your npm library on docker where your project will be built.
Note: Don't forget to define html-webpack-plugin on packge.json file

Related

I use github action and vercel to deploy my project(vite+react+pnpm) to vercel, action said error: "Error: spawn pnpm ENOENT"

when I push my github project, the github action was executed, but it failed, the error message from the action is below:
Run vercel build --prod --token=***
Vercel CLI 28.10.3
Detected `pnpm-lock.yaml` generated by pnpm 7...
Installing dependencies...
Error: spawn pnpm ENOENT
Error: Process completed with exit code 1.
this is my action yml settings:
name: Vercel Deployment
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
push:
branches:
- master
jobs:
Deploy-Production:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- uses: actions/setup-node#v3
with:
node-version: 18.12.1
- name: Install Vercel CLI
run: npm install --global vercel#latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
I got this same error too, but I fixed it by
install pnpm first
install the Vercel CLI via pnpm add --global vercel#latest:
jobs:
deploy-production:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v3
- name: Install Node.js
uses: actions/setup-node#v3
with:
node-version: 18
- uses: pnpm/action-setup#v2
name: Install pnpm
id: pnpm-install
with:
version: 7
run_install: false
- name: Install Vercel CLI
run: pnpm add --global vercel#latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}

PNPM Github actions flow

I just moved my project from npm and lerna to pnpm but now when using GitHub actions I get the following error
"line 1: pnpm: command not found"
can someone suggest how the .yml file should be, I've posted the current version below?
name: Lint & Unit Test
on: [pull_request]
jobs:
run-linters:
name: Run linter and Unit tests
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout#v3
- name: ACTIONS_ALLOW_UNSECURE_COMMANDS
run: echo 'ACTIONS_ALLOW_UNSECURE_COMMANDS=true' >> $GITHUB_ENV
- name: Set up Node.js
uses: actions/setup-node#v3
with:
node-version: 16.18.1
- name: Portal Install Node.js dependencies
working-directory: ./portals
run: |
pnpm install
- name: Portals Lint & tests
working-directory: ./portals
run: |
cat .env.example > .env
pnpm run build:tailwind
pnpm run lint
pnpm test
- name: Services Install Node.js dependencies
working-directory: ./services
run: |
pnpm install
- name: Services Lint & tests
working-directory: ./services
run: |
pnpm run lint
pnpm test
You might need to use first the pnpm/action-setup action, in order to install pnpm.
on:
- push
- pull_request
jobs:
install:
runs-on: ubuntu-latest
steps:
- uses: pnpm/action-setup#v2
with:
version: 6.0.2

Where are the repo files in a working-directory context?

I have a repo for a simple file consisting on a front directory (TS, Vue.js, Quasar) and a back one. The skeleton of the project is
infinote/
├─ front/
│ ├─ package.json
│ ├─ src/
├─ back/
├─ .git/
I am trying to build the front through the following job:
jobs:
front:
runs-on: ubuntu-latest
env:
working-directory: ./front
steps:
- uses: actions/checkout#v2
with:
ref: master
- uses: actions/setup-node#v2
with:
node-version: '14'
- run: npm install
- run: npm install -g #quasar/cli
- run: quasar build
- uses: actions/upload-artifact#v2
with:
name: front
path: dist/spa
This fails because npm install cannot find anything to install:
Run npm install
npm install
shell: /usr/bin/bash -e {0}
env:
working-directory: ./front
npm WARN saveError ENOENT: no such file or directory, open '/home/runner/work/infinote/infinote/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/runner/work/infinote/infinote/package.json'
npm WARN infinote No description
npm WARN infinote No repository field.
npm WARN infinote No README data
npm WARN infinote No license field.
up to date in 0.24s
found 0 vulnerabilities
I suppose that this is because package.json (and the rest of the project) is somewhere else. Where should I expect to find it?
What you want to achieve (to use a working-directory for an entire job) can be done by using ${{env.working-directory}} with the run: npm install command, as explained in this github community answer.
Without informing the working-directory with the step, the command will be executed at the repository root (where there is no package.json file). More information about this syntax can be found here.
Your workflow should look like this:
jobs:
front:
runs-on: ubuntu-latest
env:
working-directory: ./front
steps:
- uses: actions/checkout#v2
with:
ref: master
- uses: actions/setup-node#v2
with:
node-version: '14'
- run: npm install
working-directory: ${{env.working-directory}}
- run: npm install -g #quasar/cli
working-directory: ${{env.working-directory}}
- run: quasar build
working-directory: ${{env.working-directory}} #not sure if this one is necessary
- uses: actions/upload-artifact#v2
with:
name: front
path: dist/spa
The working directory should be set for the whole job via an entry in defaults:
jobs:
front:
defaults:
run:
working-directory: ./front
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
with:
ref: master
- uses: actions/setup-node#v2
with:
node-version: '14'
- run: npm install
- run: npm install -g #quasar/cli
- run: quasar build
- run: ls -lR dist
- uses: actions/upload-artifact#v2
with:
name: front
path: ./dist/spa/

gh-pages deployment issue, job fails on deploy. The directory you're trying to deploy ... doesn't exist

gh-pages deployment fails with next error: My repository failed job
Checking configuration and starting deployment… 🚦
Error: The directory you're trying to deploy named /home/runner/work/azure-flask-react/azure-flask-react/dist doesn't exist. Please double check the path and any prerequisite build scripts and try again. ❗
Deployment failed! ❌
I'm trying to deploy ReactApp at Github and besides deploy Python-Flask backend hosted at Azure and back-app has its automatically generated job yml.
But for front-app I followed this answer and manually added second job in yml because I need to provide env.variables.
My backend deployment succeeds but front-app constantly fails because of duplicated path
/home/runner/work/azure-flask-react/azure-flask-react/dist
Here is my yml and package.json but there is no any extra mentioning of that directory...
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy Python app to Azure Web App - first-py-app
on:
push:
branches:
- main
workflow_dispatch:
jobs:
front-build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v1
- name: Build
run: |
npm --prefix front-app install
npm --prefix front-app run-script build
env:
REACT_DEV_SERVER_URL: ${{ secrets.REACT_DEV_SERVER_URL }},
REACT_DEV_FRONT_APP_URL: ${{ secrets.REACT_DEV_FRONT_APP_URL }}
- name: Deploy
uses: JamesIves/github-pages-deploy-action#releases/v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN_KEY }}
BRANCH: gh-pages
FOLDER: dist
back-build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#master
- name: Set up Python version
uses: actions/setup-python#v1
with:
python-version: '3.8'
- name: Build using AppService-Build
uses: azure/appservice-build#v2
with:
platform: python
platform-version: '3.8'
- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy#v2
with:
app-name: 'first-py-app'
slot-name: 'production'
publish-profile: ${{ secrets.AzureAppService_PublishProfile_7edcdecca83a4354a87943f94bb32fca }}
{
...
"homepage": "https://nikonov91-dev.github.io/azure-flask-react",
"scripts": {
...
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
}
and my file structure
azure-proj
|-front-app (containing reactjs)
|-package.json
|-node_modules
|-src
|-app.py (python-flask application which deploys successfully)
I misunderstood the issue message, the problem was not duplicating the problem was the missed inner path passed in FOLDER in gh-pages YML settings
There was a hint in BUILD step
And one more thing: do not forget to get and add to GH your personal-access-token

Running actions in another directory

I've just started exploring Github actions however I've found myself placing a command in multiple places.
I have a PHP project where the composer.json is not in the root, my structure looks like:
my-project:
readme.md
app:
composer.json
Obviously there is more to it and there is a reason why, but my composer.json sits in a subdirectory called 'app'. As a result in my workflow, I have to cd into that folder every time to run a command:
name: CI
on: [push]
jobs:
phpunit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Setup Symfony
run: |
cd app
cp .env.dev .env
- name: Install Composer Dependencies
run: |
cd app
composer install --prefer-dist
- name: Run Tests
run: |
cd app
php bin/phpunit
How can I remove the cd app in every stage?
Update: It's now possible to set a working-directory default for a job. See this answer.
There is an option to set a working-directory on a step, but not for multiple steps or a whole job. I'm fairly sure this option only works for script steps, not action steps with uses.
https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Using working-directory, your workflow would look like this. It's still quite verbose but maybe a bit cleaner.
name: CI
on: [push]
jobs:
phpunit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Setup Symfony
working-directory: ./app
run: cp .env.dev .env
- name: Install Composer Dependencies
working-directory: ./app
run: composer install --prefer-dist
- name: Run Tests
working-directory: ./app
run: php bin/phpunit
Alternatively, you can run it all in one step so that you only need to specify working-directory once.
name: CI
on: [push]
jobs:
phpunit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Setup and run tests
working-directory: ./app
run: |
cp .env.dev .env
composer install --prefer-dist
php bin/phpunit
You can now add a default working directory for all steps in a job: docs
For the example here, this would be:
name: CI
on: [push]
jobs:
phpunit:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./app
steps:
- uses: actions/checkout#v1
- name: Setup Symfony
run: .env.dev .env
- name: Install Composer Dependencies
run: composer install --prefer-dist
- name: Run Tests
run: php bin/phpunit
Caveat: this only applies to run steps; eg you'll still need to add the subdirectory to with parameters of uses steps, if required.
Hope this will help somebody
name: CI
on:
...
defaults:
run:
working-directory: ./app
jobs:
...