Skip to content

Commit d11299f

Browse files
committed
fix(.github/workflows): reuse cached .git repository for branch HEAD commit (#3893)
1 parent a0748eb commit d11299f

File tree

5 files changed

+78
-32
lines changed

5 files changed

+78
-32
lines changed

.github/workflows/main-branch-tests.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
name: Main Branch and Release Tests
22

33
on:
4-
workflow_call: # allows to reuse this workflow
5-
inputs:
6-
ref:
7-
description: 'The branch to run the workflow on'
8-
required: true
9-
type: string
104
push:
115
branches:
126
- release-v*
@@ -31,4 +25,3 @@ jobs:
3125
pull-requests: write
3226
with:
3327
go-version: "1.25" # Should be the highest supported version of Go
34-
ref: ${{ github.sha }}

.github/workflows/multios-unit-tests.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ on:
44
workflow_dispatch: # manually
55
inputs:
66
go-version:
7+
description: The Go version to use
78
required: true
89
type: string
910
runs-on:
10-
required: true
11-
type: string
12-
ref:
13-
description: 'The branch to run the workflow on'
11+
description: The OS to run the tests on
1412
required: true
1513
type: string
1614
workflow_call:
@@ -21,10 +19,6 @@ on:
2119
runs-on:
2220
required: true
2321
type: string
24-
ref:
25-
description: 'The branch to run the workflow on'
26-
required: true
27-
type: string
2822

2923
env:
3024
DD_APPSEC_WAF_TIMEOUT: 1m # Increase time WAF time budget to reduce CI flakiness
@@ -51,10 +45,16 @@ jobs:
5145
shell: pwsh
5246
run: |
5347
"normalized_workspace=${{ github.workspace }}" >> $env:GITHUB_ENV
48+
- name: Restore repo cache
49+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
50+
with:
51+
path: .git
52+
key: gitdb-${{ github.repository_id }}-${{ github.sha }}
5453
- name: Checkout
5554
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v2.7.0
5655
with:
57-
ref: ${{ inputs.ref || github.ref }}
56+
ref: ${{ github.sha }}
57+
clean: false
5858
- name: Setup Go and development tools
5959
uses: ./.github/actions/setup-go
6060
with:
@@ -64,7 +64,7 @@ jobs:
6464
- name: Mac OS Coreutils
6565
if: inputs.runs-on == 'macos-latest'
6666
run: brew install coreutils
67-
- name: "Runner ${{ matrix.runner-index }}: Test Core and Contrib (No Integration Tests)"
67+
- name: "Runner: Test Core and Contrib (No Integration Tests)"
6868
shell: bash
6969
run: |
7070
export PATH="${{ github.workspace }}/bin:${PATH}"

.github/workflows/pull-request.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,33 @@ concurrency:
1212
cancel-in-progress: true
1313

1414
jobs:
15+
warm-repo-cache:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
20+
with:
21+
ref: ${{ github.event.pull_request.head.sha }}
22+
- name: Cache
23+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
24+
with:
25+
path: .git
26+
key: gitdb-${{ github.repository_id }}-${{ github.sha }}
1527
unit-integration-tests:
1628
name: PR Unit and Integration Tests
29+
needs:
30+
- warm-repo-cache
1731
strategy:
1832
matrix:
1933
go-version: [ "1.24", "1.25" ]
2034
fail-fast: false
2135
uses: ./.github/workflows/unit-integration-tests.yml
2236
with:
2337
go-version: ${{ matrix.go-version }}
24-
ref: ${{ github.sha }}
2538
secrets: inherit
2639
multios-unit-tests:
40+
needs:
41+
- warm-repo-cache
2742
strategy:
2843
matrix:
2944
runs-on: [ macos-latest, windows-latest, ubuntu-latest ]
@@ -33,7 +48,6 @@ jobs:
3348
with:
3449
go-version: ${{ matrix.go-version }}
3550
runs-on: ${{ matrix.runs-on }}
36-
ref: ${{ github.sha }}
3751
secrets: inherit
3852
# This is a simple join point to make it easy to set up branch protection rules in GitHub.
3953
pull-request-tests-done:

.github/workflows/system-tests.yml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,32 @@ permissions:
3737
packages: write
3838

3939
jobs:
40+
warm-repo-cache:
41+
runs-on: ubuntu-latest
42+
outputs:
43+
sha: ${{ steps.pin.outputs.sha }}
44+
steps:
45+
- name: Checkout system-tests
46+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
47+
with:
48+
repository: 'DataDog/system-tests'
49+
ref: ${{ inputs.ref }}
50+
- name: Pin exact commit SHA for system-tests
51+
id: pin
52+
run: |
53+
echo "sha=$(git rev-parse FETCH_HEAD)" >> "$GITHUB_OUTPUT"
54+
- name: Cache
55+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
56+
with:
57+
path: .git
58+
key: gitdb-system-tests-${{ steps.pin.outputs.sha }}
4059
system-tests:
4160
if: github.event_name != 'pull_request' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'DataDog/dd-trace-go')
4261
# Note: Not using large runners because the jobs spawned by this pipeline
4362
# don't seem to get a noticable speedup from using larger runners.
4463
runs-on: ubuntu-latest
64+
needs:
65+
- warm-repo-cache
4566
strategy:
4667
matrix:
4768
weblog-variant:
@@ -128,11 +149,17 @@ jobs:
128149
SYSTEM_TESTS_E2E_DD_APP_KEY: ${{ secrets.SYSTEM_TESTS_E2E_DD_APP_KEY }}
129150
name: Test (${{ matrix.weblog-variant }}, ${{ matrix.scenario }})
130151
steps:
131-
- name: Checkout system tests
132-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
152+
- name: Restore repo cache
153+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
133154
with:
134-
repository: 'DataDog/system-tests'
135-
ref: ${{ inputs.ref }}
155+
path: .git
156+
key: gitdb-system-tests-${{ needs.warm-repo-cache.outputs.sha }}
157+
158+
- name: Checkout system tests
159+
shell: bash
160+
run: |
161+
git config safe.directory "$GITHUB_WORKSPACE"
162+
git checkout -f ${{ needs.warm-repo-cache.outputs.sha }}
136163
137164
- name: Checkout dd-trace-go
138165
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

.github/workflows/unit-integration-tests.yml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ on:
66
go-version:
77
required: true
88
type: string
9-
ref:
10-
description: 'The branch to run the workflow on'
11-
required: true
12-
type: string
139

1410
env:
1511
DD_APPSEC_WAF_TIMEOUT: 1m # Increase time WAF time budget to reduce CI flakiness
@@ -32,10 +28,16 @@ jobs:
3228
outputs:
3329
matrix: ${{ steps.matrix.outputs.matrix }}
3430
steps:
31+
- name: Restore repo cache
32+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
33+
with:
34+
path: .git
35+
key: gitdb-${{ github.repository_id }}-${{ github.sha }}
3536
- name: Checkout
3637
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3738
with:
38-
ref: ${{ inputs.ref || github.ref }}
39+
ref: ${{ github.sha }}
40+
clean: false
3941

4042
- name: Compute Matrix
4143
id: matrix
@@ -202,11 +204,16 @@ jobs:
202204
ports:
203205
- 4566:4566
204206
steps:
207+
- name: Restore repo cache
208+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
209+
with:
210+
path: .git
211+
key: gitdb-${{ github.repository_id }}-${{ github.sha }}
205212
- name: Checkout
206213
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
207214
with:
208-
ref: ${{ inputs.ref || github.ref }}
209-
fetch-depth: $(( ${{ github.event_name == 'pull_request' && github.event.pull_request.commits || 0 }} + 1 ))
215+
ref: ${{ github.sha }}
216+
clean: false
210217

211218
- name: Setup Go and development tools
212219
uses: ./.github/actions/setup-go
@@ -274,11 +281,16 @@ jobs:
274281
- 8125:8125/udp
275282
- 8126:8126
276283
steps:
284+
- name: Restore repo cache
285+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
286+
with:
287+
path: .git
288+
key: gitdb-${{ github.repository_id }}-${{ github.sha }}
277289
- name: Checkout
278290
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
279291
with:
280-
ref: ${{ inputs.ref || github.ref }}
281-
fetch-depth: $(( ${{ github.event_name == 'pull_request' && github.event.pull_request.commits || 0 }} + 1 ))
292+
ref: ${{ github.sha }}
293+
clean: false
282294
- name: Setup Go and development tools
283295
uses: ./.github/actions/setup-go
284296
with:

0 commit comments

Comments
 (0)