Use specific parts of commit messages in releases

This is probably a bit more of a rather specific question, but I still hope people can help me out on this.
I essentially want to fully automate the release-process where I would…

  • …Create a release with title and comment
  • …Generate files for the release after it was created
  • …Upload the generated files to the release.

I already have a specific part of the Action file done, which is the creation of the release.
The current file looks like this:

name: Create Release

on:
  push:
    branches:
      - master
    paths-ignore:
      - '.github/**'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  release:
    if: " !startsWith(github.event.head_commit.message, 'Merge pull request') "
    steps:
      - name: 'Checkout Code'
        uses: actions/checkout@v2
      - name: 'Create Release'
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.ref }}
          release_name: TBD
          body: |-
            ${{ github.event.message }}
          draft: false
          prerelease: false

Now I want this to be a bit more… “fine tuned”. I essentially want that the title (Here called TBN (To be named)) contains the first line of the commit message and the body contains everything else.
Is there a good way to achieve this?

Hi @andre601,

actions/create-release@v1 will help to create the release with release_name and body specified. What you need to do is to get the commit messsage from GITHUB CONTEXT or $GITHUB_EVENT_PATH, parse the message content, spilit the the first line and left part into two variables.

For example, you can get the head_commit message with below code:

str="$(jq '.head_commit.message' $GITHUB_EVENT_PATH)"   # get the head_commit message

If you submit the commit from github web, the message content will follow “string\n\nstring2” format as below:


You need to parse the title and body content, and set the value to actions/create-release@v1.

Code sample as below:

jobs:
  release:
    runs-on: ubuntu-latest
    if: " !startsWith(github.event.head_commit.message, 'Merge pull request') "
    steps:
      - name: check headcommit message
        id: commit
        run: |
          str="$(jq '.head_commit.message' $GITHUB_EVENT_PATH)"    # get the head_commit message
          echo ::set-output name=title::${str%%\\n*} | tr -d '"'         # get the title
          echo ::set-output name=body::${str##*\\n} | tr -d '"'         # get the body
      - name: check value # confirm the value for check, you can ignore it.
        run: |
          echo ${{ steps.commit.outputs.title}}    
          echo ${{ steps.commit.outputs.body}}
      - name: 'Checkout Code'
        uses: actions/checkout@v2
      - name: 'Create Release'
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.ref }}
          release_name: ${{ steps.commit.outputs.title}}   # use the title
          body: |                                                                 # use the body
            ${{ steps.commit.outputs.body}}
          draft: false
          prerelease: false

My workflow here for your reference.

BTW, if you commit from local client(git bash), the commit message format could be different, you need to change the parse method to get the title and body.

Thanks