3

I am trying to create a Github Action job that will automatically generate a release note and create a release based on that note. I have found an action called "actions/create-release", but it is only good for creating the release, and does not provide a way to automatically generate the release note.

  - name: Create-Release
    id: release
    uses: actions/create-release@v1
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    with:
      tag_name: "${{ env.ver }}"
      release_name: "${{ env.ver }}"
      draft: false
      prerelease: false

Moreover, I have also learned that the "actions/create-release" repository is now obsolete, and no further updates will be provided for it. Therefore, I am seeking an alternative solution to accomplish my goal.

What is the best way to auto-generate a release note and create a release using Github Actions? Are there any recommended actions or workflows that can achieve this without relying on the now-obsolete "actions/create-release" repository?

gamechanger17
  • 4,025
  • 6
  • 22
  • 38

1 Answers1

6

This can be done using the GitHub CLI and a run step. For example, a workflow that creates a release for any tag pushed to the main branch could look like this:

name: Create release

on:
  push:
    tags:
      - v*

jobs:
  release:
    name: Release pushed tag
    runs-on: ubuntu-22.04
    steps:         
      - name: Create release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          tag: ${{ github.ref_name }}
        run: |
          gh release create "$tag" \
              --repo="$GITHUB_REPOSITORY" \
              --title="${GITHUB_REPOSITORY#*/} ${tag#v}" \
              --generate-notes
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
  • The `$tag` part did not work for me, so instead I used `$GITHUB_REF_NAME` as described here: https://stackoverflow.com/a/73358768/2685239 – mariusm Jun 16 '23 at 07:24
  • 1
    @mariusm `github.event.push.ref` and then `${ref##*/}` should work, according to the [`push` payload](https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#push), as long as your shell is Bash. However, `github.ref_name` is nicer because it's already shortened! I updated the answer. – Benjamin W. Jun 16 '23 at 13:22