New GitHub actions run in empty folders

偶尔善良 提交于 2019-12-24 00:46:25

问题


I am working with new GitHub actions, idea of a workflow below is to run when pr is opened or synchronised, it should first check out and install dependencies and afterwards run few yarn scripts

name: PR to Master
on: 
  pull_request:
    branches:
    - master
jobs:
  # Synchronize or Opened
  synchronized_or_opened:
    name: Synchronize or Opened
    runs-on: ubuntu-latest
    steps:
    - uses: actions/bin/filter@master
      with:
        args: action 'opened|synchronize'
  # Add Labels
  add_labels:
    name: Add Labels
    runs-on: ubuntu-latest
    steps:
    - uses: actions/labeler@v2
      with:
        repo-token: ${{ secrets.GITHUB_TOKEN }}
    needs: synchronized_or_opened
  # Checkout
  checkout:
    name: Checkout
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    needs: synchronized_or_opened
  # Install Dependencies
  install_dependencies:
    name: Install Dependencies
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [10.x]
    steps:
    - run: yarn dep:install-npm
    needs: checkout
  # Typecheck
  typecheck:
    name: Typecheck
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [10.x]
    steps:
    - run: yarn typecheck
    needs: install_dependencies
  # Prettier
  prettier:
    name: Prettier
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [10.x]
    steps:
    - run: yarn prettier
    needs: install_dependencies
  # ESLint
  eslint:
    name: ESlint
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [10.x]
    steps:
    - run: yarn eslint
    needs: install_dependencies
  # Danger
  danger:
    name: Danger
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [10.x]
    steps:
    - run: yarn danger
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    needs: install_dependencies

At the moment it successfully gets to a checkout stage, but once Install job is ran I get following error

error Couldn't find a package.json file in "/home/runner/work/myRepo/myRepo"

Judging by this checkout either failed or I am in a wrong folder?


回答1:


As mentioned in the Workflow syntax docs:

Each job runs in a fresh instance of the virtual environment specified by runs-on.

From what I can see here, you're doing the checkout step in a completely separate job from others. Doing it that way it does not affect other jobs in any way. It should actually be defined inside those jobs where your npm CLI commands are executed.

Here's an example of how it would look like in one of your jobs:

jobs:
  # (...) Other jobs
  # Install Dependencies
  install_dependencies:
    name: Install Dependencies
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [10.x]
    steps:
    - uses: actions/checkout@master
    - run: yarn dep:install-npm
    needs: checkout
  # (...) Other jobs

There are some general examples in GitHub starter workflow templates.



来源:https://stackoverflow.com/questions/57509118/new-github-actions-run-in-empty-folders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!