Build and Release #12
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Release | |
on: | |
workflow_dispatch: | |
inputs: | |
tag_name: | |
description: 'タグ名を「v数字.数字.数字」の形式で入力してください(例:v1.0.0)' | |
required: true | |
jobs: | |
create_tag: | |
runs-on: ubuntu-latest | |
outputs: | |
tag_name: ${{ steps.get_tag.outputs.tag_name }} | |
steps: | |
- name: タグ名の検証と取得 | |
id: get_tag | |
run: | | |
TAG_NAME="${{ github.event.inputs.tag_name }}" | |
if [[ ! "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
echo "エラー: タグ名が有効な形式ではありません。v数字.数字.数字 の形式で入力してください。" | |
exit 1 | |
fi | |
echo "::set-output name=tag_name::$TAG_NAME" | |
- name: リポジトリをチェックアウト | |
uses: actions/[email protected] | |
with: | |
fetch-depth: 0 | |
- name: タグが既に存在しないか確認 | |
run: | | |
TAG_NAME="${{ steps.get_tag.outputs.tag_name }}" | |
if [ "$TAG_NAME" != "v99.99.99" ] && git rev-parse "$TAG_NAME" >/dev/null 2>&1; then | |
echo "エラー: タグ '$TAG_NAME' は既に存在します。" | |
exit 1 | |
fi | |
- name: タグを作成してプッシュ | |
env: | |
TAG_NAME: ${{ steps.get_tag.outputs.tag_name }} | |
run: | | |
if [ "$TAG_NAME" != "v99.99.99" ]; then | |
git config --global user.name "${{ github.actor }}" | |
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
git tag "$TAG_NAME" | |
git push origin "$TAG_NAME" | |
fi | |
check-branch: | |
needs: [create_tag] | |
runs-on: ubuntu-latest | |
outputs: | |
current_version: ${{ steps.get_version.outputs.current_version }} | |
old_version: ${{ steps.get_version.outputs.old_version }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: バージョンを取得 | |
id: get_version | |
run: | | |
TAG_NAME="${{ needs.create_tag.outputs.tag_name }}" | |
echo "タグ名: $TAG_NAME" | |
current_version="${TAG_NAME#v}" | |
old_version=$(grep '#define MyAppVersion' Installer/setup.txt | cut -d '"' -f2) | |
echo "current_version=${current_version}" >> $GITHUB_OUTPUT | |
echo "old_version=${old_version}" >> $GITHUB_OUTPUT | |
if [ "$old_version" != "$current_version" ]; then | |
echo "現在のプロジェクトバージョン: $current_version" | |
echo "#define MyAppVersion \"$current_version\"" > Installer/setup.txt | |
echo "setup.txt の内容: $(cat Installer/setup.txt)" | |
git config --global user.name "github-actions" | |
git config --global user.email "[email protected]" | |
git add Installer/setup.txt | |
git commit -m "Update version file" | |
git push origin HEAD:${{ github.ref }} | |
fi | |
- name: タグ名の確認 | |
run: | | |
echo "イベント名: ${{ github.event_name }}" | |
TAG_NAME="${{ needs.create_tag.outputs.tag_name }}" | |
echo "タグ名: $TAG_NAME" | |
# タグ名からバージョン番号を取得 | |
current_version="${TAG_NAME#v}" | |
echo "現在のバージョン: $current_version" | |
# gitから既存のバージョンタグのリストを取得 | |
git fetch --tags | |
version_tags=$(git tag -l 'v*') | |
echo "既存のバージョンタグ: $version_tags" | |
# タグからバージョン番号を抽出 | |
versions=() | |
for tag in $version_tags; do | |
versions+=("${tag#v}") | |
done | |
if [ ${#versions[@]} -eq 0 ]; then | |
highest_version="0.0.0" | |
else | |
highest_version=$(printf '%s\n' "${versions[@]}" | sort -V | tail -n1) | |
fi | |
echo "最高の既存バージョン: $highest_version" | |
# 現在のバージョンと最高の既存バージョンを比較 | |
if [ "$(printf '%s\n' "$highest_version" "$current_version" | sort -V | tail -n1)" != "$current_version" ]; then | |
echo "エラー: 現在のバージョン ($current_version) は最高の既存バージョン ($highest_version) よりも高くありません。" | |
exit 1 | |
else | |
echo "現在のバージョン ($current_version) は最高の既存バージョン ($highest_version) よりも高いです。" | |
fi | |
build-windows: | |
needs: [check-branch] | |
runs-on: windows-latest | |
steps: | |
- name: Check out my unity project. | |
uses: actions/[email protected] | |
- name: Create LFS file list | |
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id | |
- name: Restore LFS cache | |
uses: actions/[email protected] | |
id: lfs-cache | |
with: | |
path: .git/lfs | |
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }} | |
- name: Git LFS Pull | |
run: | | |
git lfs pull | |
git add . | |
git reset --hard | |
- name: ビルド情報を設定 | |
id: build_info | |
shell: bash # ここでシェルを 明示的にBash に指定します | |
run: | | |
TAG_NAME="${{ needs.create_tag.outputs.tag_name }}" | |
VERSION="${{ needs.check-branch.outputs.current_version }}" | |
REPO_NAME="${GITHUB_REPOSITORY##*/}" | |
ARTIFACT_NAME="${REPO_NAME}_win_v${VERSION}" | |
echo "artifact_name=${ARTIFACT_NAME}" >> $GITHUB_OUTPUT | |
- uses: actions/[email protected] | |
with: | |
path: Library | |
key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }} | |
restore-keys: | | |
Library- | |
- name: Run the build for StandaloneWindows64 | |
uses: game-ci/[email protected] | |
env: | |
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} | |
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} | |
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} | |
with: | |
targetPlatform: StandaloneWindows64 | |
unityVersion: '6000.0.31f1' | |
buildName: 'uDesktopMascot' | |
versioning: Custom | |
version: ${{ needs.check-branch.outputs.current_version }} | |
- name: ビルド成果物を圧縮して名前を変更 | |
run: | | |
cd build | |
mv "StandaloneWindows64" "uDesktopMascot" | |
cd .. | |
- name: Upload the Build for StandaloneWindows64 | |
uses: actions/[email protected] | |
with: | |
name: ${{ steps.build_info.outputs.artifact_name }} | |
path: build/uDesktopMascot | |
- name: Change directory to Installer | |
run: cd Installer | |
- name: Set up Inno Setup | |
uses: Minionguyjpro/[email protected] | |
with: | |
path: 'Installer/setup.iss' | |
- name: Change directory to Root | |
run: cd .. | |
- name: Upload Installer | |
uses: actions/[email protected] | |
with: | |
name: uDesktopMascot_win64_installer_v${{ needs.check-branch.outputs.current_version }} | |
path: "Installer/uDesktopMascot_win64_installer_v${{ needs.check-branch.outputs.current_version }}.exe" | |
- name: Redo version file | |
shell: pwsh | |
run: | | |
echo "${{ needs.check-branch.outputs.current_version }}" | |
echo "${{ needs.check-branch.outputs.old_version }}" | |
if ("${{ needs.check-branch.outputs.current_version }}" -cne "99.99.99") { | |
$old_version = "${{ needs.check-branch.outputs.old_version }}" | |
Write-Output $old_version | |
"#define MyAppVersion `"$old_version`"" | Out-File -FilePath Installer/setup.txt -Encoding utf8 | |
Write-Output "setup.txt の内容: $(Get-Content Installer/setup.txt)" | |
git config --global user.name "github-actions" | |
git config --global user.email "[email protected]" | |
git add Installer/setup.txt | |
git commit -m "Update version file" | |
git push origin HEAD:${{ github.ref }} | |
} | |
build-mac: | |
needs: [check-branch] | |
runs-on: macos-latest | |
steps: | |
- name: Check out my unity project. | |
uses: actions/[email protected] | |
- name: Create LFS file list | |
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id | |
- name: Restore LFS cache | |
uses: actions/[email protected] | |
id: lfs-cache | |
with: | |
path: .git/lfs | |
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }} | |
- name: Git LFS Pull | |
run: | | |
git lfs pull | |
git add . | |
git reset --hard | |
- name: ビルド情報を設定 | |
id: build_info | |
shell: bash # ここでシェルを 明示的にBash に指定します | |
run: | | |
TAG_NAME="${{ needs.create_tag.outputs.tag_name }}" | |
VERSION="${{ needs.check-branch.outputs.current_version }}" | |
REPO_NAME="${GITHUB_REPOSITORY##*/}" | |
ARTIFACT_NAME="${REPO_NAME}_mac_v${VERSION}" | |
echo "artifact_name=${ARTIFACT_NAME}" >> $GITHUB_OUTPUT | |
- uses: actions/[email protected] | |
with: | |
path: Library | |
key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }} | |
restore-keys: | | |
Library- | |
- name: Run the build for StandaloneOSX | |
uses: game-ci/[email protected] | |
env: | |
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} | |
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} | |
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} | |
with: | |
targetPlatform: StandaloneOSX | |
unityVersion: '6000.0.31f1' | |
buildName: 'uDesktopMascot' | |
versioning: Custom | |
version: ${{ needs.check-branch.outputs.current_version }} | |
- name: ビルド成果物を圧縮して名前を変更 | |
run: | | |
cd build | |
mv "StandaloneOSX" "uDesktopMascot" | |
cd .. | |
- name: Upload the Build for StandaloneOSX | |
uses: actions/[email protected] | |
with: | |
name: ${{ steps.build_info.outputs.artifact_name }} | |
path: build/uDesktopMascot | |
- name: Set up Installer | |
run: | | |
cd build | |
productbuild --component uDesktopMascot/uDesktopMascot.app /Applications ./uDesktopMascot_mac_installer_v${{ needs.check-branch.outputs.current_version }}.pkg | |
- name: Upload Installer | |
uses: actions/[email protected] | |
with: | |
name: uDesktopMascot_mac_installer_v${{ needs.check-branch.outputs.current_version }} | |
path: build/uDesktopMascot_mac_installer_v${{ needs.check-branch.outputs.current_version }}.pkg | |
release: | |
needs: [build-windows, build-mac] | |
runs-on: ubuntu-latest | |
steps: | |
- name: コードをチェックアウト | |
uses: actions/checkout@v4 | |
- name: アーティファクトをダウンロード | |
uses: actions/download-artifact@v3 | |
with: | |
path: ./artifacts | |
- name: タグ名を取得 | |
id: vars | |
run: | | |
TAG_NAME="${{ needs.create_tag.outputs.tag_name }}" | |
echo "リリースタグ名は '${TAG_NAME}' です" | |
echo "tag_name=${TAG_NAME}" >> $GITHUB_OUTPUT | |
- name: ドラフトリリースを作成し、アーティファクトをアップロード | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ steps.vars.outputs.tag_name }} | |
draft: true | |
files: artifacts/**/* | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |