-
Notifications
You must be signed in to change notification settings - Fork 3
146 lines (140 loc) · 5.27 KB
/
integtest.yaml
File metadata and controls
146 lines (140 loc) · 5.27 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
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch: {}
name: integration tests
jobs:
list-apps:
runs-on: ubuntu-latest
outputs:
to_test: ${{ steps.find_dirs.outputs.to_test }}
steps:
- uses: actions/checkout@v3
- name: find test dirs
id: find_dirs
run: |
dirs_with_tests="$(
for d in $(find * -type d -maxdepth 0 || printf ''); do
TESTABLE_APP=$(jq &>/dev/null -e '.scripts."integ-test"' $d/package.json && echo "$d")
if grep -s -q "^integ-test:" "${d}/Makefile"; then
TESTABLE_APP=$d
fi
if [[ -n "${TESTABLE_APP}" ]]; then
echo $TESTABLE_APP
fi
done
exit 0 # otherwise, will fail if the last dir failed the jq match
)"
as_json="$(echo "$dirs_with_tests" | jq -c -R --slurp 'split("\n") | map(select(length > 0))')"
if [[ "$as_json" == '[]' ]]; then
echo "::error ::No tests found"
exit 1
fi
echo "$as_json" | jq .
echo "to_test=$as_json" > $GITHUB_OUTPUT
run-test:
needs: list-apps
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
app_to_test: ${{ fromJson(needs.list-apps.outputs.to_test) }}
services:
redis:
image: redis
ports:
- 6379:6379/tcp
# Set health checks to wait until redis has started, but only for ts-redis or py-redis.
# ${{ condition && ifTrue || ifFalse }} works as a ternary operator.
# We always need some valid docker option (even in the false case -- an empty string results in an error),
# so if this isn't a redis service, just set CPUs to 1 as some arbitrary option.
options:
${{ contains(fromJson('["ts-redis", "py-redis"]'), matrix.app_to_test)
&& '--health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5'
|| '--cpus 1' }}
steps:
- uses: actions/checkout@v3
- name: get sample app language
id: get_language
run: echo language=$(echo "${{ matrix.app_to_test }}" | cut -d "-" -f 1) >> $GITHUB_OUTPUT
- name: npm install
if: steps.get_language.outputs.language == 'ts'
run: npm install
working-directory: ${{ matrix.app_to_test }}
- name: tsc
if: steps.get_language.outputs.language == 'ts'
run: npx tsc
working-directory: ${{ matrix.app_to_test }}
- name: pipenv install
if: steps.get_language.outputs.language == 'py'
working-directory: ${{ matrix.app_to_test }}
run: |
pip install pipenv
pipenv install -r requirements.txt
- name: Test redis cluster
if: contains(fromJson('["ts-redis-cluster", "py-redis-cluster"]'), matrix.app_to_test)
uses: vishnudxb/redis-cluster@1.0.5
with:
master1-port: 8000
master2-port: 8001
master3-port: 8002
slave1-port: 8003
slave2-port: 8004
slave3-port: 8005
# Running Test
- name: ping redis cluster
if: contains(fromJson('["ts-redis-cluster", "py-redis-cluster"]'), matrix.app_to_test)
run: |
sudo apt-get install -y redis-tools
docker ps -a
redis-cli -h 127.0.0.1 -p 8000 ping
redis-cli -h 127.0.0.1 -p 8000 cluster nodes
- name: local vars
working-directory: ${{ matrix.app_to_test }}
run: |
if [[ -f test/integ_test_hooks/local-vars.sh ]]; then
test/integ_test_hooks/local-vars.sh
fi
- name: service start
id: service-start
working-directory: ${{ matrix.app_to_test }}
run: |
if [[ -f test/integ_test_hooks/localhost-start.sh ]]; then
cmd='bash test/integ_test_hooks/localhost-start.sh'
elif [[ "${{ steps.get_language.outputs.language }}" == "ts" ]]; then
cmd='node dist/index.js'
else
cmd='pipenv run make run'
fi
echo "Using start command: $cmd"
$cmd >$RUNNER_TEMP/service.out 2>$RUNNER_TEMP/service.err &
node_pid=$!
echo "node-pid=$node_pid" >> $GITHUB_OUTPUT
env:
REDIS_PORT: ${{ job.services.redis.ports[6379] }}
- name: run typescript tests
if: steps.get_language.outputs.language == 'ts'
uses: klothoplatform/gh-action-retry@v1
with:
working-directory: ${{ matrix.app_to_test }}
script: API_ENDPOINT=http://localhost:3000 npm run integ-test
- name: run python tests
if: steps.get_language.outputs.language == 'py'
uses: klothoplatform/gh-action-retry@v1
with:
working-directory: ${{ matrix.app_to_test }}
script: API_ENDPOINT=http://localhost:3000 pipenv run make integ-test
- name: service stop
if: always() && steps.service-start.outputs.node-pid
run: kill ${{ steps.service-start.outputs.node-pid }}
- name: echo service output
if: always()
run: |
echo '::group::stdout'
cat $RUNNER_TEMP/service.out
echo '::endgroup'
echo '::group::stderr'
cat $RUNNER_TEMP/service.err
echo '::endgroup'