Skip to content

Commit bcf28ce

Browse files
authored
Merge pull request #4395 from DataDog/tonycthsu/reusable-workflow
Remove template with reusable workflow
2 parents b2968df + e3a0bb7 commit bcf28ce

File tree

4 files changed

+343
-2240
lines changed

4 files changed

+343
-2240
lines changed

.github/workflows/_unit_test.yml

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
name: Unit Test Template
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
# TODO: Provides concurrency control for each ruby version
7+
engine:
8+
required: true
9+
type: string
10+
version:
11+
required: true
12+
type: string
13+
alias:
14+
required: true
15+
type: string
16+
outputs:
17+
lockfile:
18+
description: "The lockfile artifact"
19+
value: ${{ jobs.batch.outputs.lockfile }}
20+
cache-key:
21+
description: "The cache key for bundle"
22+
value: ${{ jobs.batch.outputs.cache-key }}
23+
24+
jobs:
25+
batch:
26+
runs-on: ubuntu-24.04
27+
name: batch
28+
outputs:
29+
batches: "${{ steps.set-batches.outputs.batches }}"
30+
cache-key: "${{ steps.restore-cache.outputs.cache-primary-key }}"
31+
lockfile: "${{ steps.lockfile.outputs.lockfile }}"
32+
container:
33+
image: ghcr.io/datadog/images-rb/engines/${{ inputs.engine }}:${{ inputs.version }}
34+
steps:
35+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
36+
- name: Generate lockfile
37+
id: lockfile
38+
run: |
39+
bundle lock
40+
echo "lockfile=lockfile-${{ inputs.alias }}-${{ github.run_id }}" >> $GITHUB_OUTPUT
41+
- name: Upload lockfile
42+
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
43+
with:
44+
name: ${{ steps.lockfile.outputs.lockfile }}
45+
path: "*.lock"
46+
- name: Restore cache
47+
uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
48+
id: restore-cache
49+
with:
50+
key: bundle-${{ runner.os }}-${{ runner.arch }}-${{ inputs.alias }}-${{ hashFiles('*.lock') }}
51+
path: "/usr/local/bundle"
52+
- if: steps.restore-cache.outputs.cache-hit != 'true'
53+
run: bundle install
54+
- if: steps.restore-cache.outputs.cache-hit != 'true'
55+
name: Save cache
56+
uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
57+
with:
58+
key: "${{ steps.restore-cache.outputs.cache-primary-key }}"
59+
path: "/usr/local/bundle"
60+
- id: set-batches
61+
name: Distribute tasks into batches
62+
run: |
63+
batches_json=$(bundle exec rake github:generate_batches)
64+
echo "$batches_json" | ruby -rjson -e 'puts JSON.pretty_generate(JSON.parse(STDIN.read))'
65+
echo "batches=$batches_json" >> $GITHUB_OUTPUT
66+
- name: Generate batch summary
67+
run: bundle exec rake github:generate_batch_summary
68+
env:
69+
batches_json: "${{ steps.set-batches.outputs.batches }}"
70+
build-test:
71+
needs:
72+
- batch
73+
runs-on: ubuntu-24.04
74+
name: build & test [${{ matrix.batch }}]
75+
timeout-minutes: 30
76+
env:
77+
BATCHED_TASKS: "${{ toJSON(matrix.tasks) }}"
78+
strategy:
79+
fail-fast: false
80+
matrix:
81+
include: "${{ fromJson(needs.batch.outputs.batches).include }}"
82+
container:
83+
image: ghcr.io/datadog/images-rb/engines/${{ inputs.engine }}:${{ inputs.version }}
84+
env:
85+
DD_INSTRUMENTATION_TELEMETRY_ENABLED: 'false'
86+
DD_REMOTE_CONFIGURATION_ENABLED: 'false'
87+
TEST_POSTGRES_HOST: postgres
88+
TEST_REDIS_HOST: redis
89+
TEST_ELASTICSEARCH_HOST: elasticsearch
90+
TEST_MEMCACHED_HOST: memcached
91+
TEST_MONGODB_HOST: mongodb
92+
TEST_MYSQL_HOST: mysql
93+
TEST_OPENSEARCH_HOST: opensearch
94+
TEST_OPENSEARCH_PORT: '9200'
95+
TEST_PRESTO_HOST: presto
96+
DD_AGENT_HOST: agent
97+
DD_TRACE_AGENT_PORT: '9126'
98+
DATADOG_GEM_CI: 'true'
99+
TEST_DATADOG_INTEGRATION: '1'
100+
JRUBY_OPTS: "--dev" # Faster JVM startup: https://github.com/jruby/jruby/wiki/Improving-startup-time#use-the---dev-flag
101+
services:
102+
agent:
103+
image: ghcr.io/datadog/dd-apm-test-agent/ddapm-test-agent:v1.18.0
104+
env:
105+
LOG_LEVEL: DEBUG
106+
TRACE_LANGUAGE: ruby
107+
PORT: '9126'
108+
DD_POOL_TRACE_CHECK_FAILURES: 'true'
109+
DD_DISABLE_ERROR_RESPONSES: 'true'
110+
ENABLED_CHECKS: trace_content_length,trace_stall,meta_tracer_version_header,trace_count_header,trace_peer_service,trace_dd_service
111+
postgres:
112+
image: ghcr.io/datadog/images-rb/services/postgres:9.6
113+
env:
114+
POSTGRES_PASSWORD: postgres
115+
POSTGRES_USER: postgres
116+
POSTGRES_DB: postgres
117+
redis:
118+
image: ghcr.io/datadog/images-rb/services/redis:6.2
119+
elasticsearch:
120+
image: ghcr.io/datadog/images-rb/services/elasticsearch:8.1.3
121+
env:
122+
discovery.type: single-node
123+
xpack.security.enabled: 'false'
124+
ES_JAVA_OPTS: "-Xms750m -Xmx750m"
125+
memcached:
126+
image: ghcr.io/datadog/images-rb/services/memcached:1.5-alpine
127+
mongodb:
128+
image: ghcr.io/datadog/images-rb/services/mongo:3.6
129+
opensearch:
130+
image: ghcr.io/datadog/images-rb/services/opensearchproject/opensearch:2.8.0
131+
env:
132+
discovery.type: single-node
133+
DISABLE_SECURITY_PLUGIN: 'true'
134+
DISABLE_PERFORMANCE_ANALYZER_AGENT_CLI: 'true'
135+
cluster.routing.allocation.disk.watermark.low: 3gb
136+
cluster.routing.allocation.disk.watermark.high: 2gb
137+
cluster.routing.allocation.disk.watermark.flood_stage: 1gb
138+
cluster.routing.allocation.disk.threshold_enabled: 'false'
139+
presto:
140+
image: ghcr.io/datadog/images-rb/services/starburstdata/presto:332-e.9
141+
mysql:
142+
image: ghcr.io/datadog/images-rb/services/mysql:8.0
143+
env:
144+
MYSQL_ROOT_PASSWORD: root
145+
MYSQL_PASSWORD: mysql
146+
MYSQL_USER: mysql
147+
steps:
148+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
149+
- name: Configure Git
150+
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
151+
- name: Download lockfile
152+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
153+
with:
154+
name: lockfile-${{ inputs.alias }}-${{ github.run_id }}
155+
- name: Restore cache
156+
uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
157+
id: restore-cache
158+
with:
159+
key: "${{ needs.batch.outputs.cache-key }}"
160+
path: "/usr/local/bundle"
161+
- run: bundle check || bundle install
162+
- run: bundle exec rake github:run_batch_build
163+
- name: Configure RSpec
164+
run: ln -s .rspec-local.example .rspec-local
165+
- run: bundle exec rake github:run_batch_tests
166+
env:
167+
COVERAGE_DIR: coverage/versions/${{ inputs.alias }}/${{ matrix.batch }}
168+
- name: Debug with SSH connection
169+
if: ${{ failure() && runner.debug == '1' }}
170+
uses: mxschmitt/action-tmate@e5c7151931ca95bad1c6f4190c730ecf8c7dde48 # v3.19.0
171+
with:
172+
limit-access-to-actor: true
173+
# This mode will wait at the end of the job for a user to connect and then to terminate the tmate session.
174+
# If no user has connected within 10 minutes after the post-job step started,
175+
# it will terminate the tmate session and quit gracefully.
176+
detached: true
177+
- name: Validate test agent data
178+
if: ${{ !cancelled() }}
179+
run: ruby .github/scripts/test_agent_check.rb
180+
- name: Upload junit reports
181+
if: ${{ !cancelled() }}
182+
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
183+
with:
184+
name: junit-${{ inputs.alias }}-${{ matrix.batch }}-${{ github.run_id }}
185+
path: tmp/rspec/*.xml
186+
- name: Upload coverage data
187+
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
188+
with:
189+
name: coverage-${{ inputs.alias }}-${{ matrix.batch }}-${{ github.run_id }}
190+
path: coverage
191+
include-hidden-files: true # Coverage data generated by SimpleCov are hidden

0 commit comments

Comments
 (0)