Github Actions 可重用工作流程访问存储库问题

发布于 2025-01-10 11:31:41 字数 775 浏览 0 评论 0原文

我将一些常见的 ci 工作移到了自己的存储库中,用于 linting、静态检查等。多个存储库将使用它来避免重复。我遇到的问题是,显然需要对调用工作流程的存储库进行检查。这是如何实现的?当执行通用工作流时,它无法访问初始存储库的内容。它只检查自身。

示例源存储库:

name: Perform Pre Build Check
on:
  push:
  workflow_dispatch:
    
jobs:
  checks:
    uses: <org>/<common-repo>/.github/workflows/checks.yml@main

常见工作流程:

name: Perform Pre-Build Checks

on:
  workflow_call:
jobs:
  formatting-check:
    name: Formatting Check
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Run linting check
      run: xxxxxx
    - name: Install cppcheck
      run: sudo apt-get -y install cppcheck
    - name: Run cppcheck
      run: xxxxx
      continue-on-error: true

I moved some common ci work into its own repo for linting, static checks etc. Multiple repos will then use this to avoid duplication. Issue I am having is, obviously the checks need to be carried out on the repo that invokes the workflow. How is this made possible? When the common workflow is executed it has no access to the contents of the initial repo. It only checks out itself.

Example source repo:

name: Perform Pre Build Check
on:
  push:
  workflow_dispatch:
    
jobs:
  checks:
    uses: <org>/<common-repo>/.github/workflows/checks.yml@main

Common workflow:

name: Perform Pre-Build Checks

on:
  workflow_call:
jobs:
  formatting-check:
    name: Formatting Check
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Run linting check
      run: xxxxxx
    - name: Install cppcheck
      run: sudo apt-get -y install cppcheck
    - name: Run cppcheck
      run: xxxxx
      continue-on-error: true

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

违心° 2025-01-17 11:31:41

这就是我最终所做的。不确定这是否是正确的方法,但它确实有效。基本上只是传递 repo &触发工作流程的当前存储库的引用名称,

示例源存储库:

name: Perform Pre Build Check
on:
  push:
  workflow_dispatch:
    
jobs:
  checks:
    uses: <org>/<common-repo>/.github/workflows/checks.yml@main
    with:
      repo-name: ${{ github.GITHUB_REPOSITORY  }}
      ref-name: ${{ github.GITHUB_REF_NAME  }}

常见工作流程:

name: Perform Pre-Build Checks
on:
  workflow_call:
    inputs:
    repo-name:
      required: true
      type: string
    ref-name:
      required: true
      type: string
jobs:
  formatting-check:
    name: Formatting Check
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
          repository: ${{inputs.repo-name}}
          ref: ${{inputs.ref-name}}
    - name: Run linting check
      run: xxxxxx
    - name: Install cppcheck
      run: sudo apt-get -y install cppcheck
    - name: Run cppcheck
      run: xxxxx
      continue-on-error: true

This is what I ended up doing. Not sure if this was right approach but it worked. Basically just passing in the repo & ref name from current repo that triggered the workflow,

Example source repo:

name: Perform Pre Build Check
on:
  push:
  workflow_dispatch:
    
jobs:
  checks:
    uses: <org>/<common-repo>/.github/workflows/checks.yml@main
    with:
      repo-name: ${{ github.GITHUB_REPOSITORY  }}
      ref-name: ${{ github.GITHUB_REF_NAME  }}

Common workflow:

name: Perform Pre-Build Checks
on:
  workflow_call:
    inputs:
    repo-name:
      required: true
      type: string
    ref-name:
      required: true
      type: string
jobs:
  formatting-check:
    name: Formatting Check
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
          repository: ${{inputs.repo-name}}
          ref: ${{inputs.ref-name}}
    - name: Run linting check
      run: xxxxxx
    - name: Install cppcheck
      run: sudo apt-get -y install cppcheck
    - name: Run cppcheck
      run: xxxxx
      continue-on-error: true
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文