Skip to content

Commit

Permalink
test CI matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
ajschmidt8 committed Nov 15, 2023
1 parent 13bbc25 commit fc0281c
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 53 deletions.
64 changes: 46 additions & 18 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,56 @@ permissions:
contents: read

jobs:
compute-matrix:
runs-on: ubuntu-latest
outputs:
MATRIX: ${{ steps.compute-matrix.outputs.MATRIX }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Compute matrix
id: compute-matrix
run: |
MATRIX=$(ci/compute-matrix.sh)
echo "MATRIX=${MATRIX}" | tee --append ${GITHUB_OUTPUT}
build:
needs: compute-matrix
strategy:
matrix: ${{ fromJSON(needs.compute-matrix.outputs.MATRIX) }}
fail-fast: false
matrix:
KUBERNETES_VERSION:
- "1.27"
DRIVER_VERSION:
- "525.125.06"
runs-on: ubuntu-latest
container:
image: hashicorp/packer:latest
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ vars.PACKER_AWS_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}
- uses: actions/checkout@v3
- name: Build image
run: |
packer init .
packer build \
-var "skip_create_ami=${{ inputs.skip_create_ami }}" \
-var "driver_version=${{ matrix.DRIVER_VERSION }}" \
.
- run:
- run: |
echo "DRIVER_VERSION=$DRIVER_VERSION"
echo "OS=$OS"
echo "RUNNER_VERSION=$RUNNER_VERSION"
echo "ARCH=$ARCH"
echo "ENV=$ENV"
echo "SKIP_CREATE_AMI=$SKIP_CREATE_AMI"
echo "DOMAIN=$DOMAIN"
echo "PACKER_SOURCE=$PACKER_SOURCE"
env:
DRIVER_VERSION: ${{ matrix.DRIVER_VERSION }}
OS: ${{ matrix.OS }}
RUNNER_VERSION: ${{ matrix.RUNNER_VERSION }}
ARCH: ${{ matrix.ARCH }}
ENV: ${{ matrix.ENV }}
SKIP_CREATE_AMI: ${{ inputs.skip_create_ami }}
DOMAIN: ${{ matrix.domain }}
PACKER_SOURCE: ${{ matrix.packer_source }}
# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v2
# with:
# role-to-assume: ${{ vars.PACKER_AWS_ROLE_ARN }}
# aws-region: ${{ vars.AWS_REGION }}
# - uses: actions/checkout@v4
# - name: Build image
# run: |
# packer init .
# packer build \
# -var "skip_create_ami=${{ inputs.skip_create_ami }}" \
# -var "driver_version=${{ matrix.DRIVER_VERSION }}" \
# .
15 changes: 5 additions & 10 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ concurrency:
cancel-in-progress: true

jobs:
# TODO: update PR build job
# build:
# uses: ./.github/workflows/build.yaml
# with:
# skip_create_ami: true
# secrets: inherit
temp:
runs-on: ubuntu-latest
steps:
- run: echo "temp job"
build:
uses: ./.github/workflows/build.yaml
with:
skip_create_ami: true
secrets: inherit
2 changes: 1 addition & 1 deletion build.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ build {
"NV_ARCH=${var.arch}",
"NV_DRIVER_VERSION=${var.driver_version}",
"NV_HELPER_SCRIPTS=${local.helpers_directory}",
"NV_VARIANT=${var.variant}",
"NV_VARIANT=${local.variant}",
]

scripts = [
Expand Down
26 changes: 26 additions & 0 deletions ci/compute-matrix.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Checks the current entry to see if it matches the given exclude
def matches($entry; $exclude):
all($exclude | to_entries | .[]; $entry[.key] == .value);

def filter_excludes($entry; $excludes):
select(any($excludes[]; matches($entry; .)) | not);

def lists2dict($keys; $values):
reduce range($keys | length) as $ind ({}; . + {($keys[$ind]): $values[$ind]});

def add_config($entry; $config):
$entry + $config[$entry.ENV];

def compute_matrix($matrix; $config):
($matrix.exclude // []) as $excludes |
$matrix | del(.exclude) |
keys_unsorted as $matrix_keys |
to_entries |
map(.value) |
[
combinations |
lists2dict($matrix_keys; .) |
filter_excludes(.; $excludes) |
add_config(.; $config)
] |
{include: .};
11 changes: 11 additions & 0 deletions ci/compute-matrix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -euo pipefail

# This script computes the matrix for the GHAs matrix job. The values in
# config.yaml are injected into each matrix entry according to its `ENV` key.

yq -o json \
eval-all \
'{"matrix": select(filename == "matrix.yaml")} + {"config": select(filename == "config.yaml")}' \
matrix.yaml config.yaml | \
jq -c 'include "ci/compute-matrix"; compute_matrix(.matrix; .config)'
6 changes: 6 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
aws:
domain: arc-eks
packer_source: amazon-ebs
premise:
domain: arc-nvks
packer_source: qemu
3 changes: 2 additions & 1 deletion locals.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
locals {
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
driver_major_version = var.variant == "cpu" ? null : "${split(".", var.driver_version)[0]}"
variant = var.driver_version == "" ? "cpu" : "gpu"
driver_major_version = local.variant == "cpu" ? null : "${split(".", var.driver_version)[0]}"
instance_type = var.arch == "amd64" ? "m7i.large" : "m7g.large"
helpers_directory = "/home/runner/helpers"
}
17 changes: 6 additions & 11 deletions matrix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,19 @@ OS:
# - win

DRIVER_VERSION:
# keep this blank entry. an empty driver version corresponds to CPU machines
- ""
- "525.147.05"

RUNNER_VERSION:
- "2.311.0"

ARCH:
- amd64
- arm64
# - arm64

VARIANT:
- cpu
- gpu
ENV:
- aws
# - premise

FORMAT:
- qcow2
- ami

# Specify additional excludes here.
# ci/generate-matrix.yaml will automatically exclude 'cpu' variants and
# `driver_version` combinations.
exclude: []
2 changes: 1 addition & 1 deletion source.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ source "amazon-ebs" "ubuntu" {
"driver-version" = local.driver_major_version
"os" = var.os
"runner-version" = var.runner_version
"variant" = var.variant
"variant" = local.variant
}: k => v if v != null
}
}
Expand Down
1 change: 0 additions & 1 deletion variables.auto.pkrvars.hcl.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
// os = "linux"
runner_version = "2.311.0"
// skip_create_ami = true
// variant = "gpu"
10 changes: 0 additions & 10 deletions variables.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,3 @@ variable "skip_create_ami" {
type = bool
default = true
}

variable "variant" {
type = string
default = "cpu"

validation {
condition = can(regex("^[cg]pu$", var.variant))
error_message = "The variant value must be either 'cpu' or 'gpu'."
}
}

0 comments on commit fc0281c

Please sign in to comment.