|
| 1 | +#!/usr/bin/env -S deno run --allow-all |
| 2 | +import { exec, execInherit, cdProjectRoot, cdCurrent } from "./lib.ts" |
| 3 | + |
| 4 | +const main = async () => { |
| 5 | + await cdProjectRoot() |
| 6 | + Deno.chdir("./ci/steps") |
| 7 | + |
| 8 | + const goos = Deno.env.get("GOOS") |
| 9 | + const goarch = Deno.env.get("GOARCH") ?? "" |
| 10 | + |
| 11 | + const tag = await exec("git describe --tags") |
| 12 | + console.info(`--- building coder-cli for ${goos}-${goarch}`) |
| 13 | + |
| 14 | + const dir = await Deno.makeTempDir() |
| 15 | + |
| 16 | + await execInherit( |
| 17 | + `go build -ldflags "-X cdr.dev/coder-cli/internal/version.Version=${tag}" -o "${dir}/coder" ../../cmd/coder` |
| 18 | + ) |
| 19 | + |
| 20 | + await Deno.copyFile("../gon.json", `${dir}/gon.json`) |
| 21 | + Deno.chdir(dir) |
| 22 | + switch (goos) { |
| 23 | + case "darwin": |
| 24 | + await packageMacOS(goos, goarch, tag) |
| 25 | + break |
| 26 | + case "windows": |
| 27 | + await packageWindows(goos, goarch, tag) |
| 28 | + break |
| 29 | + case "linux": |
| 30 | + await packageLinux(goos, goarch, tag) |
| 31 | + break |
| 32 | + default: |
| 33 | + throw Error(`unknown GOOS env var: ${goos}`) |
| 34 | + } |
| 35 | + cdCurrent() |
| 36 | + Deno.remove(dir, { recursive: true }) |
| 37 | +} |
| 38 | + |
| 39 | +const packageWindows = async (goos: string, goarch: string, tag: string) => { |
| 40 | + const artifact = `coder-cli-${goos}-${goarch}-${tag}.zip` |
| 41 | + await Deno.rename("coder", "coder.exe") |
| 42 | + await execInherit(`zip ${artifact} coder.exe`) |
| 43 | +} |
| 44 | + |
| 45 | +const packageLinux = async (goos: string, goarch: string, tag: string) => { |
| 46 | + const artifact = `coder-cli-${goos}-${goarch}-${tag}.tar.gz` |
| 47 | + await execInherit(`tar -czf ${artifact} coder`) |
| 48 | +} |
| 49 | + |
| 50 | +const packageMacOS = async (goos: string, goarch: string, tag: string) => { |
| 51 | + // cp ../gon.json $tmpdir/gon.json |
| 52 | + const artifact = `coder-cli-${goos}-${goarch}-${tag}.zip` |
| 53 | + await execInherit("gon -log-level debug ./gon.json") |
| 54 | + await Deno.rename("coder.zip", artifact) |
| 55 | +} |
| 56 | + |
| 57 | +await main() |
0 commit comments