跳转到主要内容

一个用于管理更改之间依赖关系的Python库。

项目描述

depends-on-action

GitHub操作,用于安装依赖的Pull Requests并将其配置为后续步骤使用。

概述

此操作允许您在触发工作流操作时安装Pull Request依赖项。

如果您项目分为多个仓库,并且您有必须一起测试的Pull Requests,则需要此操作。当您有在不同仓库中的库或微服务,并且需要与使用它们的程序一起测试更改时,这种情况经常发生。即使您依赖于非您自己的第三方仓库,您也可以使用此操作来测试您的PullRequests与第三方PullRequests。

它是如何工作的?此GitHub操作从主PullRequest的描述中提取所有使用Depends-On: <PR url>语法声明的PullRequests。您可以在主PullRequest的描述中添加多个Depends-On:行以拥有多个依赖项。例如,如果您依赖于org/library仓库中的PullRequest,您可以在您的PullRequest描述中添加以下行

Change to use the new library function

Depends-On: https://github.com/org/library/pull/123

如果您需要为特定的PullRequest指定子目录,请使用以下语法

Depends-On: <PR url>?subdir=<subdir path>

然后,此GitHub操作将在代码中注入所需的修改以使用其他更改。

Gerrit和Gitlab更改

也支持Gerrit和Gitlab依赖项。示例

Depends-On: https://gerrit-review.googlesource.com/c/gerrit/+/394841
Depends-On: https://gitlab.com/adblockinc/ext/adblockplus/spec/-/merge_requests/428

更改类型的检测按以下顺序进行

  1. 如果URL中包含/c/,则它是一个Gerrit更改。
  2. 如果主机名中包含gitlab,则它是一个Gitlab更改。
  3. 它是一个GitHub更改。

Gitlab凭证

如果您需要凭证来访问 Gitlab 服务器,您可以将环境变量 GITLAB_TOKENGITLAB_USER 设置为秘密。根据您服务器的配置,您可能只需要 GITLAB_TOKEN

Go 语言

对于 Go 语言的更改,操作会在 go.mod 文件中为依赖项添加 replace 指令。此操作需要在安装 Go 工具链之后进行。

Python

操作会替换 requirements.txt 文件中的条目,以进行 Python 更改,使用 -e <local change>pyproject.toml 的等效项。

JavaScript

操作会替换 package.json 文件中的条目,以进行 JavaScript 更改,使用 file:<local change>

Ansible

操作会替换 requirements.yml 文件中的条目,以进行 Ansible 集合更改。

容器

操作会自动检测是否存在容器,并在存在的情况下以兼容的方式注入更改。

启用操作

示例配置

定义 GitHub Actions 需要创建一个名为 .github/workflows 的目录在您的仓库中。在这个目录内,您创建在事件发生时处理的文件。

使用此操作的简单示例是创建一个名为 .github/workflows/pull_request.yml 的文件,其内容如下

---
name: Pull Request
on:
  pull_request:
    types: [opened, synchronize, reopened]
jobs:
  validate-tests:
    runs-on: ubuntu-latest
    steps:

      - name: Checkout code
        uses: actions/checkout@v4

      # install the toolchain for your language

      - name: Extract dependent Pull Requests
        uses: depends-on/depends-on-action@0.15.0
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
        # optional if needed for Gitlab
        env:
          GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
          GITLAB_USER: ${{ secrets.GITLAB_USER }}

      # <your usual actions here>

  check-all-dependencies-are-merged:
    runs-on: ubuntu-latest
    steps:

      - name: Check all dependent Pull Requests are merged
        uses: depends-on/depends-on-action@0.15.0
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          check-unmerged-pr: true
        # optional if needed for Gitlab
        env:
          GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
          GITLAB_USER: ${{ secrets.GITLAB_USER }}
...

如上所示,您至少需要两个管道:一个或多个用于执行常规构建和测试并注入依赖更改,以及一个用于阻止直到依赖更改合并的特定管道。

多个签出

如果您的管道正在克隆多个 git 仓库,您可能希望在这些所有目录中注入依赖项。为此,使用带空格分隔的目录名称的 extra-dirs 选项,如下所示

---
name: Pull Request
on:
  pull_request:
    types: [opened, synchronize, reopened]
jobs:
  validate-tests:
    runs-on: ubuntu-latest
    steps:

      - name: Checkout code
        uses: actions/checkout@v4

      - name: Check out an extra dir
        uses: actions/checkout@v4
        with:
          repository: org/proj
          path: proj

      # install the toolchain for your language

      - name: Extract dependent Pull Requests
        uses: depends-on/depends-on-action@0.15.0
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          extra-dirs: org/proj

      # <your usual actions here>
      ...
...

详细信息

当操作使用 check-unmerged-pr: true 设置调用时,使用阶段 1 和 2 但不使用阶段 3。在这种情况下,阶段 2 不是在磁盘上提取依赖更改,而是仅检查所有依赖更改的合并状态。

GitHub Action 外部使用

如果您想在其他 CI 管道或本地测试中使用相同的依赖项管理,您可以安装 Python 包

$ pip install depends-on

并使用 depends_on_stage1 脚本作为入口点,参数为要下载的更改的 URL

$ cd <workspace>
$ export GITHUB_TOKEN=<your token>
$ # if you need access to a private Gitlab server
$ export GITLAB_USER=<your user>
$ export GITLAB_TOKEN=<your gitlab token>
$ # Extracting a Github change and its dependencies
$ depends_on_stage1 https://github.com/depends-on/pyprog/pulls/2
$ # Extracting a Gitlab change and its dependencies
$ depends_on_stage1 https://gitlab.com/adblockinc/ext/adblockplus/spec/-/merge_requests/428
$ # Extracting a Gerrit change and its dependencies
$ depends_on_stage1 https://softwarefactory-project.io/r/c/dci-pipeline/+/29700

路线图

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源代码分发

depends-on-0.15.0.tar.gz (27.8 kB 查看哈希值)

上传时间 源代码

构建分发

depends_on-0.15.0-py3-none-any.whl (28.0 kB 查看哈希值)

上传时间 Python 3

支持