forked from kaiachain/kaia
-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (133 loc) · 5 KB
/
Copy pathtest-executor-template.yml
File metadata and controls
138 lines (133 loc) · 5 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
name: Reusable Test Environment
on:
workflow_call:
inputs:
test_command: # The inner command to run the test.
required: true
type: string
runs_on: # The machine type. "ubuntu-latest" or "kaia-xlarge-runner"
required: false
type: string
default: ubuntu-latest
install_python: # If true, install python.
required: false
type: boolean
default: false
# The fetch depth for the current repo (kaiachain/kaia) clone.
# 1 = clone the latest commit snapshot. 0 = clone the full history (necessary for test-linter's '--new-from-rev=dev' to work)
fetch_depth:
required: false
type: number
default: 1
with_services: # If true, launch the mock services (kafka, redis, localstack) in the background.
required: false
type: boolean
default: false
cache_fixtures: # If true, cache the spec test fixtures in ./build/cache/.
required: false
type: boolean
default: false
permissions:
contents: read
jobs:
test:
# region Setup runner and container
runs-on: ${{ inputs.runs_on }}
container:
image: kaiachain/build_base:go1.25.3-solc0.8.13-ubuntu-22.04
services:
# If !with_services, declare empty image name, therefore no service will be launched.
# See https://github.com/actions/runner/issues/822#issuecomment-1524826092
kafka:
image: ${{ inputs.with_services == true && 'apache/kafka:3.7.0' || '' }}
env:
KAFKA_NODE_ID: 0
KAFKA_PROCESS_ROLES: controller,broker
KAFKA_CONTROLLER_QUORUM_VOTERS: 0@kafka:9093
KAFKA_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: "1"
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: "1"
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: "1"
KAFKA_NUM_PARTITIONS: "1"
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: "0"
redis:
image: ${{ inputs.with_services == true && 'redis:6.0.8-alpine' || '' }}
localstack:
image: ${{ inputs.with_services == true && 'localstack/localstack:3' || '' }}
steps:
# region download source
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: ${{ inputs.fetch_depth }}
- name: Add safe directory
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
# region Install packages
# Will override the base image's Go setup. Introduced to cache the builds.
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.25.3' # The same version as the base image.
cache: true
- name: Setup Python
if: ${{ inputs.install_python == true }}
uses: actions/setup-python@v5
with:
python-version: '3.10.12' # The same version as the base image.
- name: Cache pip packages # Cache the 'pip install' downloaded pip packages.
if: ${{ inputs.install_python == true }}
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: pip-${{ runner.os }}-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
pip-${{ runner.os }}-
- name: Cache spec test fixtures # Cache the 'ci.go --ensure-fixtures' downloaded fixture files.
if: ${{ inputs.cache_fixtures == true }}
uses: actions/cache@v4
with:
path: ./build/cache
key: spec-fixtures-${{ hashFiles('build/checksums.txt') }}
# region Run test
- name: Wait for Redis
if: ${{ inputs.with_services == true }}
run: |
apt-get install -y netcat-traditional
for i in $(seq 1 10); do
nc -z redis 6379 && echo Success && exit 0
echo -n .
sleep 1
done
echo Failed waiting for Redis && exit 1
continue-on-error: true
- name: Wait for Kafka
if: ${{ inputs.with_services == true }}
run: |
for i in $(seq 1 10); do
nc -z kafka 9092 && echo Success && exit 0
echo -n .
sleep 1
done
echo Failed waiting for Kafka && exit 1
continue-on-error: true
- name: Wait for Localstack
if: ${{ inputs.with_services == true }}
run: |
for i in $(seq 1 60); do
nc -z localstack 4566 && echo Success && exit 0
echo -n .
sleep 1
done
echo Failed waiting for Kafka && exit 1
continue-on-error: true
- name: Run test
shell: bash
env:
AWS_ACCESS_KEY_ID: dummy # for localstack
AWS_SECRET_ACCESS_KEY: dummy
run: ${{ inputs.test_command }}