使用 self-repository 语法引用同一仓库中的 Actions
英文标题:Reference same-repository actions with self-repository syntax
GitHub Actions 现支持通过新的 self-repository 语法引用位于同一仓库中的 Action 或可复用工作流。以 `$/` 开头的 `uses:` 值会解析到当前正在运行工作流对应的精确提交,无需执行 checkout。该能力可避免依赖 `./` 路径和 checkout,或手动硬编码版本所带来的维护负担,并保持内部引用与调用方固定的完整提交 SHA 一致。该功能已在 github.com 提供,要求 GitHub Actions runner 版本为 2.336.0 或更高。
126.6 KB
中文
现在,你可以使用新的 self-repository 语法,引用位于同一仓库中的 Action 或可复用工作流。以 $/ 开头的 uses: 值会解析为当前工作流自身仓库中正在运行的精确提交,无需 checkout。该语法适用于所有支持工作区相对路径 ./ 语法的位置,包括工作流步骤、组合 Action 步骤、嵌套组合以及可复用工作流调用。
此前,引用自己仓库中定义的 Action,意味着必须依赖 ./ 和 checkout,或者硬编码某个版本。这不仅增加维护负担,也会在不易察觉的情况下削弱提交 SHA 固定(pinning)的作用。通过 self-repository 引用,同级 Action 和工作流会自动匹配当前正在运行的 ref;因此,即使调用方固定到完整长度的提交 SHA,内部引用也能保持一致。这也使工作流能够采用要求 Action 固定到完整长度提交 SHA 的企业策略,同时调用其自身的 Action。
self-repository 引用现已成为在同一仓库内组合 Action 和可复用工作流的推荐方式。该功能已在 github.com 上可用,并要求 GitHub Actions runner 版本为 2.336.0 或更高。
如需了解更多信息,请参阅查找和自定义 Action 的文档,或前往 GitHub Community 参与讨论。
English / 原文
You can now reference an action or reusable workflow that lives in the same repository using the new self-repository syntax. A uses: value that starts with $/ resolves to your workflow’s own repository at the exact commit that is running, with no checkout required. It works everywhere the workspace-relative ./ syntax works, including workflow steps, composite action steps, nested composition, and reusable workflow calls.
Before this, referencing an action defined in your own repository meant either relying on ./ and a checkout, or hardcoding a version. This was a maintenance burden and quietly defeated commit SHA pinning. With self-repository references, sibling actions and workflows automatically match the ref you are already running, so your internal references stay consistent even when callers pin to a full-length commit SHA. This also makes it possible to adopt the enterprise policy that requires actions to be pinned to a full-length commit SHA for workflows that call their own actions.
Self-repository references are now the recommended way to compose actions and reusable workflows within a repository. They are available on github.com. This feature requires the GitHub Actions runner to be on version 2.336.0 or newer.
Learn more by checking out our docs about finding and customizing actions, or join the discussion within GitHub Community.