|
| 1 | +name: Build and Release EasySFTP |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' # v1.2.3.4 のようなタグが push されたら発火 |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + check-cache: |
| 11 | + runs-on: windows-latest |
| 12 | + outputs: |
| 13 | + cache-hit: ${{ steps.cache-deps.outputs.cache-hit }} |
| 14 | + steps: |
| 15 | + - name: Checkout source code |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Restore OpenSSL/libssh2 cache |
| 19 | + id: cache-deps |
| 20 | + uses: actions/cache@v4 |
| 21 | + with: |
| 22 | + path: deps |
| 23 | + key: easysftp-libs-${{ runner.os }}-${{ hashFiles('.github/lib-versions.env') }} |
| 24 | + |
| 25 | + build-libs: |
| 26 | + needs: check-cache |
| 27 | + if: needs.check-cache.outputs.cache-hit != 'true' |
| 28 | + uses: ./.github/workflows/build-libs.yml |
| 29 | + |
| 30 | + build: |
| 31 | + needs: [check-cache, build-libs] |
| 32 | + if: always() && !cancelled() |
| 33 | + runs-on: windows-latest |
| 34 | + |
| 35 | + steps: |
| 36 | + - name: Checkout source code |
| 37 | + uses: actions/checkout@v4 |
| 38 | + |
| 39 | + - name: Restore OpenSSL/libssh2 cache |
| 40 | + id: cache-deps |
| 41 | + uses: actions/cache@v4 |
| 42 | + with: |
| 43 | + path: deps |
| 44 | + key: easysftp-libs-${{ runner.os }}-${{ hashFiles('.github/lib-versions.env') }} |
| 45 | + |
| 46 | + - name: Fail if deps cache not found |
| 47 | + if: steps.cache-deps.outputs.cache-hit != 'true' |
| 48 | + run: | |
| 49 | + echo "❌ Required deps cache was not found. Aborting." |
| 50 | + exit 1 |
| 51 | +
|
| 52 | + # --- Common.user.props の生成 --- |
| 53 | + - name: Generate Common.user.props |
| 54 | + shell: pwsh |
| 55 | + run: | |
| 56 | + $content = Get-Content Common.user.sample.props -Raw |
| 57 | +
|
| 58 | + $content = $content ` |
| 59 | + -replace '<OpenSSLRoot>.*?</OpenSSLRoot>', |
| 60 | + '<OpenSSLRoot>$(MSBuildThisFileDirectory)deps\openssl\</OpenSSLRoot>' ` |
| 61 | + -replace '<LibSSH2Root>.*?</LibSSH2Root>', |
| 62 | + '<LibSSH2Root>$(MSBuildThisFileDirectory)deps\libssh2\</LibSSH2Root>' |
| 63 | +
|
| 64 | + $content | Set-Content Common.user.props -Encoding UTF8 |
| 65 | +
|
| 66 | + - name: Setup MSBuild |
| 67 | + uses: microsoft/setup-msbuild@v2 |
| 68 | + with: |
| 69 | + vs-version: 'latest' |
| 70 | + |
| 71 | + - name: Build Win32 |
| 72 | + run: | |
| 73 | + msbuild EasySFTP.sln /p:Configuration=Release /p:Platform=Win32 |
| 74 | +
|
| 75 | + - name: Build x64 |
| 76 | + run: | |
| 77 | + msbuild EasySFTP.sln /p:Configuration=Release /p:Platform=x64 |
| 78 | +
|
| 79 | + - name: Prepare artifacts directory |
| 80 | + run: | |
| 81 | + mkdir dist |
| 82 | + mkdir dist\x64 |
| 83 | +
|
| 84 | + copy bin\Win32\Release\*.exe dist\ |
| 85 | + copy bin\Win32\Release\*.dll dist\ |
| 86 | + copy EasySFTP.txt dist\ |
| 87 | + copy license.txt dist\ |
| 88 | + copy README.md dist\ |
| 89 | + copy CHANGELOG.md dist\ |
| 90 | +
|
| 91 | + copy bin\x64\Release\*.exe dist\x64\ |
| 92 | + copy bin\x64\Release\*.dll dist\x64\ |
| 93 | +
|
| 94 | + - name: Upload artifacts |
| 95 | + uses: actions/upload-artifact@v4 |
| 96 | + with: |
| 97 | + name: easysftp-build |
| 98 | + path: dist/ |
| 99 | + |
| 100 | + - name: Create zip archive |
| 101 | + if: github.event_name != 'workflow_dispatch' |
| 102 | + shell: pwsh |
| 103 | + run: | |
| 104 | + $tag = "${{ github.ref_name }}" # 例: v1.2.3.4 |
| 105 | + $version = $tag.TrimStart("v") # 先頭のvを取る |
| 106 | + Compress-Archive -Path dist\* -DestinationPath "EasySFTP-$version.zip" |
| 107 | +
|
| 108 | + - name: Extract release notes from CHANGELOG.md |
| 109 | + if: github.event_name != 'workflow_dispatch' |
| 110 | + id: changelog |
| 111 | + shell: pwsh |
| 112 | + run: | |
| 113 | + $tag = "${{ github.ref_name }}" # 例: v1.2.3.4 |
| 114 | + echo "TAG_NAME=$tag" >> $env:GITHUB_ENV |
| 115 | +
|
| 116 | + $lines = Get-Content CHANGELOG.md |
| 117 | + $start = $lines.IndexOf("## $tag") |
| 118 | + if ($start -ge 0) { |
| 119 | + $rest = $lines[($start + 1)..($lines.Count - 1)] |
| 120 | + $bodyLines = @() |
| 121 | + foreach ($line in $rest) { |
| 122 | + if ($line -match "^## ") { break } |
| 123 | + $bodyLines += $line |
| 124 | + } |
| 125 | +
|
| 126 | + $body = $bodyLines -join "`n" |
| 127 | + "RELEASE_BODY<<EOF" >> $env:GITHUB_ENV |
| 128 | + $body >> $env:GITHUB_ENV |
| 129 | + "EOF" >> $env:GITHUB_ENV |
| 130 | + } |
| 131 | +
|
| 132 | + - name: Upload release asset |
| 133 | + if: github.event_name != 'workflow_dispatch' |
| 134 | + uses: softprops/action-gh-release@v2 |
| 135 | + with: |
| 136 | + tag_name: ${{ env.TAG_NAME }} |
| 137 | + name: ${{ env.TAG_NAME }} |
| 138 | + body: ${{ env.RELEASE_BODY }} |
| 139 | + files: EasySFTP-*.zip |
0 commit comments