Skip to content

Commit 605db6f

Browse files
committed
Make TypeScript test workflow reusable
1 parent 04d5967 commit 605db6f

File tree

3 files changed

+184
-113
lines changed

3 files changed

+184
-113
lines changed

.cursor/mcp.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"mcpServers": {
3+
"Datadog (alpha1)": {
4+
"command": "/Users/ulysse.mavrocordatos/.cursor/extensions/datadog.datadog-vscode-2.4.1/resources/scripts/mcp/stdio-app.mjs",
5+
"args": [
6+
"57821"
7+
]
8+
}
9+
}
10+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
name: Reusable TypeScript Testing Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
node-versions:
7+
description: 'JSON array of Node.js versions to test against'
8+
required: false
9+
type: string
10+
default: '["16", "18"]'
11+
platforms:
12+
description: 'JSON array of platforms to run tests on'
13+
required: false
14+
type: string
15+
default: '["ubuntu-latest"]'
16+
test-script:
17+
description: 'Test script to execute'
18+
required: false
19+
type: string
20+
default: './run-tests.sh'
21+
examples-script:
22+
description: 'Examples script to execute'
23+
required: false
24+
type: string
25+
default: './check-examples.sh'
26+
enable-status-reporting:
27+
description: 'Whether to post status checks to datadog-api-spec repo'
28+
required: false
29+
type: boolean
30+
default: false
31+
status-context:
32+
description: 'Context for status checks'
33+
required: false
34+
type: string
35+
default: 'master/unit'
36+
secrets:
37+
PIPELINE_GITHUB_APP_ID:
38+
required: false
39+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
40+
required: false
41+
42+
jobs:
43+
pre-commit:
44+
runs-on: ubuntu-latest
45+
if: >
46+
(github.event.pull_request.draft == false &&
47+
!contains(github.event.pull_request.labels.*.name, 'ci/skip') &&
48+
!contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) ||
49+
github.event_name == 'schedule'
50+
steps:
51+
# Run only in this repository
52+
- name: Get GitHub App token
53+
id: get_token
54+
if: github.event.pull_request.head.repo.full_name == github.repository
55+
uses: actions/create-github-app-token@v1
56+
with:
57+
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
58+
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
59+
- uses: actions/checkout@v3
60+
if: github.event.pull_request.head.repo.full_name == github.repository
61+
with:
62+
fetch-depth: 0
63+
ref: ${{ github.event.pull_request.head.sha }}
64+
token: ${{ steps.get_token.outputs.token }}
65+
- uses: actions/setup-python@v4
66+
with:
67+
python-version: '3.11'
68+
# Fetch a fork of the repo
69+
- uses: actions/checkout@v3
70+
if: github.event.pull_request.head.repo.full_name != github.repository
71+
with:
72+
fetch-depth: 0
73+
ref: ${{ github.event.pull_request.head.sha }}
74+
- name: Install pre-commit
75+
run: python -m pip install pre-commit
76+
- name: set PY
77+
run: echo "PY=$(python -c 'import hashlib, sys, platform;print(hashlib.sha256(platform.python_version().encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_ENV
78+
- uses: actions/cache@v3
79+
with:
80+
path: ~/.cache/pre-commit
81+
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
82+
- id: pre_commit
83+
name: Run pre-commit
84+
if: github.event.action != 'closed' && github.event.pull_request.merged != true
85+
run: |
86+
pre-commit run --from-ref "${FROM_REF}" --to-ref "${TO_REF}" --show-diff-on-failure --color=always
87+
env:
88+
FROM_REF: ${{ github.event.pull_request.base.sha }}
89+
TO_REF: ${{ github.event.pull_request.head.sha }}
90+
- name: Commit changes
91+
if: github.event.pull_request.head.repo.full_name == github.repository && failure()
92+
run: |-
93+
git add -A
94+
git config user.name "${GIT_AUTHOR_NAME}"
95+
git config user.email "${GIT_AUTHOR_EMAIL}"
96+
git commit -m "pre-commit fixes"
97+
git push origin "HEAD:${HEAD_REF}"
98+
exit 1
99+
env:
100+
HEAD_REF: ${{ github.event.pull_request.head.ref }}
101+
GIT_AUTHOR_EMAIL: "[email protected]"
102+
GIT_AUTHOR_NAME: "ci.datadog-api-spec"
103+
- id: pre_commit_schedule
104+
name: Run pre-commit in schedule
105+
if: github.event_name == 'schedule'
106+
run: |
107+
pre-commit run --all-files --show-diff-on-failure --color=always
108+
109+
test:
110+
strategy:
111+
matrix:
112+
node-version: ${{ fromJSON(inputs.node-versions) }}
113+
platform: ${{ fromJSON(inputs.platforms) }}
114+
runs-on: ${{ matrix.platform }}
115+
if: (github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'ci/skip') && !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) || github.event_name == 'schedule'
116+
steps:
117+
- uses: actions/checkout@v3
118+
- name: Set up Node ${{ matrix.node-version }}
119+
uses: actions/setup-node@v3
120+
with:
121+
node-version: ${{ matrix.node-version }}
122+
cache: 'yarn'
123+
- name: Test
124+
run: ${{ inputs.test-script }}
125+
shell: bash
126+
127+
examples:
128+
runs-on: ubuntu-latest
129+
if: (github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'ci/skip') && !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) || github.event_name == 'schedule'
130+
steps:
131+
- uses: actions/checkout@v3
132+
- name: Set up Node 16
133+
uses: actions/setup-node@v3
134+
with:
135+
node-version: 16
136+
cache: 'yarn'
137+
- name: Check examples
138+
run: ${{ inputs.examples-script }}
139+
shell: bash
140+
141+
report:
142+
runs-on: ubuntu-latest
143+
if: always() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/') && inputs.enable-status-reporting
144+
needs:
145+
- test
146+
- examples
147+
steps:
148+
- name: Get GitHub App token
149+
if: github.event_name == 'pull_request'
150+
id: get_token
151+
uses: actions/create-github-app-token@v1
152+
with:
153+
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
154+
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
155+
repositories: datadog-api-spec
156+
- name: Post status check
157+
uses: DataDog/github-actions/post-status-check@v2
158+
with:
159+
github-token: ${{ steps.get_token.outputs.token }}
160+
repo: datadog-api-spec
161+
status: ${{ (needs.test.result == 'cancelled' || needs.examples.result == 'cancelled') && 'pending' || needs.test.result == 'success' && needs.examples.result == 'success' && 'success' || 'failure' }}
162+
context: ${{ inputs.status-context }}

.github/workflows/test.yml

Lines changed: 12 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -19,121 +19,20 @@ concurrency:
1919
cancel-in-progress: true
2020

2121
jobs:
22-
pre-commit:
23-
runs-on: ubuntu-latest
22+
typescript-test:
23+
uses: ./.github/workflows/reusable-typescript-test.yml
2424
if: >
2525
(github.event.pull_request.draft == false &&
2626
!contains(github.event.pull_request.labels.*.name, 'ci/skip') &&
2727
!contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) ||
2828
github.event_name == 'schedule'
29-
steps:
30-
# Run only in this repository
31-
- name: Get GitHub App token
32-
id: get_token
33-
if: github.event.pull_request.head.repo.full_name == github.repository
34-
uses: actions/create-github-app-token@v1
35-
with:
36-
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
37-
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
38-
- uses: actions/checkout@v3
39-
if: github.event.pull_request.head.repo.full_name == github.repository
40-
with:
41-
fetch-depth: 0
42-
ref: ${{ github.event.pull_request.head.sha }}
43-
token: ${{ steps.get_token.outputs.token }}
44-
- uses: actions/setup-python@v4
45-
with:
46-
python-version: '3.11'
47-
# Fetch a fork of the repo
48-
- uses: actions/checkout@v3
49-
if: github.event.pull_request.head.repo.full_name != github.repository
50-
with:
51-
fetch-depth: 0
52-
ref: ${{ github.event.pull_request.head.sha }}
53-
- name: Install pre-commit
54-
run: python -m pip install pre-commit
55-
- name: set PY
56-
run: echo "PY=$(python -c 'import hashlib, sys, platform;print(hashlib.sha256(platform.python_version().encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_ENV
57-
- uses: actions/cache@v3
58-
with:
59-
path: ~/.cache/pre-commit
60-
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
61-
- id: pre_commit
62-
name: Run pre-commit
63-
if: github.event.action != 'closed' && github.event.pull_request.merged != true
64-
run: |
65-
pre-commit run --from-ref "${FROM_REF}" --to-ref "${TO_REF}" --show-diff-on-failure --color=always
66-
env:
67-
FROM_REF: ${{ github.event.pull_request.base.sha }}
68-
TO_REF: ${{ github.event.pull_request.head.sha }}
69-
- name: Commit changes
70-
if: github.event.pull_request.head.repo.full_name == github.repository && failure()
71-
run: |-
72-
git add -A
73-
git config user.name "${GIT_AUTHOR_NAME}"
74-
git config user.email "${GIT_AUTHOR_EMAIL}"
75-
git commit -m "pre-commit fixes"
76-
git push origin "HEAD:${HEAD_REF}"
77-
exit 1
78-
env:
79-
HEAD_REF: ${{ github.event.pull_request.head.ref }}
80-
- id: pre_commit_schedule
81-
name: Run pre-commit in schedule
82-
if: github.event_name == 'schedule'
83-
run: |
84-
pre-commit run --all-files --show-diff-on-failure --color=always
85-
86-
test:
87-
strategy:
88-
matrix:
89-
node-version: ["16", "18"]
90-
platform: [ubuntu-latest]
91-
runs-on: ${{ matrix.platform }}
92-
if: (github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'ci/skip') && !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) || github.event_name == 'schedule'
93-
steps:
94-
- uses: actions/checkout@v3
95-
- name: Set up Node ${{ matrix.node-version }}
96-
uses: actions/setup-node@v3
97-
with:
98-
node-version: ${{ matrix.node-version }}
99-
cache: 'yarn'
100-
- name: Test
101-
run: ./run-tests.sh
102-
shell: bash
103-
104-
examples:
105-
runs-on: ubuntu-latest
106-
if: (github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'ci/skip') && !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) || github.event_name == 'schedule'
107-
steps:
108-
- uses: actions/checkout@v3
109-
- name: Set up Node 16
110-
uses: actions/setup-node@v3
111-
with:
112-
node-version: 16
113-
cache: 'yarn'
114-
- name: Check examples
115-
run: ./check-examples.sh
116-
shell: bash
117-
118-
report:
119-
runs-on: ubuntu-latest
120-
if: always() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/')
121-
needs:
122-
- test
123-
- examples
124-
steps:
125-
- name: Get GitHub App token
126-
if: github.event_name == 'pull_request'
127-
id: get_token
128-
uses: actions/create-github-app-token@v1
129-
with:
130-
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
131-
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
132-
repositories: datadog-api-spec
133-
- name: Post status check
134-
uses: DataDog/github-actions/post-status-check@v2
135-
with:
136-
github-token: ${{ steps.get_token.outputs.token }}
137-
repo: datadog-api-spec
138-
status: ${{ (needs.test.result == 'cancelled' || needs.examples.result == 'cancelled') && 'pending' || needs.test.result == 'success' && needs.examples.result == 'success' && 'success' || 'failure' }}
139-
context: master/unit
29+
with:
30+
node-versions: '["16", "18"]'
31+
platforms: '["ubuntu-latest"]'
32+
test-script: './run-tests.sh'
33+
examples-script: './check-examples.sh'
34+
enable-status-reporting: ${{ contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/') }}
35+
status-context: 'master/unit'
36+
secrets:
37+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
38+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}

0 commit comments

Comments
 (0)