Fetching release_id by a given tag

Problem attempting to solve

We would like to have a Github Action workflow that attaches some artifacts to a given release, but am not using the automation for this at this time (ie when a tag is created, generate a release). We are creating the releases/tags by hand via the web UI at this time. So within the workflow we are attempting to lookup the release_id for a given tag that fired off the workflow.

My current hack solution

Here’s what I am currently doing within a Github Action step to attempt to figure this out:

      - id: get-id
        name: Compute needed variables
        run: |
          tag=$(echo ${{ github.ref }} | cut -d '/' -f3)
          echo "::set-output name=tag::$tag"
          rel_id=$(curl -sL https://api.github.com/repos/${{github.repository}}/releases?access_token=${{ secrets.GITHUB_TOKEN }} | jq -r --arg TAG "$tag" '.[] | select(.tag_name==$TAG) | .id')
          echo ::set-output name=rel_id::$rel_id

This logic is brittle and will generate garbage when run for a non-tag workflow event, but that is OK as later steps don’t use these variables unless running for a tag.


  1. Perhaps this is more a github API question, but there is no API to get a release_id for a given tag name, is there?
  2. Is the release_id available in some environment variable that I am blissfully ignorant of?

I suspect I am doing this all wrong, but my hack appears to be working via some jq magic. Thanks for your thoughts.