タグからリリースノートを作る

gh release create --generate-notes。checkout は fetch-depth: 0。

  • #GitHub Actions

gh はランナーに入っている。contents: write と、履歴が必要なので fetch-depth: 0

yaml
name: Tag Release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write

jobs:
  create-release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Create Release
        run: gh release create ${{ github.ref_name }} --generate-notes
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

バージョンをファイルで管理しているなら、そのファイルの変更でタグを打ち、同じ job でリリースを作る。

yaml
on:
  push:
    branches:
      - main
    paths:
      - ".version"

permissions:
  contents: write

jobs:
  create-tag:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - id: version
        run: echo "version=$(cat .version)" >> $GITHUB_OUTPUT
      - run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}"
          git push origin "v${{ steps.version.outputs.version }}"
      - run: gh release create "v${{ steps.version.outputs.version }}" --generate-notes
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

gh release create

編集