#!/usr/bin/env bash
set -e
set -o pipefail

main() {
    local template="${1}"

    preamble "${template}"

    (
        cd configs
        LC_ALL=C ls -1 *_defconfig
    ) \
    | sed -r -e 's/^(.+)$/\1: { extends: .defconfig }\n\1_check: { extends: .defconfig_check }/'

    ./support/testing/run-tests -l 2>&1 \
    | sed -r -e '/^test_run \((.*)\).*/!d; s//\1: { extends: .runtime_test }/' \
    | LC_ALL=C sort
}

preamble() {
    local template="${1}"

    cat - "${template}" <<-_EOF_
	# This file is generated; do not edit!
	# Builds appear on https://gitlab.com/buildroot.org/buildroot/pipelines

	image: ${CI_JOB_IMAGE}

_EOF_
}

main "${@}"
