name: Build Windows release on: workflow_call: inputs: version: description: 'Release version (git tag), e.g. 1.18.4' type: string required: false ref: description: 'Git ref to check out and build' type: string required: false draft_tag: description: 'Draft GitHub release tag to attach the asset to (e.g. untagged-xxxx). Empty = skip upload.' type: string required: false secrets: GH_TOKEN: required: false workflow_dispatch: inputs: ref: description: 'Git ref to check out and build' type: string required: false jobs: build-windows: runs-on: windows-latest steps: - name: Checkout repository uses: actions/checkout@v4 with: ref: ${{ inputs.ref || github.ref }} - name: Set up Rust toolchain (MSVC) uses: dtolnay/rust-toolchain@stable with: targets: x86_64-pc-windows-msvc - name: Cache cargo build uses: Swatinem/rust-cache@v2 - name: Build (cargo release) shell: pwsh run: cargo build --release --bin app - name: Prepare artifact zip id: prepare_artifact shell: pwsh env: RELEASE_VERSION: ${{ inputs.version }} run: | $tag = $env:RELEASE_VERSION if (-not $tag) { $tag = $env:GITHUB_SHA } $exe = "target\release\app.exe" if (-not (Test-Path $exe)) { Write-Error "Built binary $exe not found in target/release"; exit 1 } $outDir = "artifact" New-Item -ItemType Directory -Path $outDir -Force | Out-Null # Ship under the package name, not the internal bin name "app". Copy-Item -Path $exe -Destination "$outDir\portabase-agent.exe" $zipName = "windows-release-$tag.zip" if (Test-Path $zipName) { Remove-Item $zipName } Compress-Archive -Path "$outDir\*" -DestinationPath $zipName -Force "zip=$zipName" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append - name: Upload build artifact uses: actions/upload-artifact@v4 with: name: windows-release path: ${{ steps.prepare_artifact.outputs.zip }} - name: Attach asset to draft release if: ${{ inputs.draft_tag != '' }} shell: pwsh env: GH_TOKEN: ${{ secrets.GH_TOKEN }} run: | gh release upload "${{ inputs.draft_tag }}" "${{ steps.prepare_artifact.outputs.zip }}" --clobber