From 5672048263ca895720b622cae365d1cff19cb9ad Mon Sep 17 00:00:00 2001 From: Robert James Hernandez Date: Sat, 14 Oct 2023 15:34:09 +0000 Subject: [PATCH 1/2] openwrt-golden: migrate ci test to nix check --- .github/workflows/openwrt-golden.yml | 37 ------------------------ .github/workflows/validate-datafiles.yml | 1 + nix/tests/flake-module.nix | 10 +++++++ 3 files changed, 11 insertions(+), 37 deletions(-) delete mode 100644 .github/workflows/openwrt-golden.yml diff --git a/.github/workflows/openwrt-golden.yml b/.github/workflows/openwrt-golden.yml deleted file mode 100644 index f2b44d17..00000000 --- a/.github/workflows/openwrt-golden.yml +++ /dev/null @@ -1,37 +0,0 @@ ---- -name: openwrt-golden - -on: - pull_request: - paths: - - '.github/**' - - 'openwrt/**' - - 'facts/**' - - 'tests/**' - push: # This is only run when PRs are merged into master - branches: - - master - workflow_dispatch: - - -jobs: - gomplate_tests: - name: gomplate_tests - runs-on: ubuntu-latest - container: - # gomplate v3.11.3-alpine - image: hairyhenderson/gomplate@sha256:7a8e23a4900cb11b92b1e19122b7e20c606fb21d3fc569c44c3d9e7fc9cab1ee - steps: - - name: checkout - id: checkout - uses: actions/checkout@v2 - - name: install_diffutils - id: diffutils - shell: sh - run: | - apk update && apk add diffutils - - name: openwrt_golden_ar71xx - shell: sh - run: | - cd tests/unit/openwrt - sh -x test.sh -t ar71xx diff --git a/.github/workflows/validate-datafiles.yml b/.github/workflows/validate-datafiles.yml index 521855f4..666284d1 100644 --- a/.github/workflows/validate-datafiles.yml +++ b/.github/workflows/validate-datafiles.yml @@ -18,3 +18,4 @@ jobs: - uses: DeterminateSystems/magic-nix-cache-action@main - run: nix build -L .#checks.x86_64-linux.pytest-facts - run: nix build -L .#checks.x86_64-linux.perl-switches + - run: nix build -L .#checks.x86_64-linux.openwrt-golden diff --git a/nix/tests/flake-module.nix b/nix/tests/flake-module.nix index 2279751c..c85a2c6c 100644 --- a/nix/tests/flake-module.nix +++ b/nix/tests/flake-module.nix @@ -29,6 +29,16 @@ make .build-switch-configs touch $out ''); + openwrt-golden = pkgs.runCommand "openwrt-golden" + { + buildInputs = [ pkgs.diffutils pkgs.gomplate ]; + } '' + cp -r --no-preserve=mode ${pkgs.lib.cleanSource inputs.self}/* . + cd tests/unit/openwrt + mkdir -p $out/tmp/ar71xx + ${pkgs.bash}/bin/bash test.sh -t ar71xx -o $out + ''; + }; }; } From 5526839902d74f2efcaee27fe2255fcb74336822 Mon Sep 17 00:00:00 2001 From: Robert James Hernandez Date: Sat, 14 Oct 2023 15:34:55 +0000 Subject: [PATCH 2/2] openwrt-golden: -o flag specify output dir --- tests/unit/openwrt/test.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/unit/openwrt/test.sh b/tests/unit/openwrt/test.sh index bf2ed9b3..5df4fad9 100644 --- a/tests/unit/openwrt/test.sh +++ b/tests/unit/openwrt/test.sh @@ -6,6 +6,7 @@ Simple test for gomplate generated templates OPTIONS: -h Show this message + -o specify output for temporary generated templates -t Target arch to build -u Update golden templates @@ -17,7 +18,7 @@ EXAMPLES: EOF } -while getopts "ht:u" OPTION +while getopts "ho:t:u" OPTION do case $OPTION in u ) @@ -26,6 +27,9 @@ do t ) TARGET=$OPTARG ;; + o ) + OUTPUT=$OPTARG + ;; h ) usage exit 0 @@ -41,16 +45,16 @@ shift $((OPTIND -1)) TARGET=${TARGET:-'ar71xx'} UPDATE=${UPDATE:-0} -TMPLOC="tmp/${TARGET}" +TMPLOC="${OUTPUT:-.}/tmp/${TARGET}" KEYPATH="../../../facts/keys/" gen_templates(){ # Export to support ENV datasource export TARGET=$TARGET export KEYPATH=$KEYPATH - gomplate -d openwrt=../../../facts/secrets/${TARGET}-openwrt-example.yaml -d keys_dir=${KEYPATH} --input-dir=../../../openwrt/files --output-dir="./${1}" + gomplate -d openwrt=../../../facts/secrets/${TARGET}-openwrt-example.yaml -d keys_dir=${KEYPATH} --input-dir=../../../openwrt/files --output-dir="${1}" if [ -d ../../../openwrt/files-${TARGET} ]; then - gomplate -d openwrt=../../../facts/secrets/${TARGET}-openwrt-example.yaml -d keys_dir=${KEYPATH} --input-dir=../../../openwrt/files-${TARGET} --output-dir="./${1}" + gomplate -d openwrt=../../../facts/secrets/${TARGET}-openwrt-example.yaml -d keys_dir=${KEYPATH} --input-dir=../../../openwrt/files-${TARGET} --output-dir="${1}" fi } @@ -59,6 +63,6 @@ if [ ${UPDATE} -eq 1 ]; then gen_templates "golden/${TARGET}" fi -gen_templates $TMPLOC +gen_templates "$TMPLOC" diff -u -r "golden/${TARGET}" $TMPLOC/