- actions/checkout@v4 での fetch-depth: 0 および fetch-tags: true による全タグ・コミット履歴の取得設定 - 前回のタグを判定・特定する release_info ステップの追加 - git log より前回タグからの変更履歴を抽出する changelog ステップの追加 - softprops/action-gh-release@v2 へのアップデートと body へのリリースノート設定
83 lines
3.1 KiB
YAML
83 lines
3.1 KiB
YAML
name: release
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v[0-9]+\\.[0-9]+\\.[0-9]+"
|
|
- "v[0-9]+\\.[0-9]+\\.[0-9]+-*"
|
|
|
|
jobs:
|
|
create_release:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
fetch-tags: true
|
|
- name: version
|
|
id: version
|
|
run: |
|
|
REPOSITORY=$(echo ${{ github.event.repository.name }})
|
|
echo "repository=$REPOSITORY" >> "$GITHUB_OUTPUT"
|
|
VERSION=$(basename ${{ github.ref }})
|
|
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
|
VERSION_STRING=$(echo $VERSION | sed -e "s#\.#_#g")
|
|
echo "version_string=$VERSION_STRING" >> "$GITHUB_OUTPUT"
|
|
- name: 前のリリースタグを特定
|
|
id: release_info
|
|
run: |
|
|
VERSION="${{ steps.version.outputs.version }}"
|
|
if [[ "$VERSION" == *"-"* ]]; then
|
|
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
|
|
else
|
|
PREVIOUS_TAG=$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | grep -v '-' | grep -v "^${VERSION}$" | head -1)
|
|
fi
|
|
echo "previous_tag=$PREVIOUS_TAG" >> "$GITHUB_OUTPUT"
|
|
echo "前のタグ: $PREVIOUS_TAG"
|
|
- name: コミット履歴を生成
|
|
id: changelog
|
|
run: |
|
|
PREVIOUS_TAG="${{ steps.release_info.outputs.previous_tag }}"
|
|
VERSION="${{ steps.version.outputs.version }}"
|
|
|
|
if [ -n "$PREVIOUS_TAG" ]; then
|
|
echo "## 変更内容 (${PREVIOUS_TAG}...${VERSION})" > changelog.md
|
|
echo "" >> changelog.md
|
|
git log --pretty=format:"- %s (%h)" ${PREVIOUS_TAG}..HEAD >> changelog.md
|
|
else
|
|
echo "## 変更内容" > changelog.md
|
|
echo "" >> changelog.md
|
|
git log --pretty=format:"- %s (%h)" >> changelog.md
|
|
fi
|
|
|
|
DELIMITER="CHANGELOG_$(date +%s%N)"
|
|
echo "changelog<<${DELIMITER}" >> "$GITHUB_OUTPUT"
|
|
cat changelog.md >> "$GITHUB_OUTPUT"
|
|
echo "" >> "$GITHUB_OUTPUT"
|
|
echo "${DELIMITER}" >> "$GITHUB_OUTPUT"
|
|
- name: Zip output
|
|
id: create_zip
|
|
run: |
|
|
ARCHIVE_BASENAME=$(echo ${{steps.version.outputs.repository}}-${{steps.version.outputs.version_string}})
|
|
ARCHIVE_FILENAME=$(echo $ARCHIVE_BASENAME.zip)
|
|
|
|
echo "filename=$ARCHIVE_FILENAME" >> "$GITHUB_OUTPUT"
|
|
|
|
mkdir $ARCHIVE_BASENAME
|
|
rsync -av ./* $ARCHIVE_BASENAME --exclude $ARCHIVE_BASENAME
|
|
zip -r $ARCHIVE_FILENAME $ARCHIVE_BASENAME -x ".git"
|
|
- name: Create Release
|
|
id: create-release
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
name: Release ${{ steps.version.outputs.version }}
|
|
tag_name: ${{ steps.version.outputs.version }}
|
|
body: ${{ steps.changelog.outputs.changelog }}
|
|
draft: true
|
|
prerelease: ${{ contains(steps.version.outputs.version, '-') }}
|
|
files: |
|
|
${{ steps.create_zip.outputs.filename}}
|
|
|