|
| 1 | +name: Release CI |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + tag: |
| 7 | + description: 'Tag name for the release (e.g., v1.0.0). If empty, a tag will be generated from the run number.' |
| 8 | + required: false |
| 9 | + default: '' |
| 10 | + name: |
| 11 | + description: 'Release title (optional). If empty, a title will be generated using the tag.' |
| 12 | + required: false |
| 13 | + default: '' |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +env: |
| 23 | + PROJECT: 'Text-Grab' |
| 24 | + PROJECT_PATH: 'Text-Grab/Text-Grab.csproj' |
| 25 | + TEST_PATH: 'Tests/Tests.csproj' |
| 26 | + BUILD_X64: 'bld/x64' |
| 27 | + BUILD_X64_SC: 'bld/x64/Text-Grab-Self-Contained' |
| 28 | + BUILD_ARM64: 'bld/arm64' |
| 29 | + BUILD_ARM64_SC: 'bld/arm64/Text-Grab-Self-Contained' |
| 30 | + |
| 31 | +jobs: |
| 32 | + build: |
| 33 | + runs-on: windows-latest |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v5 |
| 36 | + |
| 37 | + - name: Setup .NET |
| 38 | + uses: actions/setup-dotnet@v5 |
| 39 | + with: |
| 40 | + dotnet-version: '9.0.x' |
| 41 | + |
| 42 | + - name: Install dependencies |
| 43 | + run: dotnet restore ${{ env.PROJECT_PATH }} |
| 44 | + |
| 45 | + - name: Run tests |
| 46 | + run: dotnet test ${{ env.TEST_PATH }} -r win-x64 |
| 47 | + |
| 48 | + - name: Compute build version, archive paths, and release metadata |
| 49 | + id: compute |
| 50 | + shell: pwsh |
| 51 | + run: | |
| 52 | + $version = Get-Date -Format 'yyyy-MM-dd' |
| 53 | + $archiveX64SC = "${{ env.BUILD_X64 }}/${{ env.PROJECT }}-x64-Self-Contained-$version.zip" |
| 54 | + $archiveArm64SC = "${{ env.BUILD_ARM64 }}/${{ env.PROJECT }}-Self-Contained-$version.zip" |
| 55 | +
|
| 56 | + $tag = "${{ github.event.inputs.tag }}" |
| 57 | + if ([string]::IsNullOrWhiteSpace($tag)) { $tag = "v${{ github.run_number }}" } |
| 58 | +
|
| 59 | + $name = "${{ github.event.inputs.name }}" |
| 60 | + if ([string]::IsNullOrWhiteSpace($name)) { $name = "Text Grab $tag" } |
| 61 | +
|
| 62 | + echo "version=$version" >> $env:GITHUB_OUTPUT |
| 63 | + echo "archive_x64_sc=$archiveX64SC" >> $env:GITHUB_OUTPUT |
| 64 | + echo "archive_arm64_sc=$archiveArm64SC" >> $env:GITHUB_OUTPUT |
| 65 | + echo "release_tag=$tag" >> $env:GITHUB_OUTPUT |
| 66 | + echo "release_name=$name" >> $env:GITHUB_OUTPUT |
| 67 | +
|
| 68 | + - name: Clean build directories |
| 69 | + shell: pwsh |
| 70 | + run: | |
| 71 | + if (Test-Path '${{ env.BUILD_X64 }}') { Remove-Item '${{ env.BUILD_X64 }}' -Recurse -Force } |
| 72 | + if (Test-Path '${{ env.BUILD_ARM64 }}') { Remove-Item '${{ env.BUILD_ARM64 }}' -Recurse -Force } |
| 73 | + New-Item -ItemType Directory -Path '${{ env.BUILD_X64 }}' -Force | Out-Null |
| 74 | + New-Item -ItemType Directory -Path '${{ env.BUILD_ARM64 }}' -Force | Out-Null |
| 75 | +
|
| 76 | + - name: Build x64 framework-dependent |
| 77 | + run: >- |
| 78 | + dotnet publish ${{ env.PROJECT_PATH }} |
| 79 | + --runtime win-x64 |
| 80 | + --self-contained false |
| 81 | + -c Release |
| 82 | + -v minimal |
| 83 | + -o ${{ env.BUILD_X64 }} |
| 84 | + -p:EnableMsixTooling=true |
| 85 | + -p:PublishReadyToRun=false |
| 86 | + -p:PublishSingleFile=true |
| 87 | + -p:CopyOutputSymbolsToPublishDirectory=false |
| 88 | + --nologo |
| 89 | +
|
| 90 | + - name: Build x64 self-contained |
| 91 | + run: >- |
| 92 | + dotnet publish ${{ env.PROJECT_PATH }} |
| 93 | + --runtime win-x64 |
| 94 | + --self-contained true |
| 95 | + -c Release |
| 96 | + -v minimal |
| 97 | + -o ${{ env.BUILD_X64_SC }} |
| 98 | + -p:EnableMsixTooling=true |
| 99 | + -p:PublishReadyToRun=true |
| 100 | + -p:PublishSingleFile=true |
| 101 | + -p:CopyOutputSymbolsToPublishDirectory=false |
| 102 | + --nologo |
| 103 | +
|
| 104 | + - name: Build ARM64 framework-dependent |
| 105 | + run: >- |
| 106 | + dotnet publish ${{ env.PROJECT_PATH }} |
| 107 | + --runtime win-arm64 |
| 108 | + --self-contained false |
| 109 | + -c Release |
| 110 | + -v minimal |
| 111 | + -o ${{ env.BUILD_ARM64 }} |
| 112 | + -p:PublishSingleFile=true |
| 113 | + -p:EnableMsixTooling=true |
| 114 | + -p:CopyOutputSymbolsToPublishDirectory=false |
| 115 | + --nologo |
| 116 | +
|
| 117 | + - name: Build ARM64 self-contained |
| 118 | + run: >- |
| 119 | + dotnet publish ${{ env.PROJECT_PATH }} |
| 120 | + --runtime win-arm64 |
| 121 | + --self-contained true |
| 122 | + -c Release |
| 123 | + -v minimal |
| 124 | + -o ${{ env.BUILD_ARM64_SC }} |
| 125 | + -p:PublishSingleFile=true |
| 126 | + -p:EnableMsixTooling=true |
| 127 | + -p:CopyOutputSymbolsToPublishDirectory=false |
| 128 | + --nologo |
| 129 | +
|
| 130 | + - name: Rename ARM64 executables |
| 131 | + shell: pwsh |
| 132 | + run: | |
| 133 | + if (Test-Path "${{ env.BUILD_ARM64 }}/${{ env.PROJECT }}.exe") { |
| 134 | + Rename-Item "${{ env.BUILD_ARM64 }}/${{ env.PROJECT }}.exe" 'Text-Grab-arm64.exe' |
| 135 | + } |
| 136 | + if (Test-Path "${{ env.BUILD_ARM64_SC }}/${{ env.PROJECT }}.exe") { |
| 137 | + Rename-Item "${{ env.BUILD_ARM64_SC }}/${{ env.PROJECT }}.exe" 'Text-Grab-arm64.exe' |
| 138 | + } |
| 139 | +
|
| 140 | + - name: Create self-contained archives |
| 141 | + shell: pwsh |
| 142 | + run: | |
| 143 | + $x64SCZip = "${{ steps.compute.outputs.archive_x64_sc }}" |
| 144 | + $arm64SCZip = "${{ steps.compute.outputs.archive_arm64_sc }}" |
| 145 | + |
| 146 | + if (Test-Path $x64SCZip) { Remove-Item -Force $x64SCZip } |
| 147 | + if (Test-Path $arm64SCZip) { Remove-Item -Force $arm64SCZip } |
| 148 | + |
| 149 | + Compress-Archive -Path "${{ env.BUILD_X64_SC }}\*" -DestinationPath $x64SCZip -Force |
| 150 | + Compress-Archive -Path "${{ env.BUILD_ARM64_SC }}\*" -DestinationPath $arm64SCZip -Force |
| 151 | +
|
| 152 | + - name: Version information |
| 153 | + shell: pwsh |
| 154 | + run: | |
| 155 | + $exe = Join-Path '${{ env.BUILD_X64 }}' '${{ env.PROJECT }}.exe' |
| 156 | + if (Test-Path $exe) { |
| 157 | + $vi = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($exe) |
| 158 | + Write-Host "Product Version: $($vi.ProductVersion)" |
| 159 | + Write-Host "File Version: $($vi.FileVersion)" |
| 160 | + } |
| 161 | +
|
| 162 | + - name: Upload build artifact (x64 framework-dependent) |
| 163 | + uses: actions/upload-artifact@v4 |
| 164 | + with: |
| 165 | + name: Text-Grab-win-x64-framework-dependent |
| 166 | + path: ${{ env.BUILD_X64 }} |
| 167 | + |
| 168 | + - name: Upload build artifact (x64 self-contained) |
| 169 | + uses: actions/upload-artifact@v4 |
| 170 | + with: |
| 171 | + name: Text-Grab-win-x64-self-contained |
| 172 | + path: ${{ steps.compute.outputs.archive_x64_sc }} |
| 173 | + |
| 174 | + - name: Upload build artifact (ARM64 framework-dependent) |
| 175 | + uses: actions/upload-artifact@v4 |
| 176 | + with: |
| 177 | + name: Text-Grab-win-arm64-framework-dependent |
| 178 | + path: ${{ env.BUILD_ARM64 }} |
| 179 | + |
| 180 | + - name: Upload build artifact (ARM64 self-contained) |
| 181 | + uses: actions/upload-artifact@v4 |
| 182 | + with: |
| 183 | + name: Text-Grab-win-arm64-self-contained |
| 184 | + path: ${{ steps.compute.outputs.archive_arm64_sc }} |
| 185 | + |
| 186 | + - name: Create draft GitHub release and upload assets |
| 187 | + uses: softprops/action-gh-release@v2 |
| 188 | + env: |
| 189 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 190 | + with: |
| 191 | + tag_name: ${{ steps.compute.outputs.release_tag }} |
| 192 | + name: ${{ steps.compute.outputs.release_name }} |
| 193 | + target_commitish: ${{ github.sha }} |
| 194 | + draft: true |
| 195 | + prerelease: true |
| 196 | + generate_release_notes: true |
| 197 | + fail_on_unmatched_files: true |
| 198 | + files: | |
| 199 | + ${{ steps.compute.outputs.archive_x64_sc }} |
| 200 | + ${{ steps.compute.outputs.archive_arm64_sc }} |
0 commit comments