Skip to content

Commit

Permalink
attempt to generate the matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Dec 10, 2023
1 parent 1e1aa02 commit b5f7dc2
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 43 deletions.
3 changes: 2 additions & 1 deletion .github/deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"imports": {
"pkgx": "https://deno.land/x/libpkgx@v0.15.1/mod.ts",
"pkgx/": "https://deno.land/x/libpkgx@v0.15.1/src/"
"pkgx/": "https://deno.land/x/libpkgx@v0.15.1/src/",
"is-what": "https://deno.land/x/is_what@v4.1.15/src/index.ts"
}
}
76 changes: 76 additions & 0 deletions .github/scripts/get-matrix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env -S pkgx deno run -A

import { hooks, utils } from "pkgx"
import { isString, isArray } from "is-what"

const pkg = utils.pkg.parse(Deno.args[0])

const rv = {} as Record<string, any>
for (const platform of await get_platforms(pkg)) {
const key = platform.replace('/', '+')
rv[key] = get_matrix(platform)
}

const ghout = Deno.env.get("GITHUB_OUTPUT")
if (ghout) {
const json = JSON.stringify(Object.values(rv))
Deno.writeTextFileSync(ghout, `matrix=${json}`, {append: true})
} else {
const json = JSON.stringify(rv, null, 2)
console.log(json)
}

///////////////////////////////////////////////////////////////////////

//TODO should be in libpkgx!
async function get_platforms(pkg: {project: string}) {
let { platforms } = await hooks.usePantry().project(pkg).yaml()
if (!platforms) return ["linux/x86-64", "linux/aarch64", "darwin/x86-64", "darwin/aarch64"]
if (isString(platforms)) platforms = [platforms]
if (!isArray(platforms)) throw new Error(`invalid platform node: ${platforms}`)
const rv = []
for (const platform of platforms) {
if (platform.match(/^(linux|darwin)\/(aarch64|x86-64)$/)) rv.push(platform)
else if (platform.match(/^(linux|darwin)$/)) rv.push(`${platform}/x86-64`, `${platform}/aarch64`)
else throw new Error(`invalid platform: ${platform}`)
}
return rv
}

function get_matrix(platform: string) {
const name = platform.replace('/', '+')
switch (platform) {
case 'darwin/aarch64': {
const os = ["self-hosted", "macOS", "ARM64"]
return {
os, name,
"test-os": [os],
"test-container": [null],
tinyname: "²"
}}
case 'darwin/x86-64': {
const os = ["self-hosted", "macOS", "X64"]
return {
os, name,
"test-os": ["macos-11", "macos-12"],
"test-container": [null],
tinyname: "x64"
}}
case 'linux/x86-64': {
const os = {group: "linux-x86-64"}
return {
os, name,
container: "debian:buster-slim",
"test-os": [os],
"test-container": ["debian:buster-slim", "ubuntu", "archlinux"],
tinyname: "Lnx·x64"
}}
case 'linux/aarch64': {
const os = ["self-hosted", "linux", "ARM64"]
return {
os, name,
"test-os": [os],
"test-container": [null],
tinyname: "Lnx·ARM64"
}}}
}
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
get-projects:
runs-on: ubuntu-latest
outputs:
diff: ${{ steps.diff.outputs.diff }}
projects: ${{ steps.diff.outputs.diff }}
steps:
- uses: actions/checkout@v4
- uses: technote-space/get-diff-action@v6
Expand All @@ -29,7 +29,7 @@ jobs:
done
echo "diff=$RESULT" >> $GITHUB_OUTPUT
deploy:
pkgit:
needs: get-projects
uses: ./.github/workflows/new-version.yml
with:
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/ci-squared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
pull_request:
paths:
- .github/workflows/pkg.yml
- .github/workflows/pkger.yml
- .github/workflows/pkg-for-platform.yml
- .github/workflows/ci-squared.yml

concurrency:
Expand All @@ -14,8 +14,14 @@ concurrency:

jobs:
ci:
name: ci²
uses: ./.github/workflows/pkg.yml
strategy:
matrix:
pkg:
- r-wos.org/gti
- alsa-project.org/alsa-lib
with:
pkg: r-wos.org/gti
# upload: false
pkg: ${{ matrix.pkg }}
upload: false
secrets: inherit
24 changes: 18 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
diff:
runs-on: ubuntu-latest
outputs:
diff: ${{ steps.diff.outputs.diff }}
pkgs: ${{ steps.diff.outputs.pkgs }}
steps:
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
Expand All @@ -28,22 +28,34 @@ jobs:
- id: diff
run: |
for x in ${{ steps.get-diff.outputs.diff }}; do
y=$(echo $x | sed 's#projects/\(.*\)/package.yml#\1#')
y=$(echo $x | sed 's#projects/\(.*\)/[^/]*#\1#')
RESULT="$RESULT $y"
done
echo "diff=$RESULT" >> $GITHUB_OUTPUT
if [ -n "$RESULT" ]; then
RESULT="$(echo $RESULT | jq -R -s -c 'split(" ")')"
else
RESULT='["zlib.net"]'
fi
echo "pkgs=$RESULT" >> $GITHUB_OUTPUT
build:
if: ${{ needs.diff.outputs.diff }}
needs: diff
name: ci ${{ matrix.platform.name }} ${{matrix.pkg}}
strategy:
matrix:
pkg: ${{ fromJSON(needs.diff.outputs.pkgs) }}
platform:
- os: ["self-hosted", "macOS", "X64"]
name: x64
- os: ["self-hosted", "macOS", "ARM64"]
name: ²
- os: ["self-hosted", "linux", "ARM64"]
- os: ["self-hosted", "linux", "X64"]
name: Lnx·ARM64
- os: {group: "linux-x86-64"}
container: debian:buster-slim
name: Lnx·x64
runs-on: ${{ matrix.platform.os }}
container: ${{ matrix.platform.container }}
steps:
- uses: actions/checkout@v4

Expand All @@ -60,7 +72,7 @@ jobs:
- uses: pkgxdev/brewkit/build@v1
id: build
with:
pkg: ${{ needs.diff.outputs.diff }}
pkg: ${{ matrix.pkg }}

- uses: pkgxdev/brewkit/audit@v1
if: steps.build.outputs.pkgspec
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/new-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
echo "pkgs=$var" >> $GITHUB_OUTPUT
id: divide
deploy:
pkgit:
needs: divide
strategy:
matrix:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name: pkger
name: pkg for platform
run-name: pkging ${{ inputs.project }} (${{ inputs.name }})

on:
workflow_call:
inputs:
name:
description: pretty name for the workflow for users
description: >
pretty name for the workflow to make GitHub Actions matrix output
more legible
required: false
type: string
os:
Expand All @@ -23,9 +25,14 @@ on:
type: boolean
default: true
test-os:
required: false
description: a JSON array of runner-names
required: true
type: string
test-container:
description: >
A JSON array of docker image names or `[null]`.
Indeed! You cannot leave this as `null` or undefined.
Sorry, GHA is not flexible enough to efficiently work around this.
required: true
type: string
secrets:
Expand Down Expand Up @@ -84,7 +91,7 @@ jobs:
PKGX_PANTRY_PATH: ${{ github.workspace }}
strategy:
matrix:
os: ${{ fromJSON(inputs.test-os || inputs.os) }}
os: ${{ fromJSON(inputs.test-os) }}
container: ${{ fromJSON(inputs.test-container) }}
runs-on: ${{ matrix.os }}
container: ${{ matrix.container }}
Expand Down
41 changes: 15 additions & 26 deletions .github/workflows/pkg.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: pkg
run-name: pkg
run-name: pkging ${{inputs.pkg}}

on:
workflow_call:
Expand All @@ -12,35 +12,24 @@ on:
default: true

jobs:
test:
get-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- uses: pkgxdev/setup@v2
- uses: actions/checkout@v4
- run: .github/scripts/get-matrix.ts ${{ inputs.pkg }}
id: matrix

pkgit:
needs: get-matrix
name: ${{matrix.platform.tinyname}}
strategy:
fail-fast: false
matrix:
platform:
- os: {group: linux-x86-64}
container: "debian:buster-slim"
test-os: [{group: linux-x86-64}]
test-container: ["debian:buster-slim", ubuntu, archlinux]
name: linux+x86-64
tinyname: 🐧x86
- os: [self-hosted, macOS, ARM64]
name: darwin+aarch64
tinyname:
test-container: [null]
test-os: [[self-hosted, macOS, ARM64]]
- os: [self-hosted, macOS, X64]
test-os: [macos-11, macos-12]
name: darwin+x86-64
tinyname: x86
test-container: [null]
- os: [self-hosted, linux, ARM64]
name: linux+aarch64
tinyname: 🐧ARM
test-container: [null]
test-os: [[self-hosted, linux, ARM64]]

uses: ./.github/workflows/pkger.yml
platform: ${{ fromJSON(needs.get-matrix.outputs.matrix) }}
uses: ./.github/workflows/pkg-for-platform.yml
with:
pkg: ${{ inputs.pkg }}
name: ${{ matrix.platform.name }}
Expand Down

0 comments on commit b5f7dc2

Please sign in to comment.