|
| 1 | +name: Windows Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + payload_url: |
| 7 | + description: Zip URL containing runtime/ and modules/. |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + payload_sha256: |
| 11 | + description: Optional SHA-256 for the payload zip. |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + tag_name: |
| 15 | + description: Optional tag to publish as a draft GitHub release, for example v0.1.0. |
| 16 | + required: false |
| 17 | + type: string |
| 18 | + create_github_release: |
| 19 | + description: Create a draft GitHub release from the generated installer. |
| 20 | + required: true |
| 21 | + default: false |
| 22 | + type: boolean |
| 23 | + prerelease: |
| 24 | + description: Mark the GitHub release as prerelease. |
| 25 | + required: true |
| 26 | + default: false |
| 27 | + type: boolean |
| 28 | + |
| 29 | +permissions: |
| 30 | + contents: write |
| 31 | + |
| 32 | +jobs: |
| 33 | + windows-installer: |
| 34 | + name: Build Windows x64 installer |
| 35 | + runs-on: windows-latest |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Checkout |
| 39 | + uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - name: Setup Bun |
| 42 | + uses: oven-sh/setup-bun@v2 |
| 43 | + |
| 44 | + - name: Install dependencies |
| 45 | + run: bun install --frozen-lockfile |
| 46 | + |
| 47 | + - name: Validate GitHub release input |
| 48 | + if: ${{ inputs.create_github_release && inputs.tag_name == '' }} |
| 49 | + shell: pwsh |
| 50 | + run: throw "tag_name is required when create_github_release is true." |
| 51 | + |
| 52 | + - name: Download release payload |
| 53 | + if: ${{ inputs.payload_url != '' }} |
| 54 | + shell: pwsh |
| 55 | + run: | |
| 56 | + Invoke-WebRequest -Uri "${{ inputs.payload_url }}" -OutFile payload.zip |
| 57 | +
|
| 58 | + if ("${{ inputs.payload_sha256 }}" -ne "") { |
| 59 | + $actual = (Get-FileHash payload.zip -Algorithm SHA256).Hash.ToLowerInvariant() |
| 60 | + $expected = "${{ inputs.payload_sha256 }}".ToLowerInvariant() |
| 61 | + if ($actual -ne $expected) { |
| 62 | + throw "Payload SHA-256 mismatch. Expected $expected, got $actual." |
| 63 | + } |
| 64 | + } |
| 65 | +
|
| 66 | + New-Item -ItemType Directory -Force -Path .payload | Out-Null |
| 67 | + Expand-Archive payload.zip -DestinationPath .payload -Force |
| 68 | +
|
| 69 | + $payloadRoot = Resolve-Path .payload |
| 70 | + if (!(Test-Path (Join-Path $payloadRoot "runtime")) -or !(Test-Path (Join-Path $payloadRoot "modules"))) { |
| 71 | + $candidate = Get-ChildItem .payload -Directory | Where-Object { |
| 72 | + (Test-Path (Join-Path $_.FullName "runtime")) -and (Test-Path (Join-Path $_.FullName "modules")) |
| 73 | + } | Select-Object -First 1 |
| 74 | +
|
| 75 | + if ($null -eq $candidate) { |
| 76 | + throw "Payload zip must contain runtime/ and modules/ at its root or one directory below the root." |
| 77 | + } |
| 78 | +
|
| 79 | + $payloadRoot = $candidate.FullName |
| 80 | + } |
| 81 | +
|
| 82 | + if (Test-Path runtime) { |
| 83 | + Remove-Item runtime -Recurse -Force |
| 84 | + } |
| 85 | + if (Test-Path modules) { |
| 86 | + Remove-Item modules -Recurse -Force |
| 87 | + } |
| 88 | +
|
| 89 | + Move-Item (Join-Path $payloadRoot "runtime") runtime |
| 90 | + Move-Item (Join-Path $payloadRoot "modules") modules |
| 91 | +
|
| 92 | + - name: Check release payload |
| 93 | + run: bun run release:check |
| 94 | + |
| 95 | + - name: Build installer |
| 96 | + run: bun run release:win |
| 97 | + |
| 98 | + - name: Upload installer artifact |
| 99 | + uses: actions/upload-artifact@v4 |
| 100 | + with: |
| 101 | + name: maibot-onekey-windows-x64 |
| 102 | + path: | |
| 103 | + release/*.exe |
| 104 | + release/*.blockmap |
| 105 | + release/*.yml |
| 106 | + if-no-files-found: error |
| 107 | + |
| 108 | + - name: Create draft GitHub release |
| 109 | + if: ${{ inputs.create_github_release && inputs.tag_name != '' }} |
| 110 | + env: |
| 111 | + GH_TOKEN: ${{ github.token }} |
| 112 | + TAG_NAME: ${{ inputs.tag_name }} |
| 113 | + shell: pwsh |
| 114 | + run: | |
| 115 | + $assets = Get-ChildItem release -File | Where-Object { |
| 116 | + $_.Name -match '\.(exe|blockmap|yml)$' |
| 117 | + } | Select-Object -ExpandProperty FullName |
| 118 | +
|
| 119 | + if ($assets.Count -eq 0) { |
| 120 | + throw "No release assets found." |
| 121 | + } |
| 122 | +
|
| 123 | + $args = @("release", "create", $env:TAG_NAME) |
| 124 | + $args += $assets |
| 125 | + $args += @("--title", $env:TAG_NAME, "--generate-notes", "--draft") |
| 126 | +
|
| 127 | + if ("${{ inputs.prerelease }}" -eq "true") { |
| 128 | + $args += "--prerelease" |
| 129 | + } |
| 130 | +
|
| 131 | + gh @args |
0 commit comments