【问题标题】:How to specify working directory for github actions for monorepo如何为 monorepo 的 github 操作指定工作目录
【发布时间】:2022-01-12 14:06:15
【问题描述】:

最近我从多个存储库切换到 monorepo,我正在尝试重写我的工作流程以使用 monorepo。我想为作业指定我的子项目的路径。例如我有以下工作。

- name: Gradle Build
      uses: eskatos/gradle-command-action@v1
      with:
        arguments: build test --stacktrace --info

如何从特定的子目录运行它? (或者,如果可能,我想为文件中的所有作业指定一个基本目录)

提前谢谢你。

【问题讨论】:

    标签: github continuous-integration github-actions


    【解决方案1】:

    您可以为一个步骤或整个作业指定一个工作目录https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepsrun

    jobs:
      job1:
        runs-on: ubuntu-latest
        defaults:
          run:
            shell: bash
            working-directory: [base-directory]
    
        steps:
          - name: step1
            run: [cmd]
            working-directory: ./dir1
    
        - name: step2
            run: [cmd]
            working-directory: ./dir2
    

    你可以看看这个帖子:https://github.community/t/use-working-directory-for-entire-job/16747

    【讨论】:

    • 感谢您的回答。但是如果没有运行命令,这会起作用吗?在示例中不要使用 run 。
    • GuiFalourd 的答案相同。谢谢他:)
    【解决方案2】:

    Nicolas G. 答案是正确的并且可以工作,但正如您所解释的,您希望为文件中的所有作业指定一个工作目录defaults 字段在工作流级别也有效,避免重复

    在工作流级别

    defaults:
      run:
        working-directory: ./your_working_dir
    jobs:
      job1:
        [...]
      job2:
        [...]
    

    在工作层面

    jobs:
      job1:
        runs-on: ubuntu-latest
        defaults:
          run:
            working-directory: ./your_working_dir1
        steps:
        [...]
    
      job2:
        runs-on: ubuntu-latest
        defaults:
          run:
            working-directory: ./your_working_dir2
        steps:
        [...]
    

    您可以在Github official documentation 上了解有关defaults 字段的更多信息。

    【讨论】:

    • 感谢您的回答。但是如果没有run 命令,这会起作用吗?在示例中不要使用 run
    • 它仅适用于run 命令。 Action (uses) 通常有 inputs 以在需要时询问特定路径。例如这里对于 gradle 命令操作,它似乎是 build-root-directory 参数:github.community/t/…
    猜你喜欢
    • 2010-12-13
    • 2019-12-27
    • 2023-02-03
    • 1970-01-01
    • 2020-02-09
    • 2010-12-22
    • 1970-01-01
    • 2016-04-08
    相关资源
    最近更新 更多