How to show release body as commits history between 2 latest tags?

this is my auto create release action
now I want to insert commits log between 2 latest tags into release body
any ideas?

name: Release

on:
  push:
    tags:
    - '*'

jobs:
  release:
    runs-on: ubuntu-latest
    steps:

      - name: Create Release
        id: create_release
        uses: actions/create-release@latest
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.ref }}
          release_name: Release ${{ github.ref }}


          body: show commits log between 2 latest tags


          draft: false
          prerelease: false

How about this (didn’t try yet)

name: Release

on:
  push:
    tags:
    - '*'

jobs:
  release:
    runs-on: ubuntu-latest
    steps:

      - name: Get commit summary
        run: | 
          #TODO: find the previous tag somehow right here
          # previousTag=$(git something)
          commitSummary="$(git log $previousTag..${{ github.ref }})"
          echo "::set-env name=COMMIT_SUMMARY::\"$commitSummary\""
      - name: Create Release
        id: create_release
        uses: actions/create-release@latest
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.ref }}
          release_name: Release ${{ github.ref }}
          body: ${{env.COMMIT_SUMMARY}}

@dogboydog Thanks for sharing your yml.
@Solor As a supplement of dogboydog’s comment, you could try the following yml to get the previous Tag.

name: Release

on:
  push:
    tags:
    - '*'

jobs:
  release:
    runs-on: ubuntu-latest
    steps: 
      - uses: actions/checkout@v2  
        with:
          fetch-depth: 0
      
      - name: Get commit summary
        run: | 
          #TODO: find the previous tag somehow right here
          previousTag=$(git tag --sort=-creatordate | sed -n 2p)
          echo "previousTag : $previousTag"
          
          commitSummary="$(git log $previousTag..${{ github.ref }})"
          echo "::set-env name=COMMIT_SUMMARY::\"$commitSummary\""
1 Like