如何在 GitHub Actions 中获取发布版本的目标分支

7
我有一个 Github Action,它应该使用 Github UI 提供的 tag_name 来更新当前分支。除目标分支的未知变量名称之外,一切似乎都正常。
on:
  release:
    types: [created]

jobs:
  update-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2 # <-- I want the branch to match github release selected branch
      - name: Update version
        run: |
          tag_name=$(echo "${github.event.release.tag_name}" | sed -e 's/[]$.*[\^]/\\&/g' )
          sed -i "s/\"version\": \".*\",/\"version\": \"${tag_name}\",/" ./src/components/package.json
      - name: Commit Updated version.
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git add . && git commit -m "Bump version" -a
      - name: Push changes
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
1个回答

13

我经过一番搜索,找到了解决方案。分支名称可以在 github.event.release.target_commitish 环境变量中找到。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接