9696 run : echo "✅ Source generation skipped - no source changes detected"
9797
9898 - name : Verify source files exist
99- run : |
100- SOURCE_PATH="distributions/${{inputs.distribution}}/_build"
101- if [ ${{ inputs.fips }} = "true" ]; then
102- SOURCE_PATH="${SOURCE_PATH}-fips"
103- fi
104- if [ ! -d "$SOURCE_PATH" ]; then
105- echo "❌ $SOURCE_PATH not found!"
106- exit 1
107- fi
108- files=(
109- "build.log" "components.go" "go.mod" "go.sum"
110- "main_others.go" "main_windows.go" "main.go"
111- )
112- if [ ${{ inputs.fips }} = "true" ]; then
113- files+=("fips.go")
114- fi
115- cd "$SOURCE_PATH"
116- missing_files=()
117- for file in "${files[@]}"; do
118- if [ ! -f "$file" ]; then
119- missing_files+=("$file")
120- else
121- echo "Found: $file"
122- fi
123- done
124- if [ ${#missing_files[@]} -eq 0 ]; then
125- echo "✅ All source files found!"
126- else
127- echo "❌ files not found: ${missing_files[*]}"
128- exit 1
129- fi
130-
99+ run : ./scripts/validate-source-files.sh -d ${{ inputs.distribution }} -f ${{ inputs.fips }}
100+
131101 - name : Login to Docker
132102 uses : docker/login-action@v3
133103 if : ${{ env.ACT }}
@@ -174,17 +144,42 @@ jobs:
174144 run : |
175145 if [ ${{ inputs.nightly }} = "true" ] && [ ${{ inputs.fips }} = "true" ]; then
176146 echo "goreleaser_args=--snapshot --clean --skip=publish,validate --timeout 2h --config .goreleaser-nightly-fips.yaml" >> $GITHUB_ENV
147+ echo "goreleaser_file=.goreleaser-nightly-fips.yaml" >> $GITHUB_ENV
177148 elif [ ${{ inputs.nightly }} = "true" ]; then
178149 echo "goreleaser_args=--snapshot --clean --skip=publish,validate --timeout 2h --config .goreleaser-nightly.yaml" >> $GITHUB_ENV
150+ echo "goreleaser_file=.goreleaser-nightly.yaml" >> $GITHUB_ENV
179151 elif [ ${{ inputs.fips }} = "true" ]; then
180152 echo "goreleaser_args=--snapshot --clean --skip=publish,validate --timeout 2h --config .goreleaser-fips.yaml" >> $GITHUB_ENV
153+ echo "goreleaser_file=.goreleaser-fips.yaml" >> $GITHUB_ENV
181154 elif [ ${{github.event.pull_request.user.login == 'dependabot[bot]' }} ]; then
182155 echo "goreleaser_args=--snapshot --clean --skip=publish,validate,sign --timeout 2h" >> $GITHUB_ENV
156+ echo "goreleaser_file=.goreleaser.yaml" >> $GITHUB_ENV
183157 else
184158 echo "goreleaser_args=--snapshot --clean --skip=publish,validate --timeout 2h" >> $GITHUB_ENV
159+ echo "goreleaser_file=.goreleaser.yaml" >> $GITHUB_ENV
185160 fi
186161
162+ - name : Generate binary cache key
163+ id : generate_binary_key
164+ run : |
165+ BINARY_HASH="${{ hashFiles(
166+ format('distributions/{0}/.goreleaser*.yaml', inputs.distribution),
167+ format('distributions/{0}/_build*/*', inputs.distribution)
168+ ) }}"
169+ ARGS_HASH=$(echo "${{ env.goreleaser_args }}" | sha256sum | cut -d' ' -f1)
170+ echo binary_key=goreleaser-build-${{ inputs.distribution }}-${ARGS_HASH}-${BINARY_HASH} >> $GITHUB_OUTPUT
171+
172+ - name : Cache goreleaser build
173+ id : cache-goreleaser
174+ if : ${{ env.caching_enabled }}
175+ uses : actions/cache@v4
176+ with :
177+ path : |
178+ distributions/${{ inputs.distribution }}/dist
179+ key : ${{ steps.generate_binary_key.outputs.binary_key }}
180+
187181 - name : Build binaries & packages with GoReleaser
182+ if : steps.cache-goreleaser.outputs.cache-hit != 'true'
188183 id : goreleaser
189184 uses : goreleaser/goreleaser-action@v6
190185 env :
@@ -197,10 +192,24 @@ jobs:
197192 version : ' 2.11.2'
198193 args : ${{ env.goreleaser_args }}
199194 workdir : distributions/${{ inputs.distribution }}
195+
196+ - name : Skip GoReleaser build (cached)
197+ if : steps.cache-goreleaser.outputs.cache-hit == 'true'
198+ run : echo "✅ GoReleaser build skipped - using cached binaries"
200199
200+ - name : Validate GoReleaser build
201+ run : ./scripts/validate-goreleaser-build.sh -d ${{ inputs.distribution }}
202+
201203 - name : Extract relevant metadata
202204 run : |
203- VERSION=$(echo '${{ steps.goreleaser.outputs.metadata }}' | jq -r '.version')
205+ if [ "${{ steps.cache-goreleaser.outputs.cache-hit }}" = "true" ]; then
206+ VERSION=$(jq -r '.version' distributions/${{ inputs.distribution }}/dist/metadata.json)
207+ echo "Using cached version: $VERSION"
208+ else
209+ # Extract from fresh GoReleaser build
210+ VERSION=$(echo '${{ steps.goreleaser.outputs.metadata }}' | jq -r '.version')
211+ echo "Using fresh build version: $VERSION"
212+ fi
204213 ARCH=$(echo '${{ runner.arch }}' | sed 's/X/amd/g')
205214 ARCH=${ARCH@L}
206215 echo "version=$VERSION" >> $GITHUB_ENV
@@ -215,6 +224,45 @@ jobs:
215224 echo "image_tag=$VERSION-$ARCH" >> $GITHUB_ENV
216225 fi
217226
227+ - name : Copy GoReleaser binary to Docker context
228+ id : copy-binary
229+ if : steps.cache-goreleaser.outputs.cache-hit == 'true'
230+ run : |
231+ cd distributions/${{ inputs.distribution }}
232+ BINARY_PATH="$(find dist -name "${{ inputs.distribution }}*_linux_${{ env.arch }}*" -type d)/${{ inputs.distribution }}"
233+ if [ ${{ inputs.fips }} = "true" ]; then
234+ BINARY_PATH+="-fips"
235+ fi
236+ if [ ! -f "$BINARY_PATH" ]; then
237+ echo "❌ Error: Binary not found at $BINARY_PATH"
238+ find dist -name "*${{ inputs.distribution }}*" -type f
239+ exit 1
240+ fi
241+ # move dockerfile dependencies to .tmp for easy cleanup when running in Act
242+ BINARY_TMP="${{ runner.temp }}/docker/${{ inputs.distribution }}"
243+ if [ ${{ inputs.fips }} = "true" ]; then
244+ BINARY_TMP+="-fips"
245+ fi
246+ mkdir -p ${BINARY_TMP}
247+ cp "$BINARY_PATH" "${BINARY_TMP}/${{ inputs.distribution }}"
248+ cp Dockerfile ${BINARY_TMP}
249+ for file in $(yq ".dockers[] | select(.goarch == \"${{ env.arch }}\") | .extra_files[]" ${{ env.goreleaser_file }}); do
250+ cp "${file}" ${BINARY_TMP}
251+ done
252+ echo "✅ Binary copied: $(ls -la ${BINARY_TMP})"
253+ echo "binary_tmp=${BINARY_TMP}" >> $GITHUB_OUTPUT
254+
255+ - name : Build and load Docker image
256+ uses : docker/build-push-action@v5
257+ if : steps.cache-goreleaser.outputs.cache-hit == 'true'
258+ with :
259+ context : ${{ steps.copy-binary.outputs.binary_tmp }}
260+ platforms : linux/${{ env.arch }}
261+ push : false
262+ load : true
263+ tags : |
264+ ${{ secrets.registry }}/${{ inputs.distribution }}:${{ env.image_tag }}
265+
218266 - name : Validate Usage of BoringCrypto
219267 if : inputs.fips
220268 run : |
0 commit comments