Skip to content

Commit 90370a7

Browse files
committed
Make the typescript CI in a reusable workflow
1 parent 48abb3e commit 90370a7

File tree

6 files changed

+401
-97
lines changed

6 files changed

+401
-97
lines changed

.github/workflows/reusable-ci.yml

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: Reusable Complete CI Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
target-branch:
7+
description: 'Branch to checkout and test (defaults to the calling branch)'
8+
required: false
9+
type: string
10+
default: ''
11+
enable-commit-changes:
12+
description: 'Whether to commit and push pre-commit fixes'
13+
required: false
14+
type: boolean
15+
default: true
16+
enable-status-reporting:
17+
description: 'Whether to enable status reporting'
18+
required: false
19+
type: boolean
20+
default: true
21+
status-context:
22+
description: 'Context for status checks'
23+
required: false
24+
type: string
25+
default: 'master/unit'
26+
target-repo:
27+
description: 'Repository to post status to'
28+
required: false
29+
type: string
30+
default: 'datadog-api-spec'
31+
node-versions:
32+
description: 'JSON array of Node.js versions to test against'
33+
required: false
34+
type: string
35+
default: '["16", "18"]'
36+
platforms:
37+
description: 'JSON array of platforms to run tests on'
38+
required: false
39+
type: string
40+
default: '["ubuntu-latest"]'
41+
test-script:
42+
description: 'Test script to execute'
43+
required: false
44+
type: string
45+
default: './run-tests.sh'
46+
examples-script:
47+
description: 'Examples script to execute'
48+
required: false
49+
type: string
50+
default: './check-examples.sh'
51+
node-version:
52+
description: 'Node.js version to use'
53+
required: false
54+
type: string
55+
default: '16'
56+
57+
secrets:
58+
PIPELINE_GITHUB_APP_ID:
59+
required: false
60+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
61+
required: false
62+
# Integration test secrets
63+
DD_API_KEY:
64+
required: false
65+
DD_CLIENT_API_KEY:
66+
required: false
67+
DD_CLIENT_APP_KEY:
68+
required: false
69+
SLEEP_AFTER_REQUEST:
70+
required: false
71+
72+
jobs:
73+
pre-commit:
74+
uses: ./.github/workflows/reusable-pre-commit.yml
75+
with:
76+
target-branch: ${{ inputs.target-branch }}
77+
enable-commit-changes: ${{ inputs.enable-commit-changes }}
78+
secrets:
79+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
80+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
81+
82+
test:
83+
uses: ./.github/workflows/reusable-typescript-test.yml
84+
with:
85+
target-branch: ${{ inputs.target-branch }}
86+
node-versions: ${{ inputs.node-versions }}
87+
platforms: ${{ inputs.platforms }}
88+
test-script: ${{ inputs.test-script }}
89+
secrets:
90+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
91+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
92+
93+
examples:
94+
uses: ./.github/workflows/reusable-examples.yml
95+
with:
96+
target-branch: ${{ inputs.target-branch }}
97+
examples-script: ${{ inputs.examples-script }}
98+
node-version: ${{ inputs.node-version }}
99+
100+
integration:
101+
uses: ./.github/workflows/reusable-integration-test.yml
102+
with:
103+
target-branch: ${{ inputs.target-branch }}
104+
enable-status-reporting: false # We handle reporting in the main report job
105+
status-context: 'integration'
106+
target-repo: ${{ inputs.target-repo }}
107+
secrets:
108+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
109+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
110+
DD_API_KEY: ${{ secrets.DD_API_KEY }}
111+
DD_CLIENT_API_KEY: ${{ secrets.DD_CLIENT_API_KEY }}
112+
DD_CLIENT_APP_KEY: ${{ secrets.DD_CLIENT_APP_KEY }}
113+
SLEEP_AFTER_REQUEST: ${{ secrets.SLEEP_AFTER_REQUEST }}
114+
115+
report:
116+
uses: ./.github/workflows/reusable-report.yml
117+
needs:
118+
- test
119+
- examples
120+
- integration
121+
if: always()
122+
with:
123+
test-result: ${{ needs.test.result }}
124+
examples-result: ${{ needs.examples.result }}
125+
integration-result: ${{ needs.integration.result }}
126+
context: ${{ inputs.status-context }}
127+
target-repo: ${{ inputs.target-repo }}
128+
enable-status-reporting: ${{ inputs.enable-status-reporting }}
129+
secrets:
130+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
131+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Reusable Examples Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
target-branch:
7+
description: 'Branch to checkout and test (defaults to the calling branch)'
8+
required: false
9+
type: string
10+
default: ''
11+
examples-script:
12+
description: 'Examples script to execute'
13+
required: false
14+
type: string
15+
default: './check-examples.sh'
16+
node-version:
17+
description: 'Node.js version to use for examples'
18+
required: false
19+
type: string
20+
default: '16'
21+
secrets:
22+
PIPELINE_GITHUB_APP_ID:
23+
required: false
24+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
25+
required: false
26+
27+
jobs:
28+
examples:
29+
runs-on: ubuntu-latest
30+
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'
31+
steps:
32+
- uses: actions/checkout@v3
33+
with:
34+
repository: DataDog/datadog-api-client-typescript
35+
ref: ${{ inputs.target-branch || github.ref }}
36+
- name: Set up Node ${{ inputs.node-version }}
37+
uses: actions/setup-node@v3
38+
with:
39+
node-version: ${{ inputs.node-version }}
40+
cache: 'yarn'
41+
- name: Check examples
42+
run: ${{ inputs.examples-script }}
43+
shell: bash

.github/workflows/test_integration.yml renamed to .github/workflows/reusable-integration-test.yml

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run Integration Tests
1+
name: Reusable Integration Test Workflow
22

33
permissions:
44
contents: read
@@ -16,6 +16,41 @@ on:
1616
- master
1717
schedule:
1818
- cron: "0 4 * * *"
19+
workflow_call:
20+
inputs:
21+
target-branch:
22+
description: 'Branch to checkout and test (defaults to the calling branch)'
23+
required: false
24+
type: string
25+
default: ''
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: 'integration'
36+
target-repo:
37+
description: 'Repository to post status to'
38+
required: false
39+
type: string
40+
default: 'datadog-api-spec'
41+
secrets:
42+
PIPELINE_GITHUB_APP_ID:
43+
required: false
44+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
45+
required: false
46+
DD_API_KEY:
47+
required: true
48+
DD_CLIENT_API_KEY:
49+
required: true
50+
DD_CLIENT_APP_KEY:
51+
required: true
52+
SLEEP_AFTER_REQUEST:
53+
required: false
1954

2055
concurrency:
2156
group: integration-${{ github.head_ref }}
@@ -48,17 +83,20 @@ jobs:
4883
with:
4984
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
5085
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
51-
repositories: datadog-api-spec
86+
repositories: ${{ inputs.target-repo || 'datadog-api-spec' }}
5287
- name: Checkout code
5388
uses: actions/checkout@v3
89+
with:
90+
repository: DataDog/datadog-api-client-typescript
91+
ref: ${{ inputs.target-branch || github.ref }}
5492
- name: Post pending status check
55-
if: github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/')
93+
if: github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/') && (inputs.enable-status-reporting || github.event_name != 'workflow_call')
5694
uses: DataDog/github-actions/post-status-check@v2
5795
with:
5896
github-token: ${{ steps.get_token.outputs.token }}
59-
repo: datadog-api-spec
97+
repo: ${{ inputs.target-repo || 'datadog-api-spec' }}
6098
status: pending
61-
context: integration
99+
context: ${{ inputs.status-context || 'integration' }}
62100
- name: Set up Node 16
63101
uses: actions/setup-node@v3
64102
with:
@@ -77,20 +115,20 @@ jobs:
77115
DD_TEST_CLIENT_API_KEY: ${{ secrets.DD_CLIENT_API_KEY }}
78116
DD_TEST_CLIENT_APP_KEY: ${{ secrets.DD_CLIENT_APP_KEY }}
79117
RECORD: "none"
80-
SLEEP_AFTER_REQUEST: "${{ vars.SLEEP_AFTER_REQUEST }}"
118+
SLEEP_AFTER_REQUEST: ${{ secrets.SLEEP_AFTER_REQUEST || vars.SLEEP_AFTER_REQUEST }}
81119
- name: Post failure status check
82-
if: failure() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/')
120+
if: failure() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/') && (inputs.enable-status-reporting || github.event_name != 'workflow_call')
83121
uses: DataDog/github-actions/post-status-check@v2
84122
with:
85123
github-token: ${{ steps.get_token.outputs.token }}
86-
repo: datadog-api-spec
124+
repo: ${{ inputs.target-repo || 'datadog-api-spec' }}
87125
status: failure
88-
context: integration
126+
context: ${{ inputs.status-context || 'integration' }}
89127
- name: Post success status check
90-
if: "!failure() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/')"
128+
if: "!failure() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/') && (inputs.enable-status-reporting || github.event_name != 'workflow_call')"
91129
uses: DataDog/github-actions/post-status-check@v2
92130
with:
93131
github-token: ${{ steps.get_token.outputs.token }}
94-
repo: datadog-api-spec
132+
repo: ${{ inputs.target-repo || 'datadog-api-spec' }}
95133
status: success
96-
context: integration
134+
context: ${{ inputs.status-context || 'integration' }}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Reusable Pre-commit Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
target-branch:
7+
description: 'Branch to checkout and test (defaults to the calling branch)'
8+
required: false
9+
type: string
10+
default: ''
11+
enable-commit-changes:
12+
description: 'Whether to commit and push pre-commit fixes'
13+
required: false
14+
type: boolean
15+
default: true
16+
secrets:
17+
PIPELINE_GITHUB_APP_ID:
18+
required: false
19+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
20+
required: false
21+
22+
jobs:
23+
pre-commit:
24+
runs-on: ubuntu-latest
25+
if: >
26+
(github.event.pull_request.draft == false &&
27+
!contains(github.event.pull_request.labels.*.name, 'ci/skip') &&
28+
!contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) ||
29+
github.event_name == 'schedule'
30+
steps:
31+
- name: Get GitHub App token
32+
if: inputs.enable-commit-changes && github.event.pull_request.head.repo.full_name == github.repository
33+
id: get_token
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+
repository: DataDog/datadog-api-client-typescript
43+
ref: ${{ inputs.target-branch || github.event.pull_request.head.sha || github.ref }}
44+
token: ${{ inputs.enable-commit-changes && steps.get_token.outputs.token || github.token }}
45+
- uses: actions/checkout@v3
46+
if: github.event.pull_request.head.repo.full_name != github.repository
47+
with:
48+
repository: DataDog/datadog-api-client-typescript
49+
ref: ${{ inputs.target-branch || github.ref }}
50+
- uses: actions/setup-python@v4
51+
with:
52+
python-version: '3.11'
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: failure() && inputs.enable-commit-changes && github.event.pull_request.head.repo.full_name == github.repository
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+
GIT_AUTHOR_EMAIL: "[email protected]"
81+
GIT_AUTHOR_NAME: "ci.datadog-api-spec"
82+
- id: pre_commit_schedule
83+
name: Run pre-commit in schedule
84+
if: github.event_name == 'schedule'
85+
run: |
86+
pre-commit run --all-files --show-diff-on-failure --color=always

0 commit comments

Comments
 (0)