如何在github中指定操作/设置节点的路径

hgb9j2n6  于 2021-10-10  发布在  Java
关注(0)|答案(1)|浏览(453)

注意:我已经看到了这两个:
如何在github操作中的特定文件夹中运行ci步骤
如何在github操作中指定节点的路径?
但我仍然无法让它工作,这就是为什么我问我如何能够设置一个工作目录 uses 指挥部。我的yaml目前如下所示:


# This workflow will build a Java project with Maven

# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven

on:
  push:
    branches: [ main, Create-.yml-file ]
  pull_request:
    branches: [ main, Create-.yml-file ]

jobs:
  javatest:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-java@v2
      with:
        java-version: '16'
        distribution: 'adopt'
    - name: Cache Maven packages
      uses: actions/cache@v2
      with:
        path: ~/.m2
        key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
        restore-keys: ${{ runner.os }}-m2
    - name: Build with Maven
      run: |
          mvn -f ./backend/pom.xml -B test
          #mvn -f ./notification/pom.xml -B test

    - name: Generate JaCoCo Badge
      uses: cicirello/jacoco-badge-generator@v2
      with:
        generate-branches-badge: true
        on-missing-report: quiet
        jacoco-csv-file: >
          -backend/target/site/jacoco/jacoco.csv

    - name: Log coverage percentage
      run: |
        echo "coverage = ${{ steps.jacoco.outputs.coverage }}"
        echo "branch coverage = ${{ steps.jacoco.outputs.branches }}"

    - name: Commit the badge (if it changed)
      run: |
        if [[ `git status --porcelain` ]]; then
          git config --global user.name 'myusername'
          git config --global user.email 'myId@users.noreply.github.com'
          git add -A
          git commit -m "Autogenerated JaCoCo coverage badge"
          git push
        fi

    - name: Upload JaCoCo coverage report
      uses: actions/upload-artifact@v2
      with:
        name: jacoco-report
        path: target/site/jacoco/

  nodejstest:
    runs-on: ubuntu-latest
    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
      working-directory: ./frontend
    - run: npm run build --if-present
      working-directory: ./frontend
    - run: npm test
      working-directory: ./frontend

错误发生在此处:

- name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v2
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'

看起来是这样的:

Run actions/setup-node@v2
/usr/local/bin/npm config get cache
/home/runner/.npm
Error: Dependencies lock file is not found in /home/runner/work/path/to/main/directory. Supported file patterns: package-lock.json,yarn.lock

我的包锁位于…/path/to/main/directory/frontend中,因此很明显找不到它,但是根据其他两个解决方案,这个代码段应该可以工作,不是吗?我还尝试将最后三个run语句组合到中,并将工作目录设置移动到不同的位置。所有这些都有不同程度的失败

hvvq6cgz

hvvq6cgz1#

您可以将节点设置和缓存分解为如下两个步骤

nodejstest:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v2
      with:
        node-version: ${{ matrix.node-version }}
    - name : Cache
      uses: actions/cache@v2
      with:
        path: "frontend/node_modules"
        key: node-modules-${{ hashFiles('frontend/package.json') }}
    - run: npm ci
      working-directory: ./frontend
    - run: npm run build --if-present
      working-directory: ./frontend
    - run: npm test
      working-directory: ./frontend

相关问题