Skip to content

Commit 51ee991

Browse files
authored
Make typescript v2 workflow reusable (#2830)
1 parent 3761381 commit 51ee991

File tree

5 files changed

+293
-85
lines changed

5 files changed

+293
-85
lines changed

.github/workflows/reusable-ci.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
node-versions:
12+
description: 'JSON array of Node.js versions to test against'
13+
required: false
14+
type: string
15+
default: '["18", "20"]'
16+
platforms:
17+
description: 'JSON array of platforms to run tests on'
18+
required: false
19+
type: string
20+
default: '["ubuntu-latest"]'
21+
test-script:
22+
description: 'Test script to execute'
23+
required: false
24+
type: string
25+
default: './run-tests.sh'
26+
examples-script:
27+
description: 'Examples script to execute'
28+
required: false
29+
type: string
30+
default: './check-examples.sh'
31+
secrets:
32+
PIPELINE_GITHUB_APP_ID:
33+
required: false
34+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
35+
required: false
36+
# Integration test secrets
37+
DD_API_KEY:
38+
required: false
39+
DD_CLIENT_API_KEY:
40+
required: false
41+
DD_CLIENT_APP_KEY:
42+
required: false
43+
SLEEP_AFTER_REQUEST:
44+
required: false
45+
46+
jobs:
47+
pre-commit:
48+
uses: ./.github/workflows/reusable-pre-commit.yml
49+
with:
50+
target-branch: ${{ inputs.target-branch }}
51+
enable-commit-changes: false # Don't auto-commit in external CI
52+
secrets:
53+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
54+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
55+
56+
test:
57+
uses: ./.github/workflows/reusable-typescript-test.yml
58+
with:
59+
target-branch: ${{ inputs.target-branch }}
60+
node-versions: ${{ inputs.node-versions }}
61+
platforms: ${{ inputs.platforms }}
62+
test-script: ${{ inputs.test-script }}
63+
secrets:
64+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
65+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
66+
67+
# examples:
68+
# uses: ./.github/workflows/reusable-examples.yml
69+
# with:
70+
# target-branch: ${{ inputs.target-branch }}
71+
# examples-script: ${{ inputs.examples-script }}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
22+
jobs:
23+
examples:
24+
runs-on: ubuntu-latest
25+
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'
26+
steps:
27+
- uses: actions/checkout@v3
28+
with:
29+
repository: DataDog/datadog-api-client-typescript
30+
ref: ${{ inputs.target-branch || github.ref }}
31+
- name: Enable Corepack
32+
run: corepack enable
33+
env:
34+
COREPACK_ENABLE_DOWNLOAD_PROMPT: 0
35+
- name: Set up Node ${{ inputs.node-version }}
36+
uses: actions/setup-node@v3
37+
with:
38+
node-version: ${{ inputs.node-version }}
39+
cache: 'yarn'
40+
- name: Check examples
41+
run: ${{ inputs.examples-script }}
42+
shell: bash
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
env:
23+
GIT_AUTHOR_EMAIL: "[email protected]"
24+
GIT_AUTHOR_NAME: "ci.datadog-api-spec"
25+
26+
jobs:
27+
pre-commit:
28+
runs-on: ubuntu-latest
29+
if: >
30+
(github.event.pull_request.draft == false &&
31+
!contains(github.event.pull_request.labels.*.name, 'ci/skip') &&
32+
!contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) ||
33+
github.event_name == 'schedule'
34+
steps:
35+
- name: Get GitHub App token
36+
id: get_token
37+
if: inputs.enable-commit-changes && github.event.pull_request.head.repo.full_name == github.repository
38+
uses: actions/create-github-app-token@v1
39+
with:
40+
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
41+
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
42+
- uses: actions/checkout@v3
43+
if: github.event.pull_request.head.repo.full_name == github.repository
44+
with:
45+
repository: DataDog/datadog-api-client-typescript
46+
ref: ${{ inputs.target-branch || github.event.pull_request.head.sha || github.ref }}
47+
fetch-depth: 50
48+
token: ${{ inputs.enable-commit-changes && steps.get_token.outputs.token || github.token }}
49+
- uses: actions/checkout@v3
50+
if: github.event.pull_request.head.repo.full_name != github.repository
51+
with:
52+
repository: DataDog/datadog-api-client-typescript
53+
ref: ${{ inputs.target-branch || github.event.pull_request.head.sha || github.ref }}
54+
fetch-depth: 50
55+
- uses: actions/setup-python@v4
56+
with:
57+
python-version: '3.11'
58+
- name: Install pre-commit
59+
run: python -m pip install pre-commit
60+
- name: set PY
61+
run: echo "PY=$(python -c 'import hashlib, sys, platform;print(hashlib.sha256(platform.python_version().encode()+sys.executable.encode()).hexdigest())')" >> $GITHUB_ENV
62+
- uses: actions/cache@v3
63+
with:
64+
path: ~/.cache/pre-commit
65+
key: pre-commit|split-package|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
66+
- name: Fetch v2 branch
67+
run: |
68+
git fetch origin v2 --depth=50
69+
- name: Determine pre-commit range
70+
id: commit_range
71+
run: |
72+
FROM_REF=$(git merge-base HEAD origin/v2)
73+
echo "from_ref=$FROM_REF" >> $GITHUB_OUTPUT
74+
echo "to_ref=HEAD" >> $GITHUB_OUTPUT
75+
echo "Pre-commit will check from $FROM_REF to HEAD"
76+
- id: pre_commit
77+
name: Run generate to fix lint and format
78+
if: github.event.action != 'closed' && github.event.pull_request.merged != true
79+
run: bash -c "./generate.sh"
80+
- name: Commit changes
81+
if: failure() && inputs.enable-commit-changes && github.event.pull_request.head.repo.full_name == github.repository
82+
run: |-
83+
git add -A
84+
git config user.name "${GIT_AUTHOR_NAME}"
85+
git config user.email "${GIT_AUTHOR_EMAIL}"
86+
git commit -m "pre-commit fixes"
87+
git push origin "HEAD:${HEAD_REF}"
88+
exit 1
89+
env:
90+
HEAD_REF: ${{ github.event.pull_request.head.ref }}
91+
- id: pre_commit_schedule
92+
name: Run pre-commit in schedule
93+
if: github.event_name == 'schedule'
94+
run: |
95+
pre-commit run --all-files --show-diff-on-failure --color=always
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Reusable TypeScript Testing 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+
node-versions:
12+
description: 'JSON array of Node.js versions to test against'
13+
required: false
14+
type: string
15+
default: '["18", "20"]'
16+
platforms:
17+
description: 'JSON array of platforms to run tests on'
18+
required: false
19+
type: string
20+
default: '["ubuntu-latest"]'
21+
test-script:
22+
description: 'Test script to execute'
23+
required: false
24+
type: string
25+
default: './run-tests.sh'
26+
secrets:
27+
PIPELINE_GITHUB_APP_ID:
28+
required: false
29+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
30+
required: false
31+
32+
jobs:
33+
test:
34+
strategy:
35+
matrix:
36+
node-version: ${{ fromJSON(inputs.node-versions) }}
37+
platform: ${{ fromJSON(inputs.platforms) }}
38+
runs-on: ${{ matrix.platform }}
39+
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'
40+
steps:
41+
- uses: actions/checkout@v3
42+
with:
43+
repository: DataDog/datadog-api-client-typescript
44+
ref: ${{ inputs.target-branch || github.ref }}
45+
- name: Enable Corepack
46+
run: corepack enable
47+
env:
48+
COREPACK_ENABLE_DOWNLOAD_PROMPT: 0
49+
- name: Set up Node ${{ matrix.node-version }}
50+
uses: actions/setup-node@v3
51+
with:
52+
node-version: ${{ matrix.node-version }}
53+
cache: 'yarn'
54+
- name: Test
55+
run: ${{ inputs.test-script }}
56+
shell: bash

0 commit comments

Comments
 (0)