Skip to content

Commit c4df7f6

Browse files
committed
ci: add beta desktop runtime build
1 parent c1260f5 commit c4df7f6

1 file changed

Lines changed: 216 additions & 0 deletions

File tree

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
name: Beta Desktop Runtime
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
beta_version:
7+
description: "Beta version to stamp into the desktop app and runtime"
8+
required: true
9+
default: "0.5.6-beta.0"
10+
type: string
11+
retention_days:
12+
description: "Days to keep downloadable Actions artifacts"
13+
required: true
14+
default: "14"
15+
type: string
16+
push:
17+
branches:
18+
- codex/wsl-runtime-followup
19+
20+
concurrency:
21+
group: beta-desktop-runtime-${{ github.ref }}
22+
cancel-in-progress: false
23+
24+
env:
25+
DEFAULT_BETA_VERSION: "0.5.6-beta.0"
26+
RUNTIME_ARTIFACT_BRANCH: beta-artifacts
27+
28+
jobs:
29+
build-windows:
30+
name: Build Windows desktop beta
31+
runs-on: windows-latest
32+
permissions:
33+
contents: write
34+
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@v4
38+
with:
39+
fetch-depth: 0
40+
41+
- name: Setup pnpm
42+
uses: pnpm/action-setup@v4
43+
with:
44+
version: 10.33.2
45+
run_install: false
46+
47+
- name: Setup Node.js
48+
uses: actions/setup-node@v4
49+
with:
50+
node-version: "24"
51+
cache: "pnpm"
52+
53+
- name: Install dependencies
54+
run: pnpm install --frozen-lockfile
55+
56+
- name: Resolve beta metadata
57+
id: beta
58+
shell: pwsh
59+
env:
60+
INPUT_BETA_VERSION: ${{ github.event.inputs.beta_version }}
61+
run: |
62+
$version = $env:INPUT_BETA_VERSION
63+
if ([string]::IsNullOrWhiteSpace($version)) {
64+
$version = $env:DEFAULT_BETA_VERSION
65+
}
66+
$branchSlug = $env:GITHUB_REF_NAME -replace '[^A-Za-z0-9._-]', '-'
67+
68+
"version=$version" >> $env:GITHUB_OUTPUT
69+
"branch_slug=$branchSlug" >> $env:GITHUB_OUTPUT
70+
71+
- name: Stamp beta package versions
72+
shell: pwsh
73+
env:
74+
BETA_VERSION: ${{ steps.beta.outputs.version }}
75+
run: |
76+
$script = @'
77+
import { readFile, writeFile } from "node:fs/promises";
78+
79+
const version = process.env.BETA_VERSION;
80+
if (!version) {
81+
throw new Error("BETA_VERSION is required");
82+
}
83+
84+
for (const file of ["packages/cli/package.json", "packages/desktop/package.json"]) {
85+
const manifest = JSON.parse(await readFile(file, "utf8"));
86+
manifest.version = version;
87+
await writeFile(file, `${JSON.stringify(manifest, null, 2)}\n`);
88+
}
89+
'@
90+
node --input-type=module -e $script
91+
92+
- name: Build web assets
93+
run: pnpm build:web
94+
95+
- name: Build desktop app and embedded runtime
96+
run: pnpm build:desktop
97+
98+
- name: Package beta runtime artifacts
99+
id: package_runtime
100+
shell: pwsh
101+
env:
102+
BETA_VERSION: ${{ steps.beta.outputs.version }}
103+
BRANCH_SLUG: ${{ steps.beta.outputs.branch_slug }}
104+
run: |
105+
$platform = node -p "process.platform"
106+
$arch = node -p "process.arch"
107+
$outDir = "packages/desktop/dist/beta"
108+
$runtimeDir = "packages/desktop/dist/runtime/embedded"
109+
$runtimeZipName = "coder-studio-runtime-$env:BETA_VERSION-$platform-$arch.zip"
110+
$runtimeZipPath = Join-Path $outDir $runtimeZipName
111+
$runtimeIndexPath = Join-Path $outDir "runtime-release-index.json"
112+
113+
New-Item -ItemType Directory -Force -Path $outDir | Out-Null
114+
Compress-Archive -Path (Join-Path $runtimeDir "*") -DestinationPath $runtimeZipPath -Force
115+
116+
$runtimeZip = Get-Item $runtimeZipPath
117+
$checksum = (Get-FileHash $runtimeZipPath -Algorithm SHA256).Hash.ToLowerInvariant()
118+
$publishedAt = (Get-Date).ToUniversalTime().ToString("o")
119+
$runtimeArtifactPath = "desktop-runtime/$env:BRANCH_SLUG/$env:BETA_VERSION/$runtimeZipName"
120+
$runtimeArtifactUrl = "https://raw.githubusercontent.com/$env:GITHUB_REPOSITORY/$env:RUNTIME_ARTIFACT_BRANCH/$runtimeArtifactPath"
121+
$runtimeIndexUrl = "https://raw.githubusercontent.com/$env:GITHUB_REPOSITORY/$env:RUNTIME_ARTIFACT_BRANCH/desktop-runtime/$env:BRANCH_SLUG/runtime-release-index.json"
122+
123+
$index = @(
124+
[ordered]@{
125+
version = $env:BETA_VERSION
126+
platform = $platform
127+
arch = $arch
128+
artifactUrl = $runtimeArtifactUrl
129+
checksumSha256 = $checksum
130+
artifactSize = $runtimeZip.Length
131+
publishedAt = $publishedAt
132+
minAppVersion = $env:BETA_VERSION
133+
notes = "Beta runtime built from $env:GITHUB_SHA on $env:GITHUB_REF_NAME"
134+
}
135+
)
136+
137+
$index | ConvertTo-Json -Depth 5 | Set-Content -Path $runtimeIndexPath -Encoding UTF8
138+
139+
"runtime_zip_path=$runtimeZipPath" >> $env:GITHUB_OUTPUT
140+
"runtime_index_path=$runtimeIndexPath" >> $env:GITHUB_OUTPUT
141+
"runtime_index_url=$runtimeIndexUrl" >> $env:GITHUB_OUTPUT
142+
143+
- name: Publish beta runtime index
144+
shell: pwsh
145+
env:
146+
BETA_VERSION: ${{ steps.beta.outputs.version }}
147+
BRANCH_SLUG: ${{ steps.beta.outputs.branch_slug }}
148+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
149+
RUNTIME_ZIP_PATH: ${{ steps.package_runtime.outputs.runtime_zip_path }}
150+
RUNTIME_INDEX_PATH: ${{ steps.package_runtime.outputs.runtime_index_path }}
151+
run: |
152+
$stageDir = Join-Path $env:RUNNER_TEMP "coder-studio-beta-artifacts"
153+
$repoUrl = "https://x-access-token:$env:GITHUB_TOKEN@github.com/$env:GITHUB_REPOSITORY.git"
154+
155+
Remove-Item -Recurse -Force $stageDir -ErrorAction SilentlyContinue
156+
git clone --depth 1 --branch $env:RUNTIME_ARTIFACT_BRANCH $repoUrl $stageDir
157+
if ($LASTEXITCODE -ne 0) {
158+
Remove-Item -Recurse -Force $stageDir -ErrorAction SilentlyContinue
159+
New-Item -ItemType Directory -Force -Path $stageDir | Out-Null
160+
git -C $stageDir init
161+
git -C $stageDir checkout --orphan $env:RUNTIME_ARTIFACT_BRANCH
162+
git -C $stageDir remote add origin $repoUrl
163+
}
164+
165+
git -C $stageDir config user.name "github-actions[bot]"
166+
git -C $stageDir config user.email "41898282+github-actions[bot]@users.noreply.github.com"
167+
168+
$runtimeTargetDir = Join-Path $stageDir "desktop-runtime/$env:BRANCH_SLUG/$env:BETA_VERSION"
169+
$indexTargetDir = Join-Path $stageDir "desktop-runtime/$env:BRANCH_SLUG"
170+
New-Item -ItemType Directory -Force -Path $runtimeTargetDir | Out-Null
171+
New-Item -ItemType Directory -Force -Path $indexTargetDir | Out-Null
172+
173+
Copy-Item -Force $env:RUNTIME_ZIP_PATH $runtimeTargetDir
174+
Copy-Item -Force $env:RUNTIME_INDEX_PATH (Join-Path $indexTargetDir "runtime-release-index.json")
175+
176+
$metadata = [ordered]@{
177+
version = $env:BETA_VERSION
178+
sourceRef = $env:GITHUB_REF_NAME
179+
sourceSha = $env:GITHUB_SHA
180+
runId = $env:GITHUB_RUN_ID
181+
publishedAt = (Get-Date).ToUniversalTime().ToString("o")
182+
}
183+
$metadata | ConvertTo-Json -Depth 5 | Set-Content -Path (Join-Path $indexTargetDir "build.json") -Encoding UTF8
184+
185+
git -C $stageDir add "desktop-runtime/$env:BRANCH_SLUG"
186+
$changes = git -C $stageDir status --porcelain
187+
if ([string]::IsNullOrWhiteSpace($changes)) {
188+
Write-Host "No runtime artifact changes to publish."
189+
} else {
190+
git -C $stageDir commit -m "publish beta runtime $env:BETA_VERSION from $($env:GITHUB_SHA.Substring(0, 7))"
191+
git -C $stageDir push origin "HEAD:$env:RUNTIME_ARTIFACT_BRANCH"
192+
}
193+
194+
- name: Upload desktop installer artifact
195+
uses: actions/upload-artifact@v4
196+
with:
197+
name: coder-studio-desktop-${{ steps.beta.outputs.version }}-win32-x64
198+
path: packages/desktop/dist/release/**
199+
retention-days: ${{ github.event.inputs.retention_days || '14' }}
200+
if-no-files-found: error
201+
202+
- name: Upload runtime artifact bundle
203+
uses: actions/upload-artifact@v4
204+
with:
205+
name: coder-studio-runtime-${{ steps.beta.outputs.version }}-win32-x64
206+
path: |
207+
${{ steps.package_runtime.outputs.runtime_zip_path }}
208+
${{ steps.package_runtime.outputs.runtime_index_path }}
209+
retention-days: ${{ github.event.inputs.retention_days || '14' }}
210+
if-no-files-found: error
211+
212+
- name: Print beta runtime config
213+
shell: pwsh
214+
run: |
215+
Write-Host "Runtime release index URL:"
216+
Write-Host "${{ steps.package_runtime.outputs.runtime_index_url }}"

0 commit comments

Comments
 (0)