Skip to content

Commit 0dd5e95

Browse files
authored
turn all of the relevant ci jobs in reusable workflow (#3343)
1 parent 30f9481 commit 0dd5e95

6 files changed

Lines changed: 236 additions & 122 deletions

File tree

.github/workflows/reusable-ci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
12+
secrets:
13+
PIPELINE_GITHUB_APP_ID:
14+
required: false
15+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
16+
required: false
17+
# Integration test secrets
18+
DD_API_KEY:
19+
required: false
20+
DD_CLIENT_API_KEY:
21+
required: false
22+
DD_CLIENT_APP_KEY:
23+
required: false
24+
SLEEP_AFTER_REQUEST:
25+
required: false
26+
27+
jobs:
28+
pre-commit:
29+
uses: ./.github/workflows/reusable-pre-commit.yml
30+
with:
31+
target-branch: ${{ inputs.target-branch }}
32+
enable-commit-changes: false # Don't auto-commit in external CI
33+
secrets:
34+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
35+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
36+
37+
test:
38+
uses: ./.github/workflows/reusable-go-test.yml
39+
with:
40+
target-branch: ${{ inputs.target-branch }}
41+
42+
examples:
43+
uses: ./.github/workflows/reusable-examples.yml
44+
with:
45+
target-branch: ${{ inputs.target-branch }}
46+
47+
integration:
48+
uses: ./.github/workflows/reusable-integration-test.yml
49+
with:
50+
target-branch: ${{ inputs.target-branch }}
51+
secrets:
52+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
53+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
54+
DD_API_KEY: ${{ secrets.DD_API_KEY }}
55+
DD_CLIENT_API_KEY: ${{ secrets.DD_CLIENT_API_KEY }}
56+
DD_CLIENT_APP_KEY: ${{ secrets.DD_CLIENT_APP_KEY }}
57+
SLEEP_AFTER_REQUEST: ${{ secrets.SLEEP_AFTER_REQUEST }}
58+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
12+
jobs:
13+
examples:
14+
runs-on: ubuntu-latest
15+
if: >
16+
(github.event.pull_request.draft == false &&
17+
!contains(github.event.pull_request.labels.*.name, 'ci/skip') &&
18+
!contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) ||
19+
github.event_name == 'schedule'
20+
steps:
21+
- uses: actions/checkout@v3
22+
with:
23+
repository: DataDog/datadog-api-client-go
24+
ref: ${{ inputs.target-branch || github.ref }}
25+
- name: Install Go
26+
uses: actions/setup-go@v4
27+
with:
28+
go-version: 1.22.x
29+
cache: true
30+
cache-dependency-path: tests/go.sum
31+
- name: Check examples
32+
run: ./check-examples.sh
33+
shell: bash

.github/workflows/reusable-go-test.yml

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,6 @@ on:
88
required: false
99
type: string
1010
default: ''
11-
enable-status-reporting:
12-
description: 'Whether to post status checks to datadog-api-spec repo'
13-
required: false
14-
type: boolean
15-
default: false
16-
status-context:
17-
description: 'Context for status checks'
18-
required: false
19-
type: string
20-
default: 'master/unit'
21-
secrets:
22-
# Optional: Only needed for cross-repository status reporting when called
23-
# from external repos (e.g., datadog-api-spec) for generated code changes
24-
PIPELINE_GITHUB_APP_ID:
25-
required: false
26-
PIPELINE_GITHUB_APP_PRIVATE_KEY:
27-
required: false
2811

2912
jobs:
3013
test:
@@ -51,24 +34,3 @@ jobs:
5134
env:
5235
TESTARGS: ${{ matrix.go-build-tags }}
5336

54-
report:
55-
runs-on: ubuntu-latest
56-
if: always() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/') && inputs.enable-status-reporting
57-
needs:
58-
- test
59-
steps:
60-
- name: Get GitHub App token
61-
if: github.event_name == 'pull_request'
62-
id: get_token
63-
uses: actions/create-github-app-token@v1
64-
with:
65-
app-id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
66-
private-key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
67-
repositories: datadog-api-spec
68-
- name: Post status check
69-
uses: DataDog/github-actions/post-status-check@v2
70-
with:
71-
github-token: ${{ steps.get_token.outputs.token }}
72-
repo: datadog-api-spec
73-
status: ${{ needs.test.result == 'cancelled' && 'pending' || needs.test.result == 'success' && 'success' || 'failure' }}
74-
context: ${{ inputs.status-context }}

.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
- unlabeled
1717
schedule:
1818
- cron: "0 0 * * *"
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-go
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: Install Go
63101
uses: actions/setup-go@v4
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+
env:
23+
GIT_AUTHOR_EMAIL: "packages@datadoghq.com"
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
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+
with:
44+
fetch-depth: 0
45+
repository: DataDog/datadog-api-client-go
46+
ref: ${{ inputs.target-branch || github.event.pull_request.head.sha || github.ref }}
47+
token: ${{ inputs.enable-commit-changes && steps.get_token.outputs.token || github.token }}
48+
- uses: actions/setup-python@v4
49+
with:
50+
python-version: '3.11'
51+
- name: Install pre-commit
52+
run: python -m pip install pre-commit
53+
- name: set PY
54+
run: echo "PY=$(python -c 'import platform;print(platform.python_version())')" >> $GITHUB_ENV
55+
- uses: actions/cache@v3
56+
with:
57+
path: ~/.cache/pre-commit
58+
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
59+
- name: Install Go
60+
uses: actions/setup-go@v4
61+
with:
62+
go-version: 1.22.x
63+
- id: pre_commit
64+
name: Run pre-commit
65+
if: github.event.action != 'closed' && github.event.pull_request.merged != true
66+
run: |
67+
pre-commit run --from-ref "${FROM_REF}" --to-ref "${TO_REF}" --show-diff-on-failure --color=always
68+
env:
69+
FROM_REF: ${{ github.event.pull_request.base.sha }}
70+
TO_REF: ${{ github.event.pull_request.head.sha }}
71+
- name: Commit changes
72+
if: ${{ failure() && inputs.enable-commit-changes }}
73+
run: |-
74+
git add -A
75+
git config user.name "${GIT_AUTHOR_NAME}"
76+
git config user.email "${GIT_AUTHOR_EMAIL}"
77+
git commit -m "pre-commit fixes"
78+
git push origin "HEAD:${HEAD_REF}"
79+
exit 1
80+
env:
81+
HEAD_REF: ${{ github.event.pull_request.head.ref }}
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)