From f36c78fdbf2265e0f7740f17acbcd05a10885f66 Mon Sep 17 00:00:00 2001 From: David Fridrich <49119790+gauron99@users.noreply.github.com> Date: Thu, 9 Jan 2025 13:01:16 +0100 Subject: [PATCH] Feature: Workflow now Invokes Functions + some edits (#22) * redo some workflows, func invoke instead of deploy because its easier Signed-off-by: David Fridrich * fix triggering, remove old wf * fix * synchronize on push * trigger on pull_request_target * trigger on pull_request_target * testing trigger on pull_request_target * testing trigger on pull_request_target * testing filtered list * add hack Signed-off-by: David Fridrich * install binaries init, filter list to only languages Signed-off-by: David Fridrich * dont deploy, just invoke, chmod stuff Signed-off-by: David Fridrich * fix Signed-off-by: David Fridrich * fix Signed-off-by: David Fridrich * fix Signed-off-by: David Fridrich * func run in bg and invoke * fix Signed-off-by: David Fridrich * fix Signed-off-by: David Fridrich * fix * fix Signed-off-by: David Fridrich * fix Signed-off-by: David Fridrich * fix Signed-off-by: David Fridrich * fix Signed-off-by: David Fridrich * fix Signed-off-by: David Fridrich * fix Signed-off-by: David Fridrich * fix Signed-off-by: David Fridrich * fix Signed-off-by: David Fridrich * fix Signed-off-by: David Fridrich * rename, we invoke now instead of deploy Signed-off-by: David Fridrich * fix Signed-off-by: David Fridrich * remove unnecessary Signed-off-by: David Fridrich * fix Signed-off-by: David Fridrich * fix Signed-off-by: David Fridrich --------- Signed-off-by: David Fridrich --- .../{build-all.yaml => invoke-all.yaml} | 68 +++++++++++++++---- .github/workflows/main-build-all.yaml | 42 ------------ README.md | 2 +- 3 files changed, 55 insertions(+), 57 deletions(-) rename .github/workflows/{build-all.yaml => invoke-all.yaml} (64%) delete mode 100644 .github/workflows/main-build-all.yaml diff --git a/.github/workflows/build-all.yaml b/.github/workflows/invoke-all.yaml similarity index 64% rename from .github/workflows/build-all.yaml rename to .github/workflows/invoke-all.yaml index 91dcf15..bca489d 100644 --- a/.github/workflows/build-all.yaml +++ b/.github/workflows/invoke-all.yaml @@ -1,9 +1,10 @@ -name: Build All Functions +name: Invoke All Functions on: pull_request: paths-ignore: - '.github/**' + jobs: prepare: runs-on: ubuntu-latest @@ -28,7 +29,7 @@ jobs: echo language_paths=$language_paths >> $GITHUB_OUTPUT echo languages=$languages >> $GITHUB_OUTPUT - deploy: + run: needs: prepare runs-on: ubuntu-latest strategy: @@ -51,14 +52,12 @@ jobs: version: ${{ env.FUNC_VERSION }} name: f - - name: Deploy Function + - name: Build & Invoke Function run: | - # series of commands to build & deploy the Function (with specifics per language) + # series of commands to build & invoke the Function (with specifics per language) # Might change this to scenario because then # I would just need to check the matrix language for which one to run - - # DETERMINE IF HOST BUILDER SHOULD BE USED ## NOTE: HOST_ENABLED_LANGUAGES MUST BE UP TO DATE if echo '${{env.HOST_ENABLED_LANGUAGES}}' | jq -r ".[] | select(. == \"${{matrix.language}}\")" | grep -q .; then @@ -85,7 +84,7 @@ jobs: ls -la ${GITHUB_WORKSPACE} template=$(basename "$template_dir_abs") - ############################## FUNC CREATE ############################## + ############################# FUNC CREATE ############################# echo "> FUNC CREATE" echo "f create $language-$template -r=$url -l=$language -t=$template" @@ -93,21 +92,62 @@ jobs: cd $language-$template - ############################## FUNC BUILD ############################## + ############################# FUNC BUILD ############################# echo "> FUNC BUILD" - - if $HOST_ENABLED; then + if [ "$HOST_ENABLED" == "true" ]; then echo "build with host" FUNC_ENABLE_HOST_BUILDER=1 FUNC_BUILDER=host FUNC_CONTAINER=false FUNC_REGISTRY=docker.io/4141gauron3268 f build else - echo "build with pack" + echo "build with pack" + #TODO this might be moved up above the if statement for HOSTBUILDER? if [ ${{matrix.language}} == "typescript" ];then npm install - fi - if [ ${{matrix.language}} == "rust"]; then + elif [ ${{matrix.language}} == "rust" ]; then cargo build fi - FUNC_REGISTRY=docker.io/4141gauron3268 f build --builder=pack + FUNC_REGISTRY=docker.io/4141gauron3268 f build + fi + + ############################## FUNC RUN ############################## + if [ "$HOST_ENABLED" == "true" ]; then + FUNC_ENABLE_HOST_BUILDER=1 FUNC_CONTAINER=false f run & + else + FUNC_CONTAINER=true f run & + fi + + RUN_PID=$! + + if ps -p $RUN_PID > /dev/null; then + echo "'func run' is running with PID $RUN_PID" + else + echo "Failed to start 'func run'. Exiting" + exit 1 + fi + + sleep 5 + ############################# FUNC INVOKE ############################# + MAX_RETRIES=5 + RETRY_COUNT=0 + SUCCESS=false + while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do + echo "Attempt $RETRY_COUNT of $MAX_RETRIES" + echo "Invoking 'func invoke' with current PID $$" + if f invoke; then + echo "'func invoke' succeeded." + SUCCESS=true + break + else + echo "'func invoke' failed." + RETRY_COUNT=$((RETRY_COUNT + 1)) + sleep 2 + fi + done + kill $RUN_PID + if [ "$SUCCESS" = true ]; then + echo "all good" + else + echo "'func invoke' failed." + exit 1 fi done diff --git a/.github/workflows/main-build-all.yaml b/.github/workflows/main-build-all.yaml deleted file mode 100644 index 85dc178..0000000 --- a/.github/workflows/main-build-all.yaml +++ /dev/null @@ -1,42 +0,0 @@ -name: Build All on main - -on: - push: - branches: main - -jobs: - builds: - runs-on: ubuntu-latest - env: - FUNC_VERSION: "knative-v1.16.1" - 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: | - WORKDIR=$(mktemp -d) - cd $WORKDIR - ## NOTE: ls -d returns absolute path - ## GITHUB_WORKSPACE is the root directory (checked out?) - #cycle through all languages - url="http://github.com/gauron99/func-templates" - for lang_dir_abs in $(ls -d ${GITHUB_WORKSPACE}/*/); do - lang=$(basename "$lang_dir_abs") - echo "Building funcs in language $lang" - for template_dir_abs in $(ls -d $lang_dir_abs*/); do - template=$(basename "$template_dir_abs") - ls -la $template_dir_abs - echo "f create $lang-$template -r=$url -l=$lang -t=$template" - f create $lang-$template -r "$url" -l "$lang" -t "$template" - #FUNC_ENABLE_HOST_BUILDER=1 FUNC_BUILDER=host FUNC_CONTAINER=false FUNC_REGISTRY=docker.io/4141gauron3268 f - done - done - - diff --git a/README.md b/README.md index 3a41b13..5bf092e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build All](https://github.com/gauron99/func-templates/actions/workflows/main-build-all.yaml/badge.svg?branch=main&event=push)](https://github.com/gauron99/func-templates/actions/workflows/main-build-all.yaml) +[![Deploy All](https://github.com/gauron99/func-templates/actions/workflows/deploy-all.yaml/badge.svg?branch=main&event=push)](https://github.com/gauron99/func-templates/actions/workflows/deploy-all.yaml) # WELCOME To Knative Function Templates! ### Quick search