Antoine Eskaros
Antoine Eskaros

Reputation: 851

How to get target branch in github actions on release

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 "[email protected]"
          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 }}

Upvotes: 8

Views: 2992

Answers (1)

Antoine Eskaros
Antoine Eskaros

Reputation: 851

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

Upvotes: 14

Related Questions