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?
CodePudding user response:
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
CodePudding user response:
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/