Skip to content

chore: add basic template build validation workflow #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/only-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: ci-only

on:
push:
branches:
- master
pull_request:
types:
- opened
- synchronize
- reopened

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Setup faas-cli
run: curl -sSL https://cli.openfaas.com | sh
- name: Verify all templates
run: bash verify.sh
77 changes: 77 additions & 0 deletions verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash
set -e

CLI="faas-cli"

build_template() {
template=$1

echo Building $template
func_name=$template-ci
$CLI new $func_name --lang $template 2>/dev/null 1>&2
$CLI build -f $func_name.yml
}

verify_and_clean() {
image=$1
tag_name=latest

echo Verifying $template
container=$(docker run -d -p 8080:8080 $func_name:$tag_name)
sleep 5 # wait for slower templates to start
output=$(curl -s -d "testing" http://127.0.0.1:8080)

echo $image output: $output
success=false
if [ ! -z "$output" ]; then # output was not empty = good template
success=true
fi

echo Cleaning $image
docker rm $container -f 2>/dev/null 1>&2
docker rmi $func_name:$tag_name 2>/dev/null 1>&2

if [ "$success" = false ]; then
echo $image template failed validation
exit 1
else
echo $image template validation successful
fi
}

if ! [ -x "$(command -v faas-cli)" ]; then
HERE=$(pwd)
cd /tmp/
curl -sSL https://cli.openfaas.com | sh
CLI="/tmp/faas-cli"

cd $HERE
fi

cli_version=$($CLI version --short-version)

echo Validating templates with faas-cli $cli_version

cd ./template

# verify each of the templates
for dir in ./*/; do
dirname=${dir%*/}
template=${dirname##*/}

# skip arm templates
case "$template" in
*-arm*) continue ;;
esac

pushd ../ 2>/dev/null 1>&2

build_template $template
verify_and_clean $template

popd 2>/dev/null 1>&2
done

# remove the generated files and folders if successful
cd ../
rm -rf *-ci *-ci.yml