-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (126 loc) · 4.63 KB
/
_invoke.yaml
File metadata and controls
147 lines (126 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Invoke All Functions
on:
workflow_call:
inputs:
func-version:
required: true
type: string
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])
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:
language_paths: ${{ needs.prepare.outputs.language_paths }}
HEADREF: ${{ github.head_ref || github.ref_name }}
# Host builder is currently the default for Go and Python.
# Update this list if host builder support is added for more languages.
HOST_ENABLED_LANGUAGES: '["go","python"]'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install func
uses: functions-dev/action@main
with:
version: ${{ inputs.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: |
set -euo pipefail
builder="pack"
language=${{ matrix.language }}
#### DETERMINE IF HOST BUILDER SHOULD BE USED
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'"
# Get the absolute path for this language's templates
language_path=$(echo '${{ env.language_paths }}' | jq -r ".[] | select(contains(\"${{ matrix.language }}\"))")
echo ">> language_path=$language_path"
# Use the PR branch (or main) so func create picks up the changes being tested
url="https://github.com/functions-dev/templates#${{ env.HEADREF }}"
echo ">> url=$url"
WORKDIR=$(mktemp -d)
for template_dir_abs in $(ls -d $language_path*/); do
cd $WORKDIR
echo "template_dir_abs=$template_dir_abs"
template=$(basename "$template_dir_abs")
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
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
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
sleep 10
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 $(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