From 7f528698270d6c10632c06b90e8cd69974dee2f9 Mon Sep 17 00:00:00 2001 From: David Fridrich Date: Mon, 23 Mar 2026 17:26:17 +0100 Subject: [PATCH] add Makefile with test targets, test-templates CI workflow, remove manual-workflow --- .github/workflows/invoke-all.yaml | 1 + .github/workflows/manual-workflow.yml | 69 --------------------------- .github/workflows/test-templates.yaml | 37 ++++++++++++++ Makefile | 60 +++++++++++++++++++++++ 4 files changed, 98 insertions(+), 69 deletions(-) delete mode 100644 .github/workflows/manual-workflow.yml create mode 100644 .github/workflows/test-templates.yaml create mode 100644 Makefile diff --git a/.github/workflows/invoke-all.yaml b/.github/workflows/invoke-all.yaml index ed4c1ac..292315e 100644 --- a/.github/workflows/invoke-all.yaml +++ b/.github/workflows/invoke-all.yaml @@ -1,6 +1,7 @@ name: Invoke All Functions on: + workflow_dispatch: pull_request: types: - opened diff --git a/.github/workflows/manual-workflow.yml b/.github/workflows/manual-workflow.yml deleted file mode 100644 index 437cd23..0000000 --- a/.github/workflows/manual-workflow.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: Manual Flow Testing - -on: workflow_dispatch - -jobs: - prepare: - runs-on: ubuntu-latest - outputs: - languages: ${{ steps.prep-matrix.outputs.languages }} - language_paths: ${{ steps.prep-matrix.outputs.language_paths }} - env: - FUNC_VERSION: "knative-v1.19.1" - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Prep Matrix - id: prep-matrix - run: | - ## NOTE: ls -d returns absolute path - ## GITHUB_WORKSPACE is the root directory - language_paths="$(ls -d ${GITHUB_WORKSPACE}/*/ | jq -R -s 'split("\n")[:-1]')" - languages="$(ls -d ${GITHUB_WORKSPACE}/*/ | xargs -n 1 basename | jq -R -s 'split("\n")[:-1]')" - - # set output - echo language_paths=$language_paths >> $GITHUB_OUTPUT - echo languages=$languages >> $GITHUB_OUTPUT - - deploy: - needs: prepare - runs-on: ubuntu-latest - strategy: - matrix: - language: ${{ fromJSON(needs.prepare.outputs.languages) }} - env: - ACTIONS_STEP_DEBUG: true - language_paths: ${{needs.prepare.outputs.language_paths}} - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install func - uses: gauron99/knative-func-action@main - with: - version: ${{ env.FUNC_VERSION }} - name: f - - - name: Build Functions - run: | - language=${{matrix.language}} - echo "Current language: $language" - - # This takes the array of paths, wraps it in single quotes for jq, then - # selects only the value that matches with language to get current - # language AND its full path (where the func template is) - language_path=$(echo '${{env.language_paths}}' | jq -r ".[] | select(contains(\"${{matrix.language}}\"))") - - url="https://github.com/gauron99/func-templates" - WORKDIR=$(mktemp -d) - cd $WORKDIR - echo "Building funcs in language ${{matrix.language}}" - for template_dir_abs in $(ls -d $language_path*/); do - echo "ls -la ${GITHUB_WORKSPACE}" - ls -la ${GITHUB_WORKSPACE} - template=$(basename "$template_dir_abs") - echo "f create $language-$template -r=$url -l=$language -t=$template" - f create $language-$template -r "$url" -l "$language" -t "$template" - #FUNC_REGISTRY=quay.io/dfridric f build --builder=host - done \ No newline at end of file diff --git a/.github/workflows/test-templates.yaml b/.github/workflows/test-templates.yaml new file mode 100644 index 0000000..772d273 --- /dev/null +++ b/.github/workflows/test-templates.yaml @@ -0,0 +1,37 @@ +name: Test Templates + +on: + pull_request: + types: + - opened + - synchronize + - reopened + paths-ignore: + - '.github/**' + push: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: 'stable' + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + + - name: Setup Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + + - name: Run template tests + run: make test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..86809fb --- /dev/null +++ b/Makefile @@ -0,0 +1,60 @@ +.PHONY: test test-go test-node test-python test-quarkus test-rust test-springboot test-typescript test-ci invoke-ci + +LOG := test-results.log +START_TIME := $(shell date +%s%3N) + +# Skipped templates: +# go/blog — Hugo theme is a broken submodule, func create doesn't fetch submodules +# python/llamacpp, mcp, mcp-ollama, mcp-ollama-rag, ollama-client — need external services or have broken tests +GO_SKIP := blog +PYTHON_SKIP := llamacpp mcp mcp-ollama mcp-ollama-rag ollama-client + +# Run tests for each template in a language directory. +# For each template: check skip list, run test command, print colored result with timing. +# Detailed output goes to LOG file; PASS/FAIL/SKIP printed to stdout. +# Args: $(1)=language dir $(2)=space-separated skip list $(3)=test command +define run_tests + @for dir in $(1)/*/; do \ + t=$$(basename $$dir); \ + skip=false; for s in $(2); do [ "$$t" = "$$s" ] && skip=true && break; done; \ + if [ "$$skip" = "true" ]; then \ + printf "\033[33mSKIP\033[0m %s\n" "$$dir"; echo "SKIP $$dir" >> $(LOG); continue; \ + fi; \ + start=$$(date +%s%3N); \ + if (cd $$dir && $(3)) >> $(LOG) 2>&1; then \ + ms=$$(( $$(date +%s%3N) - $$start )); \ + printf "\033[32mPASS\033[0m %s (%d.%03ds)\n" "$$dir" "$$((ms/1000))" "$$((ms%1000))"; \ + echo "PASS $$dir ($${ms}ms)" >> $(LOG); \ + else \ + ms=$$(( $$(date +%s%3N) - $$start )); \ + printf "\033[31mFAIL\033[0m %s (%d.%03ds)\n" "$$dir" "$$((ms/1000))" "$$((ms%1000))"; \ + echo "FAIL $$dir ($${ms}ms)" >> $(LOG); \ + fi; \ + done +endef + +test: clean-log test-go test-node test-python test-quarkus test-rust test-springboot test-typescript summary + +clean-log: + @rm -f $(LOG) + @echo "Running tests..." + +test-go: ; $(call run_tests,go,$(GO_SKIP),go test -count=1 ./...) +test-node: ; $(call run_tests,node,,npm install --silent && npm test && rm -rf node_modules) +test-python: ; $(call run_tests,python,$(PYTHON_SKIP),python -m venv .venv && .venv/bin/pip install -q '.[dev]' && .venv/bin/python -m pytest tests/ && rm -rf .venv) +test-quarkus: ; $(call run_tests,quarkus,,mvn test -q) +test-rust: ; $(call run_tests,rust,,cargo test) +test-springboot: ; $(call run_tests,springboot,,mvn test -q) +test-typescript: ; $(call run_tests,typescript,,npm install --silent && npm test && rm -rf node_modules build) + +summary: + @echo "" + @echo "=== Test Summary ===" + @passed=$$(grep -c "^PASS" $(LOG) || true); \ + failed=$$(grep -c "^FAIL" $(LOG) || true); \ + skipped=$$(grep -c "^SKIP" $(LOG) || true); \ + ms=$$(( $$(date +%s%3N) - $(START_TIME) )); \ + printf "\033[32m$$passed passed\033[0m, \033[31m$$failed failed\033[0m, \033[33m$$skipped skipped\033[0m in %d.%03ds\n" "$$((ms/1000))" "$$((ms%1000))"; \ + echo "Full log: $(LOG)"; \ + if [ "$$failed" -gt 0 ]; then echo ""; echo "=== Failed ==="; grep "^FAIL" $(LOG); exit 1; fi +