Skip to content

Build and Release

Build and Release #5

Workflow file for this run

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 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: |
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"
check-branch:
needs: [create_tag]
runs-on: ubuntu-latest
outputs:
current_version: ${{ steps.get_version.outputs.current_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}"
echo "current_version=${current_version}" >> $GITHUB_OUTPUT
- 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}_v${VERSION}_win"
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"
Compress-Archive -Path "uDesktopMascot\*" -DestinationPath "${{ steps.build_info.outputs.artifact_name }}.zip"
cd ..
mv "build/${{ steps.build_info.outputs.artifact_name }}.zip" "./${{ steps.build_info.outputs.artifact_name }}.zip"
- name: Upload the Build for StandaloneWindows64
uses: actions/[email protected]
with:
name: ${{ steps.build_info.outputs.artifact_name }}
path: "${{ steps.build_info.outputs.artifact_name }}.zip"
- 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"
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"
zip -r "${{ steps.build_info.outputs.artifact_name }}.zip" *
ls -la
cd ..
mv "build/${{ steps.build_info.outputs.artifact_name }}.zip" "./${{ steps.build_info.outputs.artifact_name }}.zip"
- name: Upload the Build for StandaloneOSX
uses: actions/[email protected]
with:
name: ${{ steps.build_info.outputs.artifact_name }}
path: "${{ steps.build_info.outputs.artifact_name }}.zip"
- 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 }}