Skip to content

refactor: full_build.yamlでsetup-rosアクションを使用 (#1139) #174

refactor: full_build.yamlでsetup-rosアクションを使用 (#1139)

refactor: full_build.yamlでsetup-rosアクションを使用 (#1139) #174

Workflow file for this run

name: Auto Version Bump and Release
on:
workflow_dispatch:
inputs:
bump_type:
description: 'バージョンバンプタイプ'
required: true
type: choice
default: 'patch'
options:
- patch
- minor
- major
dry_run:
description: 'ドライランモード(実際のpush・リリースは行わない)'
required: false
type: boolean
default: false
push:
branches:
- develop
permissions:
contents: write
pull-requests: write
jobs:
version-bump-release:
name: Version Bump and Release
runs-on: ubuntu-latest
timeout-minutes: 10
# 無限ループ防止: Merge queue botとgithub-actions botによるコミットを除外
# ただし手動実行は許可
if: |
github.actor != 'github-merge-queue[bot]' &&
(github.event.head_commit.author.name != 'github-actions[bot]' || github.event_name == 'workflow_dispatch')
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
# Protected branchへのpushにはPATが必要
token: ${{ secrets.GH_PAT }}
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: '3.x'
- name: Install bloom and dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -yqq python3-pip python3-catkin-pkg
pip3 install bloom
shell: bash
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
shell: bash
- name: Display mode
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.dry_run }}" = "true" ]; then
echo "🔍 =========================================="
echo "🔍 ドライランモード(DRY RUN MODE)"
echo "🔍 =========================================="
echo "🔍 実際のpush・リリースは行いません"
echo "🔍 =========================================="
else
echo "✅ 通常モード(実際のpush・リリースを実行)"
fi
shell: bash
- name: Determine bump type
id: bump_type
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "type=${{ inputs.bump_type }}" >> $GITHUB_OUTPUT
else
echo "type=patch" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Get current version
id: current_version
run: |
# 最初のpackage.xmlからバージョンを取得
VERSION=$(grep -m1 '<version>' $(find . -name package.xml | head -1) | sed 's/.*<version>\(.*\)<\/version>.*/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Current version: $VERSION"
shell: bash
- name: Check and fix tag consistency
run: |
# 現在のバージョンを取得
CURRENT_VERSION=$(grep -m1 '<version>' $(find . -name package.xml | head -1) | sed 's/.*<version>\(.*\)<\/version>.*/\1/')
# 次のバージョンを計算(bump typeに応じて)
BUMP_TYPE="${{ steps.bump_type.outputs.type }}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
case "$BUMP_TYPE" in
major)
NEXT_VERSION="$((MAJOR + 1)).0.0"
;;
minor)
NEXT_VERSION="${MAJOR}.$((MINOR + 1)).0"
;;
patch)
NEXT_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
;;
esac
echo "Expected next version: $NEXT_VERSION"
# タグが既に存在するかチェック
if git rev-parse "$NEXT_VERSION" >/dev/null 2>&1; then
echo "⚠️ タグ $NEXT_VERSION が既に存在します。整合性を確認中..."
# タグが指すコミットのpackage.xmlバージョンを取得
PACKAGE_FILE=$(find . -name package.xml | head -1)
TAG_VERSION=$(git show "$NEXT_VERSION:$PACKAGE_FILE" 2>/dev/null | grep -m1 '<version>' | sed 's/.*<version>\(.*\)<\/version>.*/\1/' || echo "")
echo "Tag points to version: $TAG_VERSION"
if [ "$TAG_VERSION" != "$NEXT_VERSION" ]; then
echo "❌ タグとバージョンが不一致です(タグ: $NEXT_VERSION, package.xml: $TAG_VERSION)"
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.dry_run }}" = "true" ]; then
echo "🔍 [DRY RUN] 不整合なタグを削除する予定:"
echo " - git tag -d $NEXT_VERSION"
echo " - git push origin --delete $NEXT_VERSION"
else
echo "🔧 不整合なタグを削除します..."
# ローカルとリモートのタグを削除
git tag -d "$NEXT_VERSION"
git push origin --delete "$NEXT_VERSION" || echo "リモートタグの削除に失敗しましたが続行します"
echo "✅ タグを削除しました。catkin_prepare_releaseで再作成されます。"
fi
else
echo "✅ タグとバージョンは整合性があります。"
echo "⚠️ しかし、このタグは既に存在するため、catkin_prepare_releaseでエラーが発生する可能性があります。"
fi
else
echo "✅ タグ $NEXT_VERSION は存在しません。問題ありません。"
fi
shell: bash
- name: Run catkin_prepare_release
id: release
run: |
# バージョンバンプを実行
catkin_prepare_release --bump ${{ steps.bump_type.outputs.type }} --no-push -y
# 新しいバージョンを取得
NEW_VERSION=$(grep -m1 '<version>' $(find . -name package.xml | head -1) | sed 's/.*<version>\(.*\)<\/version>.*/\1/')
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
shell: bash
- name: Amend commit with custom message
run: |
# catkin_prepare_releaseが作成したコミットを修正して日本語メッセージに変更
git reset --soft HEAD~1
git add .
git commit -m "$(cat <<'EOF'
release: バージョン${{ steps.release.outputs.new_version }}をリリース
全パッケージのバージョンを${{ steps.current_version.outputs.version }}から${{ steps.release.outputs.new_version }}に更新
[skip ci]
EOF
)"
# タグを再作成(catkin_prepare_releaseが作成したタグを削除して、新しいコミットに再作成)
git tag -d "${{ steps.release.outputs.new_version }}"
git tag -a "${{ steps.release.outputs.new_version }}" -m "Release ${{ steps.release.outputs.new_version }}"
echo "Recreated tag ${{ steps.release.outputs.new_version }} on the amended commit"
shell: bash
- name: Push version bump commit and tag
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.dry_run }}" = "true" ]; then
echo "🔍 [DRY RUN] 以下のコマンドを実行する予定:"
echo " - git push origin develop"
echo " - git push origin ${{ steps.release.outputs.new_version }}"
else
# バージョンアップコミットとタグをpush
git push origin develop
git push origin ${{ steps.release.outputs.new_version }}
echo "✅ Pushed commit and tag to remote repository"
fi
shell: bash
- name: Generate release notes
id: release_notes
run: |
# 前回のタグを取得
PREVIOUS_TAG=$(git tag --sort=-creatordate | sed -n '2p')
if [ -z "$PREVIOUS_TAG" ]; then
# 最初のリリースの場合
echo "notes=🎉 crane v${{ steps.release.outputs.new_version }}の初回リリースです。" >> $GITHUB_OUTPUT
else
# 変更履歴を生成
CHANGES=$(git log --pretty=format:"- %s" ${PREVIOUS_TAG}..${{ steps.release.outputs.new_version }})
echo "notes<<EOF" >> $GITHUB_OUTPUT
echo "## 変更内容" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "$CHANGES" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "---" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREVIOUS_TAG}...${{ steps.release.outputs.new_version }}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Display dry run message for release
if: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run == true }}
run: |
echo "🔍 [DRY RUN] 以下の内容でGitHub Releaseを作成する予定:"
echo " - Tag: ${{ steps.release.outputs.new_version }}"
echo " - Name: Release ${{ steps.release.outputs.new_version }}"
echo " - Draft: false"
echo " - Prerelease: false"
shell: bash
- name: Create GitHub Release
if: ${{ ! (github.event_name == 'workflow_dispatch' && inputs.dry_run == true) }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release.outputs.new_version }}
name: Release ${{ steps.release.outputs.new_version }}
body: ${{ steps.release_notes.outputs.notes }}
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}