Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 31 additions & 60 deletions .github/workflows/release-upload-zip.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
name: Release - Upload ZIP

on:
pull_request:
branches:
- main
types:
- closed
push:
tags:
- 'v*' # v1.3.0.0 など

permissions:
contents: write
Expand All @@ -15,85 +13,58 @@ env:

jobs:
release:
# 通常のマージでのみ動作することを想定
if: github.event.pull_request.merged == true
runs-on: windows-latest # 安定した最新のWindows環境
runs-on: windows-2025-vs2026

steps:
- name: Checkout
uses: actions/checkout@v4
with:
# マージコミットではなく、ソースブランチのHEADを一時的に見るか、全履歴を取得
fetch-depth: 0

- name: Resolve tag from source branch (v*)
id: tag_check
shell: pwsh
run: |
git fetch --tags --force
$headSha = '${{ github.event.pull_request.head.sha }}'
$baseSha = '${{ github.event.pull_request.base.sha }}'

$selectedTag = git describe --tags --match 'v*' --abbrev=0 $headSha 2>$null
if (-not $selectedTag) {
Write-Error "No reachable v* tag found from source branch head commit: $headSha"
exit 1
}

$tagCommit = git rev-list -n 1 $selectedTag

# 初期値を設定
$shouldRelease = "true"

git merge-base --is-ancestor $tagCommit $baseSha
if ($LASTEXITCODE -eq 0) {
$shouldRelease = "false"
Write-Host "Tag $selectedTag already existed on main side before merge. Skipping release flow."
}

# GitHubの環境変数とステップ出力に保存
"SHOULD_RELEASE=$shouldRelease" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"RELEASE_TAG=$selectedTag" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
Write-Host "Using tag: $selectedTag"

- name: Setup .NET
if: env.SHOULD_RELEASE == 'true'
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Setup MSBuild
if: env.SHOULD_RELEASE == 'true'
uses: microsoft/setup-msbuild@v2
with:
vs-version: '17.0'

# packages.config 対応
- name: NuGet Restore
if: env.SHOULD_RELEASE == 'true'
run: nuget restore SampleCSharpBulkRAGReg.sln

- name: Build (Release)
if: env.SHOULD_RELEASE == 'true'
run: |
msbuild SampleCSharpBulkRAGReg.sln `
/p:Configuration=Release `
/p:Platform="Any CPU" `
/t:Build
run: msbuild SampleCSharpUI.sln `
/p:Configuration=Release `
/p:Platform="Any CPU" `
/t:Build

# ZIP 作成(タグ名を使用)
- name: Create ZIP
if: env.SHOULD_RELEASE == 'true'
run: |
Compress-Archive `
-Path SampleCSharpBulkRAGReg/bin/Release/* `
-DestinationPath SampleCSharpBulkRAGReg-${{ env.RELEASE_TAG }}.zip
-DestinationPath SampleCSharpBulkRAGReg-${{ github.ref_name }}.zip

# 非推奨アクションを最新の定番アクションに統合
- name: Create and Upload GitHub Release
if: env.SHOULD_RELEASE == 'true'
uses: softprops/action-gh-release@v2
# Release 作成(タグ名を使用)
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.RELEASE_TAG }}
name: Release ${{ env.RELEASE_TAG }}
tag_name: ${{ github.ref_name }}
release_name: Release ${{ github.ref_name }}
draft: false
prerelease: false
files: SampleCSharpBulkRAGReg-${{ env.RELEASE_TAG }}.zip

# ZIP を Release に Upload(ご指定どおり)
- name: Upload ZIP to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: SampleCSharpBulkRAGReg-${{ github.ref_name }}.zip
asset_name: SampleCSharpBulkRAGReg-${{ github.ref_name }}.zip
asset_content_type: application/zip
Loading