-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (151 loc) · 5.47 KB
/
Copy pathpull_request.yaml
File metadata and controls
180 lines (151 loc) · 5.47 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: pull_request
on: [pull_request, workflow_dispatch]
jobs:
eslint:
name: Run eslint
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Run linters
uses: wearerequired/lint-action@v1
with:
github_token: ${{ secrets.github_token }}
# Enable linters
eslint: true
prettier: true
eslint_extensions: ts
- name: OpenAPI Lint Checks
if: ${{ inputs.enableOpenApiCheck == true }}
uses: nwestfall/openapi-action@v1.0.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ inputs.openApiFilePath }}
integration-test:
name: Run Integration Tests
runs-on: ubuntu-latest
container: node:16
services:
# Label used to access the service container
elasticsearch:
# Docker Hub image
image: elasticsearch:8.15.3
env:
discovery.type: single-node
xpack.security.enabled: false
xpack.security.enrollment.enabled: false
ES_JAVA_OPTS: "-Xms512m -Xmx512m"
ports:
- 9200:9200
# Set health checks to wait until elastic has started
options: >-
--health-cmd "curl -f http://localhost:9200/_cluster/health || exit 1"
--health-interval 10s
--health-timeout 10s
--health-retries 30
kafka:
image: apache/kafka:3.8.0
ports:
- 9092:9092
env:
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092,CONTROLLER://0.0.0.0:9093
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,CONTROLLER:PLAINTEXT
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@kafka:9093
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
options: >-
--health-cmd "bash -lc 'kafka-broker-api-versions.sh --bootstrap-server 127.0.0.1:9092 >/dev/null 2>&1'"
--health-interval 10s
--health-timeout 10s
--health-retries 30
strategy:
matrix:
node: [18.x, 20.x]
steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: Install Node.js dependencies
run: npm ci
- name: Wait for Kafka
shell: bash
run: |
for i in {1..60}; do
(echo > /dev/tcp/kafka/9092) >/dev/null 2>&1 && echo "Kafka is up" && exit 0
echo "Waiting for Kafka..."
sleep 2
done
exit 1
- name: Create Kafka topics
env:
KAFKA_BROKERS: kafka:9092
run: |
node - <<'NODE'
const { Kafka } = require('kafkajs');
(async () => {
const brokers = (process.env.KAFKA_BROKERS || 'kafka:9092').split(',');
const kafka = new Kafka({ clientId: 'ci-topic-init', brokers });
const admin = kafka.admin();
await admin.connect();
const topics = ['topic1-test', 'topic2-test'];
// Create topics only if missing (idempotent-ish)
// KafkaJS createTopics will return false if topics already exist.
const created = await admin.createTopics({
topics: topics.map(t => ({ topic: t, numPartitions: 1, replicationFactor: 1 })),
waitForLeaders: true,
timeout: 30000,
});
console.log(`createTopics result: ${created ? 'created' : 'already existed'}`);
await admin.disconnect();
})().catch(err => {
console.error(err);
process.exit(1);
});
NODE
- name: Wait for Elasticsearch
run: |
until curl -s http://elasticsearch:9200/_cluster/health | grep -E '"status":"(yellow|green)"'; do
echo "Waiting for Elasticsearch...";
sleep 5;
done
- name: Run integration tests
env:
USER_DATA_SERVICE_QUERY_PARAMS: '{"extraDetails":true}'
HEADER_PARAMS: '{"headerDetails":true}'
run: npm run test:integration
- uses: actions/upload-artifact@v4
with:
name: Integration Test Reporters (Node ${{ matrix.node }})
path: reports/**
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/node@master
continue-on-error: true
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
build_image:
name: Build Image
runs-on: ubuntu-latest
steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: build Docker image
run: docker build -t test-build:latest .