如何在 GitHub Action 构建过程中引用我的仓库中的目录?

6

我有一些用于pytest单元测试的测试数据,我使用环境变量设置它们的位置。查看我的pytest日志,构建过程能够看到环境变量,但是它们引用的位置不存在。在GitHub Actions文档中,仓库应该位于/home/runner/Repo/。以下是我的文件夹结构。有人注意到任何明显的问题吗?

Repo/
  notebooks/
  repo/
    __init__.py
    tests/
      tests_db.hdf5
      Sample_Raw/
        ...
      __init__.py
      test_obj1.py
      test_obj2.py
    obj1.py
    obj2.py
    utils.py

构建YAML

name: build-test

on:
  push:
    branches:
      - '*' # all branches for now

jobs:
  build-and-run:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest]
        python-version: [3.8]
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
    - name: Generate coverage report
      env:
        DB_URL: /home/runner/work/Repo/repo/tests/test_db.hdf5
        RAW_FOLDER: /home/runner/work/Repo/repo/tests/Sample_Raw/
      run: |
        pip install pytest
        pip install pytest-cov
        pytest --cov=./ --cov-report=xml
    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v1
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        file: ./coverage.xml
        name: codecov-umbrella

1
尝试省略路径中的/home/runner/work/Repo部分,使用库中的相对路径 - 我认为checkout操作会自动cd到库中。如果这样可以,请告诉我,我可以将其作为答案。 - MLavrentyev
6
DB_URL: ${{ github.workspace }}/repo/tests/test_db.hdf5 等。 (翻译:DB_URL是${{ github.workspace }}/repo/tests/test_db.hdf5等的网址。) - hoefling
此外,据我所知,checkout操作使用类似于/home/runner/work/<gh-user>/<gh-repo>作为工作目录,不过可能是错误的。 - hoefling
你解决了这个问题吗? - Sam
1
@Sam 是的,hoefling的答案是有效的。 - pmdaly
正如 MLarvrentyev 所提到的,只需使用相对路径。因此,请尝试使用 ./repo/tests/test_db.hdf5。 - hui chen
1个回答

2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接