在派生请求中通过派生请求在代码上运行GitHub Action

问题描述

我在GitHub上有一个原始存储库,并且创建了一个我正在开发的本地fork。我有一个运行Bandit安全检查的GitHub Action,但是当我推送更改并从fork中的分支创建一个Pull请求时,Bandit测试将在源仓库中当前使用的代码上运行,而不是在公关。

如何在Pull Request内的代码上运行GitHub Action Workflow?

仅供参考:这是yml文件中当前的“ on”语句:

name: Security scan
on:
  push:
    branches:
      - master
  pull_request_target:
    branches: [main,dev]

解决方法

我使用this blog post为我的一个存储库设置了github操作。检查一下,可能会有所帮助。另外阅读documentation from github可能会有帮助。

关于您的特定问题,我认为您应该删除docker login -u <user> -p <pass> fred.foo.bar:8883部分并执行以下操作:

pdfjam --nup 1x4,landscape input.pdf
,

[...]我们添加了一个新的pull_request_target事件,它的行为与具有相同过滤器和有效负载的pull_request事件几乎相同。但是,该事件不是针对合并提交中的工作流和代码运行,而是针对提取请求的基础上的工作流和代码运行。

来源:https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/

您仍然可以通过以下步骤从pull请求中检出代码:

- uses: actions/checkout@v2
  with:
    ref: ${{github.event.pull_request.head.ref}}
    repository: ${{github.event.pull_request.head.repo.full_name}}

来源:https://github.community/t/running-code-from-forks-with-pull-request-target/126688/6

,

您应该改用pull_request触发器。如果您的公关工作流程需要pull_request_target,可以更secrets有目的地和安全地使用https://securitylab.github.com/research/github-actions-preventing-pwn-requests

,

在推送或拉取请求事件上触发工作流

使用 pull_request

name: CI
on: [push,pull_request]
jobs:
  python-tests:
    runs-on: ubuntu-latest

    steps:
      ...