Skip to content

Commit 14b50f1

Browse files
authored
convert go testing workflow to reusable workflow (#3317)
1 parent ddc6ae6 commit 14b50f1

2 files changed

Lines changed: 83 additions & 21 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Reusable Go Testing Workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
enable-status-reporting:
7+
description: 'Whether to post status checks to datadog-api-spec repo'
8+
required: false
9+
type: boolean
10+
default: false
11+
status-context:
12+
description: 'Context for status checks'
13+
required: false
14+
type: string
15+
default: 'master/unit'
16+
secrets:
17+
# Optional: Only needed for cross-repository status reporting when called
18+
# from external repos (e.g., datadog-api-spec) for generated code changes
19+
PIPELINE_GITHUB_APP_ID:
20+
required: false
21+
PIPELINE_GITHUB_APP_PRIVATE_KEY:
22+
required: false
23+
24+
jobs:
25+
test:
26+
strategy:
27+
matrix:
28+
go-version: ["1.22.x", "1.23.x"]
29+
go-build-tags: ["--tags=goccy_gojson", ""]
30+
platform: ["ubuntu-latest"]
31+
runs-on: ${{ matrix.platform }}
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v3
35+
- name: Install Go
36+
uses: actions/setup-go@v4
37+
with:
38+
go-version: ${{ matrix.go-version }}
39+
cache: true
40+
cache-dependency-path: tests/go.sum
41+
- name: Test
42+
run: ./run-tests.sh
43+
env:
44+
TESTARGS: ${{ matrix.go-build-tags }}
45+
46+
report:
47+
runs-on: ubuntu-latest
48+
if: always() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/') && inputs.enable-status-reporting
49+
needs:
50+
- test
51+
steps:
52+
- name: Get GitHub App token
53+
if: github.event_name == 'pull_request'
54+
id: get_token
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+
repositories: datadog-api-spec
60+
- name: Post status check
61+
uses: DataDog/github-actions/post-status-check@v2
62+
with:
63+
github-token: ${{ steps.get_token.outputs.token }}
64+
repo: datadog-api-spec
65+
status: ${{ needs.test.result == 'cancelled' && 'pending' || needs.test.result == 'success' && 'success' || 'failure' }}
66+
context: ${{ inputs.status-context }}

.github/workflows/test.yml

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,30 +79,26 @@ jobs:
7979
pre-commit run --all-files --show-diff-on-failure --color=always
8080
8181
test:
82-
strategy:
83-
matrix:
84-
go-version: [1.22.x, 1.23.x]
85-
go-build-tags: ["--tags=goccy_gojson", ""]
86-
platform: [ubuntu-latest]
87-
runs-on: ${{ matrix.platform }}
88-
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'
89-
steps:
90-
- name: Checkout code
91-
uses: actions/checkout@v3
92-
- name: Install Go
93-
uses: actions/setup-go@v4
94-
with:
95-
go-version: ${{ matrix.go-version }}
96-
cache: true
97-
cache-dependency-path: tests/go.sum
98-
- name: Test
99-
run: ./run-tests.sh
100-
env:
101-
TESTARGS: ${{ matrix.go-build-tags }}
82+
if: >
83+
(github.event.pull_request.draft == false &&
84+
!contains(github.event.pull_request.labels.*.name, 'ci/skip') &&
85+
!contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) ||
86+
github.event_name == 'schedule'
87+
uses: ./.github/workflows/reusable-go-test.yml
88+
with:
89+
enable-status-reporting: true
90+
status-context: 'master/unit'
91+
secrets:
92+
PIPELINE_GITHUB_APP_ID: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
93+
PIPELINE_GITHUB_APP_PRIVATE_KEY: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
10294

10395
examples:
10496
runs-on: ubuntu-latest
105-
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'
97+
if: >
98+
(github.event.pull_request.draft == false &&
99+
!contains(github.event.pull_request.labels.*.name, 'ci/skip') &&
100+
!contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) ||
101+
github.event_name == 'schedule'
106102
steps:
107103
- uses: actions/checkout@v3
108104
- name: Install Go

0 commit comments

Comments
 (0)