How to get target branch in github actions on release

Viewed 1015

I have a github action that should update the current branch with the release version provided from tag_name from github UI.

Everything seems to work except for the unknown variable name of the target branch.

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 Answers

After a bit of digging I found out the solution. branch name is found in github.event.release.target_commitish env variable.

Related