用于在GitHub actions workflow.yml文件中扁平化include语句的工具。
项目描述
:warning: 此项目大部分已弃用。
actions-includes
允许在另一个操作内部包含一个操作(通过预处理YAML文件)。
在您的操作步骤中使用uses
或run
代替,使用关键词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。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分布
构建分布
哈希值 for actions-includes-0.0.post140-py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3b2e06f524b3d89318894cee725eb3a0e272fbf24f0a1511f8a2455116a81ce6 |
|
MD5 | 99cc2c957758b3f6b853bc02a295a7ea |
|
BLAKE2b-256 | 7d47387a737967c37989c085fb9fc2830ceb5156e5585c6ff06f16889fd0a79a |