Skip to content

Commit fe6874c

Browse files
authored
chore: add source caching to CI (#403)
* chore: add source caching * chore: fix caching_enabled syntax * chore: fix sources hash using wrong variable * chore: print source files for better log clarity * chore: print source files for better log clarity * chore: minor language adjustment * chore: fix issue where act could not connect to cache server * chore: fix caching_enabled typo * chore: add directory check to source code validation * chore: log all missing source files instead of first found * chore: re-add check to make ci (other jobs depend on it) * chore: add fips.go to sources hash
1 parent 6f244a7 commit fe6874c

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

.actrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
-P ubuntu-latest=catthehacker/ubuntu:act-latest
44
-e event.json
55
--artifact-server-path $PWD/.artifacts
6-
--bind
6+
--bind
7+
--cache-server-addr host.docker.internal

.github/workflows/ci-base.yaml

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ on:
4141
permissions:
4242
contents: read
4343

44+
env:
45+
caching_enabled: ${{ !inputs.nightly }}
46+
4447
jobs:
4548
build:
4649
runs-on: ubuntu-latest
@@ -54,13 +57,77 @@ jobs:
5457
uses: actions/setup-go@v5
5558
with:
5659
go-version: "~1.24"
60+
cache: ${{ env.caching_enabled }}
5761

5862
- name: Tidy go.mod files
5963
run: go mod tidy
6064

61-
- name: Verify build
65+
- name: Ensure goreleaser up to date
66+
run: make check
67+
68+
- name: Generate sources cache key
69+
id: sources-cache-key
70+
if: ${{ env.caching_enabled }}
71+
run: |
72+
SOURCES_HASH="${{ hashFiles(
73+
format('distributions/{0}/manifest.yaml', inputs.distribution),
74+
'scripts/build.sh',
75+
'Makefile',
76+
'fips/fips.go'
77+
) }}"
78+
echo "sources_key=sources-${{ inputs.distribution }}-${SOURCES_HASH}" >> $GITHUB_OUTPUT
79+
80+
- name: Cache sources
81+
id: cache-sources
82+
uses: actions/cache@v4
83+
if: ${{ env.caching_enabled }}
84+
with:
85+
path: |
86+
distributions/${{ inputs.distribution }}/_build
87+
distributions/${{ inputs.distribution }}/_build-fips
88+
key: ${{ steps.sources-cache-key.outputs.sources_key }}
89+
90+
- name: Generate sources
91+
if: steps.cache-sources.outputs.cache-hit != 'true'
6292
run: make ci DISTRIBUTIONS=${{ inputs.distribution }}
6393

94+
- name: Skip source generation (cached)
95+
if: steps.cache-sources.outputs.cache-hit == 'true'
96+
run: echo "✅ Source generation skipped - no source changes detected"
97+
98+
- 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+
64131
- name: Login to Docker
65132
uses: docker/login-action@v3
66133
if: ${{ env.ACT }}

0 commit comments

Comments
 (0)