【问题标题】:Get PR Number OR Branch Name in GitHub Actions在 GitHub Actions 中获取 PR 编号或分支名称
【发布时间】:2020-12-29 06:08:58
【问题描述】:

我正在尝试在 PR 请求合并到开发和主和时部署无服务器应用程序。我希望阶段名称与分支名称或拉取请求编号相对应。

这是有问题的步骤,但 github.event.push.ref 是整个分支 ref(即 ref/head/master)等。我只想要“master”或“develop”。有没有办法使用与下面相同的语法来获取 pull_request 编号或分支名称?

      # Deploy API Tests
      - name: Deploy API
        run: yarn deploy --stage ${{ github.event.pull_request.number || github.event.push.ref }}
        working-directory: api

【问题讨论】:

    标签: github github-actions


    【解决方案1】:

    如果您使用的 shell 是 bash 或其他 POSIX shell,这样做很容易:

    run: 'yarn deploy --stage $(echo "${{ github.event.pull_request.number || github.event.push.ref }}" | sed -e 's!^refs/heads/!!')'
    

    这将去掉 refs/heads/ 前缀,只留下分支名称。如果你没有使用 PR,那么你也可以使用它,它会让 Git 将名称缩写为分支或标签名称:

    run: 'yarn deploy --stage $(git rev-parse --abbrev-ref "${{ github.event.push.ref }}")'
    

    【讨论】:

      猜你喜欢
      • 2020-04-10
      • 2020-12-16
      • 2020-12-13
      • 2022-06-21
      • 2020-01-21
      • 1970-01-01
      • 1970-01-01
      • 2022-07-27
      • 2023-02-24
      相关资源
      最近更新 更多