github - 如何在可重用的 github 工作流程中执行远程脚本

标签 github github-actions workflow

我在一个名为 terraform-do-database 的 repo 中有这个工作流程,我正在尝试使用来自公共(public) repo foo/git-workflows/.github/的可重用工作流程workflows/tag_validation.yaml@master

name: Tag Validation

on:
  pull_request:
    branches: [master]
  push:
    branches:    
      - '*'         # matches every branch that doesn't contain a '/'
      - '*/*'       # matches every branch containing a single '/'
      - '**'        # matches every branch
      - '!master'   # excludes master
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:

  tag_check:
    uses: foo/git-workflows/.github/workflows/tag_validation.yaml@master

这是来自公共(public) git-workflows 存储库的可重用工作流文件,其中包含应在其上运行的脚本。发生的事情是工作流试图在 repo terraform-do-database

中使用脚本
name: Tag Validation

on:
  pull_request:
    branches: [master]
  workflow_call:

jobs:

  tag_check:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3

      # Runs a single command using the runners shell
      - name: Verify the tag value
        run: ./scripts/tag_verify.sh

所以问题是:如何让工作流使用存储在 git-worflows 存储库中的脚本而不是 terraform-do-database?

我想要一个可以调用工作流和脚本的存储库,我不想在我的所有存储库中复制所有内容。

最佳答案

我发现,如果我将脚本包装成复合 Action 。我可以使用 GitHub 上下文 github.action_path 来定位脚本。 示例:

运行:${{ github.action_path }}/scripts/foo.sh

关于github - 如何在可重用的 github 工作流程中执行远程脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72133102/

相关文章:

authentication - 为 GitHub 创建 SSH key ?

github - 在提交/拉取请求时跟踪多个 github 存储库以构建 jenkins 作业

ruby-on-rails - 在 Github 中安装特定版本的 Rails gem

Docker - 错误 : Cannot perform an interactive login from a non TTY device (GCP Service Account)

PHP 工作流程 - 函数的执行顺序

c# - 将子类别添加到工作流事件中的依赖属性

GitHub:将分支映射到 Windows 上的不同本地目录

GitHub Actions cronjob 触发器似乎在一个小时后触发

elm - 在 github 操作中使用 elm-test

asp.net-mvc - 您团队中前端和后端之间的工作流程是怎样的?