Skip to content

Commit 5c0508f

Browse files
LucasRoesleralexellis
authored andcommitted
chore: add basic template validate workflow
Create a CI workflow that will create and build an "echo" function for each template in the repo. This allows us to ensure that the basic structure of the template is functional. Signed-off-by: Lucas Roesler <[email protected]>
1 parent 8a1a07e commit 5c0508f

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

.github/workflows/only-ci.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: ci-only
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
- reopened
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 1
20+
- name: Setup faas-cli
21+
run: curl -sSL https://cli.openfaas.com | sh
22+
- name: Verify all templates
23+
run: bash verify.sh

verify.sh

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
set -e
3+
4+
CLI="faas-cli"
5+
6+
build_template() {
7+
template=$1
8+
9+
echo Building $template
10+
func_name=$template-ci
11+
$CLI new $func_name --lang $template 2>/dev/null 1>&2
12+
$CLI build -f $func_name.yml
13+
}
14+
15+
verify_and_clean() {
16+
image=$1
17+
tag_name=latest
18+
19+
echo Verifying $template
20+
container=$(docker run -d -p 8080:8080 $func_name:$tag_name)
21+
sleep 5 # wait for slower templates to start
22+
output=$(curl -s -d "testing" http://127.0.0.1:8080)
23+
24+
echo $image output: $output
25+
success=false
26+
if [ ! -z "$output" ]; then # output was not empty = good template
27+
success=true
28+
fi
29+
30+
echo Cleaning $image
31+
docker rm $container -f 2>/dev/null 1>&2
32+
docker rmi $func_name:$tag_name 2>/dev/null 1>&2
33+
34+
if [ "$success" = false ]; then
35+
echo $image template failed validation
36+
exit 1
37+
else
38+
echo $image template validation successful
39+
fi
40+
}
41+
42+
if ! [ -x "$(command -v faas-cli)" ]; then
43+
HERE=$(pwd)
44+
cd /tmp/
45+
curl -sSL https://cli.openfaas.com | sh
46+
CLI="/tmp/faas-cli"
47+
48+
cd $HERE
49+
fi
50+
51+
cli_version=$($CLI version --short-version)
52+
53+
echo Validating templates with faas-cli $cli_version
54+
55+
cd ./template
56+
57+
# verify each of the templates
58+
for dir in ./*/; do
59+
dirname=${dir%*/}
60+
template=${dirname##*/}
61+
62+
# skip arm templates
63+
case "$template" in
64+
*-arm*) continue ;;
65+
esac
66+
67+
pushd ../ 2>/dev/null 1>&2
68+
69+
build_template $template
70+
verify_and_clean $template
71+
72+
popd 2>/dev/null 1>&2
73+
done
74+
75+
# remove the generated files and folders if successful
76+
cd ../
77+
rm -rf *-ci *-ci.yml

0 commit comments

Comments
 (0)