add build.cores yaml key to control min-required build machine

This commit is contained in:
Jacob Heider 2023-01-12 16:43:08 -05:00 committed by Jacob Heider
parent a3bb5da37d
commit b8ca94a587
3 changed files with 73 additions and 1 deletions

View file

@ -11,14 +11,34 @@ env:
TEA_PANTRY_PATH: ${{ github.workspace }}/pantry TEA_PANTRY_PATH: ${{ github.workspace }}/pantry
jobs: jobs:
check-core-sizes:
runs-on: ubuntu-latest
outputs:
gha-linux-build-size: ${{ env.GHA_LINUX_BUILD_SIZE }}
steps:
- name: co pantry
uses: actions/checkout@v3
with:
path: pantry
repository: teaxyz/pantry.core
- uses: teaxyz/setup@v0
with:
# necessary because we currently require a `.git` directory
srcroot: ~/pantry
- run: ./scripts/check-core-sizes.ts ${{ inputs.projects }}
working-directory: pantry
build: build:
runs-on: ${{ matrix.platform.os }} runs-on: ${{ matrix.platform.os }}
needs: [check-core-sizes]
strategy: strategy:
matrix: matrix:
platform: platform:
- os: macos-11 - os: macos-11
name: darwin+x86-64 name: darwin+x86-64
- os: ubuntu-latest-4-cores - os: ${{ needs.check-core-sizes.outputs.gha-linux-build-size }}
name: linux+x86-64 name: linux+x86-64
container: container:
image: debian:buster-slim image: debian:buster-slim

View file

@ -18,6 +18,7 @@ runtime:
DENO_NO_UPDATE_CHECK: "true" DENO_NO_UPDATE_CHECK: "true"
build: build:
cores: 4
script: | script: |
# https://github.com/denoland/deno/issues/15596 -- reported fixed in 1.25.3 # https://github.com/denoland/deno/issues/15596 -- reported fixed in 1.25.3
if test {{ version.major }} -eq 1 -a {{ version.minor }} -eq 25 -a {{ version.patch }} -lt 3; then if test {{ version.major }} -eq 1 -a {{ version.minor }} -eq 25 -a {{ version.patch }} -lt 3; then

51
scripts/check-core-sizes.ts Executable file
View file

@ -0,0 +1,51 @@
#!/usr/bin/env -S tea -E
/*---
args:
- deno
- run
- --allow-read
- --allow-env
- --allow-write
- --import-map={{ srcroot }}/import-map.json
---*/
import { usePantry } from "hooks"
import * as ARGV from "./utils/args.ts"
const pantry = usePantry()
const pkgs = await ARGV.toArray(ARGV.pkgs())
let coreSize = 2
for (const pkg of pkgs) {
const yml = await pantry.getYAML(pkg).parse()
if (yml?.build?.cores) {
coreSize = Math.max(yml.build.cores, coreSize)
}
}
const output = `GHA_LINUX_BUILD_SIZE=${imageName(coreSize)}\n`
Deno.stdout.write(new TextEncoder().encode(output))
if (Deno.env.get("GITHUB_ENV")) {
const envFile = Deno.env.get("GITHUB_ENV")!
await Deno.writeTextFile(envFile, output, { append: true})
}
function imageName(size: number) {
switch (size) {
case 0:
case 1:
case 2:
return "ubuntu-latest"
case 4:
case 8:
case 16:
return `ubuntu-latest-${size}-cores`
default:
throw new Error("Invalid core size")
}
}