chore(ci/preview-build): simplify PR comment to ; remove helper script artifact and files

This commit is contained in:
James Peter
2025-09-09 13:29:44 +10:00
parent ee37eca746
commit ed171971df
3 changed files with 5 additions and 230 deletions
+5 -94
View File
@@ -179,16 +179,6 @@ jobs:
path: artifacts/
compression-level: 0
- name: Upload helper scripts (once)
if: matrix.os == 'ubuntu-24.04'
uses: actions/upload-artifact@v4
with:
name: preview-helper
path: |
scripts/preview-get.sh
scripts/preview-get.ps1
compression-level: 0
comment:
name: Post Artifact Links
needs: [build]
@@ -207,96 +197,17 @@ jobs:
const marker = '<!-- preview-build:artifacts -->';
// List artifacts for this run so we can provide direct ZIP links
const artsResp = await github.rest.actions.listArtifactsForRun({ owner, repo, run_id: runId, per_page: 100 });
const artifacts = artsResp.data.artifacts || [];
// Map target triple -> friendly label
const labelFor = (name) => {
if (name.includes('x86_64-unknown-linux-musl')) return 'Linux x86_64 (musl)';
if (name.includes('aarch64-unknown-linux-musl')) return 'Linux aarch64 (musl)';
if (name.includes('x86_64-apple-darwin')) return 'macOS x86_64';
if (name.includes('aarch64-apple-darwin')) return 'macOS arm64 (Apple Silicon)';
if (name.includes('x86_64-pc-windows-msvc')) return 'Windows x86_64';
if (name.includes('preview-helper')) return 'Helper scripts';
return name;
};
// Build a list of direct artifact links (ZIP of the artifact contents)
const directLinks = artifacts
.filter(a => a.name?.startsWith('preview-'))
.map(a => `- ${labelFor(a.name)}: https://api.github.com/repos/${owner}/${repo}/actions/artifacts/${a.id}/zip`)
.join('\n');
// Single-command helper (Linux/macOS) using gh to fetch + extract + run
const ghOneLiner = [
'bash -lc "set -euo pipefail; ',
'RID=', runId, '; ',
'OS=$(uname -s); ARCH=$(uname -m); ',
'case \"$OS-$ARCH\" in ',
'Linux-x86_64) T=x86_64-unknown-linux-musl ;; ',
'Linux-aarch64|Linux-arm64) T=aarch64-unknown-linux-musl ;; ',
'Darwin-x86_64) T=x86_64-apple-darwin ;; ',
'Darwin-arm64) T=aarch64-apple-darwin ;; ',
'*) echo \"Unsupported: $OS/$ARCH\" >&2; exit 1 ;; ',
'esac; ',
'D=code-preview-$T; rm -rf \"$D\"; ',
'gh run download \"$RID\" -n preview-$T -D \"$D\" >/dev/null; ',
'cd \"$D\"; ',
'if ls code-*.zst >/dev/null 2>&1; then F=$(ls code-*.zst | head -n1); zstd -d \"$F\" -o code; chmod +x code; ./code --help; ',
'elif ls code-*.tar.gz >/dev/null 2>&1; then F=$(ls code-*.tar.gz | head -n1); B=$(tar -tzf \"$F\" | head -n1 | xargs basename); tar -xzf \"$F\"; chmod +x \"$B\"; ./\"$B\" --help; ',
'else echo \"No known artifact format found\" >&2; exit 2; fi"'
].join('');
const body = [
marker,
'### Preview Binaries',
'### Preview Build',
'',
`Artifacts are available for this PR: ${runUrl}`,
'',
'- Linux (x86_64, aarch64) — .zst and .tar.gz',
'- macOS (x86_64, arm64) — .zst and .tar.gz',
'- Windows (x86_64) — .zip',
'',
'**Quick one‑liner (Linux/macOS)**',
'',
'Option A (gh): requires `gh auth login`',
'You can run this right now! In your terminal just use:',
'```bash',
ghOneLiner,
'```',
'Option B (curl raw helper):',
'```bash',
`curl -fsSL https://raw.githubusercontent.com/${owner}/${repo}/${context.sha}/scripts/preview-get.sh | bash -s -- ${runId}`,
`code preview ${runId}`,
'```',
'This will run the version of Code we\'ve created for this issue.',
'',
'**One‑liner (Windows with gh)**',
'',
'Option A (gh): requires `gh auth login`',
'```powershell',
`$RID = ${runId}; gh run download $RID -n preview-x86_64-pc-windows-msvc -D code-preview; Set-Location code-preview; Get-ChildItem -Filter *.zip | ForEach-Object { Expand-Archive -Path $_.FullName -DestinationPath . -Force }; Start-Process .\\code-x86_64-pc-windows-msvc.exe`,
'```',
'Option B (script helper):',
'```powershell',
`iwr -useb https://raw.githubusercontent.com/${owner}/${repo}/${context.sha}/scripts/preview-get.ps1 -OutFile preview-get.ps1; .\\preview-get.ps1 -RunId ${runId}`,
'```',
'',
'**Direct artifact links**',
'',
directLinks || '_Artifacts are still processing — refresh in a minute._',
'',
'**Manual usage**',
'',
'Linux/macOS (.zst):',
'```bash',
'zstd -d code-<target>.zst -o code && chmod +x code && ./code',
'```',
'Linux/macOS (.tar.gz):',
'```bash',
'tar -xzf code-<target>.tar.gz && chmod +x code-<target> && ./code-<target>',
'```',
'Windows (.zip): unzip and run `code.exe`',
'',
'_Note: macOS may require: `xattr -d com.apple.quarantine ./code`_',
'After you run it, please comment here and let me know if it does what you need.',
marker
].join('\n');
-56
View File
@@ -1,56 +0,0 @@
param(
[Parameter(Mandatory = $true)] [string] $RunId,
[string] $Repo
)
$ErrorActionPreference = 'Stop'
if (-not $Repo) {
$Repo = if ($env:GITHUB_REPOSITORY) { $env:GITHUB_REPOSITORY } else { 'just-every/code' }
}
$parts = $Repo.Split('/')
$Owner = $parts[0]
$Name = $parts[1]
# Detect target
$arch = (Get-CimInstance Win32_Processor).Architecture
if ($arch -ne 9 -and $arch -ne 0) { # 9 = x64, 0 = x86
Write-Error "Unsupported Windows architecture: $arch"; exit 1
}
$Target = 'x86_64-pc-windows-msvc'
$Work = "code-preview-$Target"
if (Test-Path $Work) { Remove-Item -Recurse -Force $Work }
New-Item -ItemType Directory -Path $Work | Out-Null
Set-Location $Work
function Download-WithGh {
gh run download $RunId -R "$Owner/$Name" -n "preview-$Target" -D . | Out-Null
}
function Download-WithApi {
if (-not $env:GH_TOKEN) { Write-Error 'Set GH_TOKEN to a GitHub token with actions:read'; exit 2 }
$base = "https://api.github.com/repos/$Owner/$Name"
$hdrs = @{ Authorization = "Bearer $env:GH_TOKEN"; Accept = 'application/vnd.github+json' }
$arts = Invoke-RestMethod -Uri "$base/actions/runs/$RunId/artifacts?per_page=100" -Headers $hdrs
$art = $arts.artifacts | Where-Object { $_.name -eq "preview-$Target" } | Select-Object -First 1
if (-not $art) { Write-Error "Could not find artifact preview-$Target for run $RunId"; exit 3 }
Invoke-WebRequest -Uri "$base/actions/artifacts/$($art.id)/zip" -Headers $hdrs -OutFile artifact.zip
Expand-Archive -Path artifact.zip -DestinationPath . -Force
}
try {
if (Get-Command gh -ErrorAction SilentlyContinue) { Download-WithGh } else { Download-WithApi }
} catch { Download-WithApi }
# Extract and run
$zip = Get-ChildItem -Filter 'code-*.zip' | Select-Object -First 1
if ($zip) {
Expand-Archive -Path $zip.FullName -DestinationPath . -Force
}
$exe = Get-ChildItem -Filter 'code-*.exe' | Select-Object -First 1
if (-not $exe) { Write-Error 'No code executable found in artifact.'; exit 4 }
Write-Host "Ready: $($exe.FullName)"
Write-Host "Launching with --help"
Start-Process -FilePath $exe.FullName -ArgumentList '--help'
-80
View File
@@ -1,80 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
if [[ ${1:-} == "" ]]; then
echo "Usage: preview-get.sh <GITHUB_RUN_ID> [owner/repo]" >&2
echo "Example: preview-get.sh 123456789 just-every/code" >&2
exit 2
fi
RID="$1"
REPO="${2:-${GITHUB_REPOSITORY:-just-every/code}}"
uname_s=$(uname -s)
uname_m=$(uname -m)
case "${uname_s}-${uname_m}" in
Linux-x86_64) T="x86_64-unknown-linux-musl" ;;
Linux-aarch64|Linux-arm64) T="aarch64-unknown-linux-musl" ;;
Darwin-x86_64) T="x86_64-apple-darwin" ;;
Darwin-arm64) T="aarch64-apple-darwin" ;;
*) echo "Unsupported platform: ${uname_s}/${uname_m}" >&2; exit 1 ;;
esac
owner="${REPO%%/*}"
repo="${REPO##*/}"
workdir="code-preview-${T}"
rm -rf "$workdir" && mkdir -p "$workdir"
cd "$workdir"
download_with_gh() {
gh run download "$RID" -R "$owner/$repo" -n "preview-$T" -D . >/dev/null
}
download_with_api() {
: "${GH_TOKEN:?Set GH_TOKEN to a GitHub token with actions:read}"
api="https://api.github.com/repos/${owner}/${repo}"
arts_json=$(curl -fsSL -H "Authorization: Bearer $GH_TOKEN" -H 'Accept: application/vnd.github+json' "$api/actions/runs/$RID/artifacts?per_page=100")
art_id=$(printf '%s' "$arts_json" | awk -v name="preview-$T" -v RS=',\{|' -v FS=',' '/"name":"[^"\n]*"/ { if ($0 ~ name) { if (match($0, /"id":[0-9]+/)) { id=substr($0,RSTART+5,RLENGTH-5); print id; exit } } }')
if [[ -z "${art_id:-}" ]]; then
echo "Could not find artifact preview-$T for run $RID" >&2; exit 3
fi
curl -fSL -H "Authorization: Bearer $GH_TOKEN" "$api/actions/artifacts/$art_id/zip" -o artifact.zip
unzip -q artifact.zip
}
if command -v gh >/dev/null 2>&1; then
download_with_gh || download_with_api
else
download_with_api
fi
# Prefer .tar.gz on Unix (no zstd dependency)
if ls code-*.tar.gz >/dev/null 2>&1; then
tgz=$(ls code-*.tar.gz | head -n1)
bname=$(tar -tzf "$tgz" | head -n1 | xargs basename)
tar -xzf "$tgz"
chmod +x "$bname"
echo "Ready: $(pwd)/$bname"
echo "Running: ./$bname --help"
./"$bname" --help || true
exit 0
fi
if ls code-*.zst >/dev/null 2>&1; then
zst=$(ls code-*.zst | head -n1)
if ! command -v zstd >/dev/null 2>&1; then
echo "Found Zstandard archive but 'zstd' is not installed. Install zstd or re-run with gh to auto-extract." >&2
exit 4
fi
zstd -d "$zst" -o code
chmod +x code
echo "Ready: $(pwd)/code"
echo "Running: ./code --help"
./code --help || true
exit 0
fi
echo "No recognized artifact content found." >&2
exit 5