跳转到主要内容

用于在GitHub actions workflow.yml文件中扁平化include语句的工具。

项目描述

:warning: 此项目大部分已弃用。

您可能更愿意使用组合操作可重用工作流



actions-includes

License GitHub issues PyPI PyPI - Python Version PyPI - Downloads

允许在另一个操作内部包含一个操作(通过预处理YAML文件)。

在您的操作步骤中使用usesrun代替,使用关键词includes

一旦您使用includes参数,可以使用此工具扩展工作流

# python -m actions_include <input-workflow-with-includes> <output-workflow-flattened>

python -m actions_includes ./.github/workflows-src/workflow-a.yml ./.github/workflows/workflow-a.yml

使用docker的用法

docker container run --rm -it -v $(pwd):/github/workspace --entrypoint="" ghcr.io/mithro/actions-includes/image:main python -m actions_includes ./.github/workflows-src/workflow-a.yml ./.github/workflows/workflow-a.yml

includes: 步骤

steps:
- name: Other step
  run: |
    command

- includes: {action-name}
  with:
    {inputs}

- name: Other step
  run: |
    command

{action-name}遵循与标准GitHub操作uses相同的语法,引用的操作应类似于一个GitHub "组合操作"除了runs.using应该使用includes

例如;

  • {owner}/{repo}@{ref} - 在github.com/{owner}/{repo}中的公共操作
  • {owner}/{repo}/{path}@{ref} - 在github.com/{owner}/{repo}{path}下的公共操作。
  • ./{path} - 在本地{path}下的本地操作,即./.github/actions/{action-name}

因为它只适用于引用组合操作,所以不支持docker://形式。

由于您经常需要包含本地操作,actions-includes 扩展了 {action-name} 语法,使其也支持

  • /{name} - 位于 ./.github/includes/actions/{name} 下的本地操作。

这就是组合操作应该工作的样子。

includes-script

您可以使用 includes-script 步骤在 workflow.yml 文件中包含脚本(例如,Python 或 shell 脚本)。

示例脚本文件:script.py

print('Hello world')

要包含脚本,请在 workflow.yml 中的 includes-script 操作中引用它,如下所示

steps:
- name: Other step
  run: |
    command

- name: Hello
  includes-script: script.py

- name: Other step
  run: |
    command

当使用 python -m actions_includes.py workflow.in.yml workflow.out.yml 运行 workflow.yml 时,生成的 workflow.out.yml 看起来是这样的

steps:
- name: Other step
  run: |
    command

- name: Hello
  shell: python
  run: |
    print('Hello world')

- name: Other step
  run: |
    command

从文件扩展名推断出 shell 参数,但可以通过手动设置 shell 参数来使用自定义 shell。

使用 pre-commit 钩子

当您使用 actions-includes 时,可能需要将 pre-commit 钩子(见 https://git-scm.cn/docs/githooks)添加到您的项目中,以便在它们到达 GitHub 之前始终预处理工作流程文件。

使用 git 钩子包

有多个包(特别是 pre-commit;见 https://pre-commit.git-scm.cn/)支持添加 pre-commit 钩子。

在使用 pre-commit 包的情况下,您可以将以下条目添加到您的 pre-commit-config.yaml 文件中

- repo: local
  hooks:
  - id: preprocess-workflows
    name: Preprocess workflow.yml
    entry: python -m actions_includes.py workflow.in.yml workflow.out.yml
    language: system
    always-run: true

不使用 git 钩子包

或者,为了在不安装其他包的情况下添加 pre-commit 钩子,您可以直接创建或修改 .git/hooks/pre-commit(相对于项目根目录)。一个示例文件通常位于 .git/hooks/pre-commit.sample

pre-commit 钩子应运行必要的命令以预处理您的工作流程。因此,您的 .git/hooks/pre-commit 文件可能看起来像这样

#!/bin/bash

python -m actions_includes.py workflow.in.yml workflow.out.yml || {
    echo "Failed to preprocess workflow file."""
}

要跟踪此脚本在源代码管理中的状态,您必须将其放在项目中不忽略的文件中,然后在项目设置过程中将其复制到 .git/hooks/pre-commit。有关使用设置脚本(setup.sh)执行此操作的项目的示例,请参阅 https://github.com/ModularHistory/modularhistory

项目详情


发布历史 发布通知 | RSS 源

下载文件

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

源分布

actions-includes-0.0.post140.tar.gz (39.3 kB 查看哈希值)

上传时间:

构建分布

actions_includes-0.0.post140-py3.9.egg (57.8 kB 查看哈希值)

上传时间:

actions_includes-0.0.post140-py3.8.egg (57.8 kB 查看哈希值)

上传时间:

actions_includes-0.0.post140-py3-none-any.whl (31.3 kB 查看哈希值)

上传时间: Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面