Skip to content

Commit ceecfa2

Browse files
committed
chore: test ci optimizations
1 parent 3c4580b commit ceecfa2

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

.github/workflows/ci-base.yaml

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,34 @@ jobs:
5555
- name: Tidy go.mod files
5656
run: go mod tidy
5757

58-
- name: Verify build
58+
- name: Generate cache keys
59+
id: cache-keys
60+
run: |
61+
# Base hash for source generation (inputs that affect generation)
62+
SOURCE_HASH="${{ hashFiles('distributions/${{ inputs.distribution }}/manifest.yaml', 'distributions/${{ inputs.distribution }}/_build/go.mod', 'distributions/${{ inputs.distribution }}/_build/go.sum', 'Makefile') }}"
63+
# Extended hash for Docker build (includes generated sources)
64+
DOCKER_HASH="${{ hashFiles('distributions/${{ inputs.distribution }}/Dockerfile', 'distributions/${{ inputs.distribution }}/manifest.yaml', 'distributions/${{ inputs.distribution }}/_build/go.mod', 'distributions/${{ inputs.distribution }}/_build/go.sum') }}"
65+
echo "source_key=generate-sources-${{ inputs.distribution }}-${SOURCE_HASH}" >> $GITHUB_OUTPUT
66+
echo "docker_key=${{ inputs.distribution }}-${{ github.ref_name }}-${DOCKER_HASH}" >> $GITHUB_OUTPUT
67+
68+
- name: Cache sources
69+
id: cache-sources
70+
uses: actions/cache@v4
71+
with:
72+
path: distributions/${{ inputs.distribution }}/_build
73+
key: ${{ steps.cache-keys.outputs.source_key }}
74+
restore-keys: |
75+
generate-sources-${{ inputs.distribution }}-${{ hashFiles('distributions/${{ inputs.distribution }}/manifest.yaml') }}
76+
generate-sources-${{ inputs.distribution }}-
77+
78+
- name: Generate sources
79+
if: steps.cache-sources.outputs.cache-hit != 'true'
5980
run: make ci DISTRIBUTIONS=${{ inputs.distribution }}
6081

82+
- name: Skip source generation (cached)
83+
if: steps.cache-sources.outputs.cache-hit == 'true'
84+
run: echo "✅ Source generation skipped - no source changes detected"
85+
6186
- name: Login to Docker
6287
uses: docker/login-action@v3
6388
if: ${{ env.ACT }}
@@ -92,10 +117,8 @@ jobs:
92117
run: |
93118
if [ ${{ inputs.nightly }} = "true" ]; then
94119
echo "goreleaser_args=--snapshot --clean --skip=publish,validate --timeout 2h --config .goreleaser-nightly.yaml" >> $GITHUB_ENV
95-
elif [ ${{github.event.pull_request.user.login == 'dependabot[bot]' }} ]; then
96-
echo "goreleaser_args=--snapshot --clean --skip=publish,validate,sign --timeout 2h" >> $GITHUB_ENV
97120
else
98-
echo "goreleaser_args=--snapshot --clean --skip=publish,validate --timeout 2h" >> $GITHUB_ENV
121+
echo "goreleaser_args=build --single-target --snapshot --clean" >> $GITHUB_ENV
99122
fi
100123
101124
- name: Build binaries & packages with GoReleaser
@@ -112,7 +135,8 @@ jobs:
112135
args: ${{ env.goreleaser_args }}
113136
workdir: distributions/${{ inputs.distribution }}
114137

115-
- name: Extract relevant metadata
138+
- name: Extract relevant metadata from GoReleaser output
139+
if: ${{ inputs.nightly }} = "true"
116140
run: |
117141
VERSION=$(echo '${{ steps.goreleaser.outputs.metadata }}' | jq -r '.version')
118142
ARCH=$(echo '${{ runner.arch }}' | sed 's/X/amd/g')
@@ -125,6 +149,29 @@ jobs:
125149
echo "image_tag=$VERSION-$ARCH" >> $GITHUB_ENV
126150
fi
127151
152+
- name: Copy GoReleaser binary to Docker context
153+
if: ${{ inputs.nightly }} = "false"
154+
run: |
155+
cd distributions/${{ inputs.distribution }}
156+
BINARY_PATH="$(find dist -name "${{ inputs.distribution }}_linux_amd64*" -type d)/${{ inputs.distribution }}"
157+
cp "$BINARY_PATH" ./${{ inputs.distribution }}
158+
159+
- name: Build and load Docker image
160+
uses: docker/build-push-action@v5
161+
if: ${{ inputs.nightly }} = "false"
162+
with:
163+
context: distributions/${{ inputs.distribution }}
164+
platforms: linux/amd64
165+
push: false
166+
load: true
167+
tags: |
168+
${{ secrets.registry }}/${{ inputs.distribution }}:${{ env.image_tag }}
169+
cache-from: |
170+
type=gha,scope=${{ steps.cache-keys.outputs.docker_key }}
171+
type=gha,scope=${{ inputs.distribution }}-${{ github.ref_name }}
172+
type=gha,scope=${{ inputs.distribution }}-main
173+
cache-to: type=gha,mode=max,scope=${{ steps.cache-keys.outputs.docker_key }}
174+
128175
- name: Setup local kind cluster
129176
uses: helm/kind-action@v1
130177
with:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ GO_LICENCE_DETECTOR_CONFIG := $(SRC_ROOT)/internal/assets/license/rules.json
1818

1919
DISTRIBUTIONS ?= "nrdot-collector-host,nrdot-collector-k8s,nrdot-collector"
2020

21-
ci: check build version-check licenses-check
21+
ci: check generate-sources version-check licenses-check
2222
check: ensure-goreleaser-up-to-date
2323

2424
build: go ocb

distributions/nrdot-collector/.goreleaser-nightly.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ nfpms:
6767
formats:
6868
- deb
6969
- rpm
70-
maintainer: New Relic <caos-team@newrelic.com>
70+
maintainer: New Relic <otelcomm-team@newrelic.com>
7171
description: NRDOT Collector - nrdot-collector
7272
license: Apache 2.0
7373
snapshot:

distributions/nrdot-collector/.goreleaser.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ nfpms:
6767
formats:
6868
- deb
6969
- rpm
70-
maintainer: New Relic <caos-team@newrelic.com>
70+
maintainer: New Relic <otelcomm-team@newrelic.com>
7171
description: NRDOT Collector - nrdot-collector
7272
license: Apache 2.0
7373
snapshot:

0 commit comments

Comments
 (0)