fix printing, add more logs #120
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Invoke All Functions | |
| on: | |
| pull_request: | |
| types: | |
| - opened | |
| - synchronize | |
| - reopened | |
| paths-ignore: | |
| - '.github/**' | |
| push: | |
| branches: | |
| - main | |
| env: | |
| FUNC_VERSION: 'knative-v1.19.1' | |
| jobs: | |
| prepare: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| languages: ${{ steps.prep-matrix.outputs.languages }} | |
| language_paths: ${{ steps.prep-matrix.outputs.language_paths }} | |
| 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=$(find . -maxdepth 1 -type d -not -name ".*" -exec basename {} \; | jq -R -s -c 'split("\n")'[:-1]) | |
| # set output | |
| echo language_paths=$language_paths >> $GITHUB_OUTPUT | |
| echo languages=$languages >> $GITHUB_OUTPUT | |
| run: | |
| needs: prepare | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| language: ${{ fromJSON(needs.prepare.outputs.languages) }} | |
| env: | |
| ACTIONS_STEP_DEBUG: true | |
| language_paths: ${{needs.prepare.outputs.language_paths}} | |
| HEADREF: ${{github.head_ref}} | |
| # TODO: UPDATE THIS IF HOST BUILDER IS ENABLED FOR MORE LANGUAGES SO WE | |
| # DEFAULT TO THE HOST BUILDER | |
| HOST_ENABLED_LANGUAGES: '["go","python"]' | |
| 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: Setup Hugo | |
| uses: peaceiris/actions-hugo@v3 | |
| with: | |
| hugo-version: '0.142.0' | |
| extended: true | |
| - name: Build & Invoke Function | |
| run: | | |
| # series of commands to build & invoke the Function (with specifics per language) | |
| # Might change this to <one "run" per language> scenario because then | |
| # I would just need to check the matrix language for which one to run | |
| # and the number of supported languages is very stable. This would | |
| # invoke an action for each template. Perhaps an overkill | |
| set -euo pipefail | |
| builder="pack" # default; sets host dynamically for enabled languages | |
| language=${{ matrix.language }} | |
| #### 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 | |
| builder="host" | |
| fi | |
| echo "Using language '$language'" | |
| echo "Using builder '$builder'" | |
| # 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}}\"))") | |
| echo ">> language_path=$language_path" | |
| ## use the Pull request environment so that the changes are included in testing | |
| url="https://github.com/functions-dev/templates#${{ env.HEADREF }}" | |
| echo ">> url=$url" | |
| WORKDIR=$(mktemp -d) | |
| # see current state of dir | |
| echo "ls -la ${GITHUB_WORKSPACE}" | |
| ls -la ${GITHUB_WORKSPACE} | |
| # RUN FOR EACH TEMPLATE | |
| for template_dir_abs in $(ls -d $language_path*/); do | |
| cd $WORKDIR # cd to root for each template to not create embedded dirs | |
| echo "template_dir_abs=$template_dir_abs" | |
| template=$(basename "$template_dir_abs") | |
| ############################# FUNC CREATE ############################# | |
| echo ">>> FUNC CREATE <<<" | |
| echo "f create $language-$template -r=$url -l=$language -t=$template" | |
| f create $language-$template -r "$url" -l "$language" -t "$template" | |
| echo "cd $language-$template" | |
| cd $language-$template | |
| ############################## PRE-REQS ############################## | |
| echo "> PREREQS (if any)" | |
| ### language & template specific prerequisites | |
| if [ ${{ matrix.language }} == "go" ] && [ "$template" == "blog" ];then | |
| make | |
| elif [ ${{ matrix.language }} == "typescript" ];then | |
| npm install | |
| elif [ ${{ matrix.language }} == "rust" ]; then | |
| cargo build | |
| fi | |
| ########################## FUNC BUILD & RUN ########################## | |
| echo ">>> FUNC BUILD <<<" | |
| echo "FUNC_REGISTRY=quay.io/dfridric f build --builder=$builder" | |
| FUNC_REGISTRY=quay.io/dfridric f build --builder=$builder | |
| echo ">>> FUNC RUN <<<" | |
| echo "f run --build=false &" | |
| f run --build=false & | |
| 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 | |
| # wait for run just in case | |
| sleep 10 | |
| ############################# FUNC INVOKE ############################# | |
| echo "> FUNC INVOKE" | |
| MAX_RETRIES=5 | |
| RETRY_COUNT=0 | |
| SUCCESS=false | |
| while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do | |
| echo ">>> Attempt $RETRY_COUNT of $MAX_RETRIES for <<<" | |
| echo "$(basename "$(dirname "$PWD")")/$(basename "$PWD")" | |
| echo "Invoking 'func invoke' with current PID $$" | |
| if f invoke --request-type=GET; then | |
| echo "'func invoke' succeeded." | |
| SUCCESS=true | |
| break | |
| else | |
| echo "'func invoke' failed." | |
| RETRY_COUNT=$((RETRY_COUNT + 1)) | |
| sleep 10 | |
| fi | |
| done | |
| kill $RUN_PID | |
| if [ "$SUCCESS" = true ]; then | |
| echo "all good" | |
| else | |
| echo "'func invoke' failed." | |
| exit 1 | |
| fi | |
| done |