-1

We're updating our release workflow to use semantic-release, and I need to be able to grab the SHA of the latest tag, create a new branch with it, build our assets, commit them to that new branch.

The action I'm using to create the branch, requires the SHA of the parent branch if you're building a branch based on something other than the branch the runs the workflow.

So I have a couple actions to determine if the release is major, minor, or patch, and then will find the latest semver tag name. But I don't know how to get the SHA of this Ref.

So far I have this:

jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Setup Node.js
        uses: actions/setup-node@v2
        with:
          node-version: 'lts/*'
      - name: Install dependencies
        run: npm ci
      - name: Release
        env:
          GITHUB_TOKEN: ${{ $secrets.GH_TOKEN }}
        run: npx semantic-release

      # Search for latest tag
      - name: Find latest tag label
        uses: actions-ecosystem/action-release-label@v1
        id: release-label

      - name: Find latest tag 
        uses: actions-ecosystem/action-get-latest-tag@v1
        id: get-latest-tag
        if: ${{ steps.release-label.outputs.level != null }}

      # lastest tag is now stored in 
      # ${{ steps.get-latest-tag.outputs.tag }}
      # but this only returns a string, I need the SHA for: 
        
      - name: Create release branch
        uses: peterjgrainger/action-create-branch@v2.1.0
        env:
          GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
        with:
          branch: release 
          sha: ${{ github.sha }} # Need the TAG SHA here as base for release branch

I can't find any docs to tell me how to get info for a specific ref, my tag in this case.

secondman
  • 3,233
  • 6
  • 43
  • 66
  • 1
    Git doesn't have the concept of a "parent branch". There may be something in Git*Hub* you can use, but Git itself won't help here. – torek Jan 11 '22 at 05:46
  • 1
    No, I have no idea what you mean to accomplish. In particular I don't understand why you need any parent at all here, whether it's a parent commit (which Git does have) or a parent branch (which Git doesn't have). – torek Jan 11 '22 at 06:43
  • 1
    If you have an answer you like, ignore any comments you don't like. You've already accepted TTT's answer. My comment was a statement of fact: Git doesn't keep track of parents of branches. – torek Jan 11 '22 at 06:54
  • @torek I think by "SHA of the parent branch" OP was referring to the "commit the new branch started at" (merge-base). Regardless, I think that sentence was mostly backstory anyway. – TTT Jan 12 '22 at 15:10

1 Answers1

1

To answer your question:

git log -1 --format="%H" REF-NAME

REF-NAME here could be a tag, branch, or a commit ID, any of which the command will return the commit ID.

Note though that you should be able to create a branch by just supplying the tag name without the commit ID.

TTT
  • 22,611
  • 8
  • 63
  • 69
  • Thanks. I'll give this a shot. I'm trying to use actions wherever possible and stay away from running command line functions. Is there not a `github.event.release.tag.sha` or something similar? – secondman Jan 11 '22 at 05:38