Skip to content

Commit 23d109a

Browse files
IONOS(build): enhance cache handling with optional version suffix and specific app rebuilds
Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
1 parent 16fe2cd commit 23d109a

File tree

2 files changed

+77
-5
lines changed

2 files changed

+77
-5
lines changed

.github/scripts/detect-app-cache.sh

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ set -o pipefail # Exit if any command in pipeline fails
1717
: "${FORCE_REBUILD:?FORCE_REBUILD not set}"
1818
: "${ARTIFACTORY_REPOSITORY_SNAPSHOT:?ARTIFACTORY_REPOSITORY_SNAPSHOT not set}"
1919

20-
# Optional JFrog variables
20+
# Optional variables
21+
APPS_TO_REBUILD="${APPS_TO_REBUILD:-}"
2122
JF_URL="${JF_URL:-}"
2223
JF_USER="${JF_USER:-}"
2324
JF_ACCESS_TOKEN="${JF_ACCESS_TOKEN:-}"
@@ -34,7 +35,11 @@ JF_ACCESS_TOKEN="${JF_ACCESS_TOKEN:-}"
3435
# - has_apps_to_restore: boolean flag
3536

3637
echo "Collecting app SHAs and checking cache status..."
38+
echo "Cache version: $CACHE_VERSION"
3739
echo "Force rebuild mode: $FORCE_REBUILD"
40+
if [ -n "$APPS_TO_REBUILD" ]; then
41+
echo "Apps to rebuild: $APPS_TO_REBUILD"
42+
fi
3843
echo ""
3944

4045
# Setup JFrog CLI if credentials are available
@@ -92,17 +97,34 @@ echo ""
9297

9398
echo "### 📦 Cache Status Report for ($GITHUB_REF)" >> "$GITHUB_STEP_SUMMARY"
9499
echo "" >> "$GITHUB_STEP_SUMMARY"
100+
echo "**Cache Version:** \`$CACHE_VERSION\`" >> "$GITHUB_STEP_SUMMARY"
101+
echo "" >> "$GITHUB_STEP_SUMMARY"
95102
if [ "$FORCE_REBUILD" == "true" ]; then
96103
echo "**🔄 FORCE REBUILD MODE ENABLED** - All caches bypassed" >> "$GITHUB_STEP_SUMMARY"
97104
echo "" >> "$GITHUB_STEP_SUMMARY"
98105
fi
106+
if [ -n "$APPS_TO_REBUILD" ]; then
107+
echo "**🔨 Specific apps to rebuild:** \`$APPS_TO_REBUILD\`" >> "$GITHUB_STEP_SUMMARY"
108+
echo "" >> "$GITHUB_STEP_SUMMARY"
109+
fi
99110
if [ "$JFROG_AVAILABLE" == "true" ]; then
100111
echo "**🎯 JFrog Artifact Cache**: Enabled for all branches" >> "$GITHUB_STEP_SUMMARY"
101112
echo "" >> "$GITHUB_STEP_SUMMARY"
102113
fi
103114
echo "| App | SHA | Cache Key | Status |" >> "$GITHUB_STEP_SUMMARY"
104115
echo "|-----|-----|-----------|--------|" >> "$GITHUB_STEP_SUMMARY"
105116

117+
# Convert comma-separated apps list to array for easier checking
118+
if [ -n "$APPS_TO_REBUILD" ]; then
119+
IFS=',' read -ra REBUILD_APPS_ARRAY <<< "$APPS_TO_REBUILD"
120+
# Trim whitespace from each app name using xargs for readability
121+
for i in "${!REBUILD_APPS_ARRAY[@]}"; do
122+
REBUILD_APPS_ARRAY[$i]=$(echo "${REBUILD_APPS_ARRAY[$i]}" | xargs)
123+
done
124+
else
125+
REBUILD_APPS_ARRAY=()
126+
fi
127+
106128
# Iterate through each app in the matrix
107129
while IFS= read -r app_json; do
108130
APP_NAME=$(echo "$app_json" | jq -r '.name')
@@ -148,6 +170,23 @@ while IFS= read -r app_json; do
148170
continue
149171
fi
150172

173+
# Check if this specific app should be rebuilt (ignore cache)
174+
REBUILD_THIS_APP=false
175+
for rebuild_app in "${REBUILD_APPS_ARRAY[@]}"; do
176+
if [ "$APP_NAME" == "$rebuild_app" ]; then
177+
REBUILD_THIS_APP=true
178+
break
179+
fi
180+
done
181+
182+
if [ "$REBUILD_THIS_APP" == "true" ]; then
183+
echo "🔨 rebuild requested"
184+
echo "| $APP_NAME | \`$SHORT_SHA\` | \`$CACHE_KEY\` | 🔨 Rebuild requested |" >> "$GITHUB_STEP_SUMMARY"
185+
APPS_TO_BUILD=$(echo "$APPS_TO_BUILD" | jq -c --arg app "$APP_NAME" --arg sha "$CURRENT_SHA" '. + [{name: $app, sha: $sha}]')
186+
APPS_TO_BUILD_COUNT=$((APPS_TO_BUILD_COUNT + 1))
187+
continue
188+
fi
189+
151190
# Check JFrog first before GitHub cache (available for all branches)
152191
if [ "$JFROG_AVAILABLE" == "true" ]; then
153192
JFROG_PATH="${ARTIFACTORY_REPOSITORY_SNAPSHOT}/apps/${CACHE_VERSION}/${APP_NAME}/${APP_NAME}-${CURRENT_SHA}.tar.gz"

.github/workflows/build-artifact.yml

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ on:
3838
required: false
3939
type: boolean
4040
default: false
41+
cache_version_suffix:
42+
description: 'Optional cache version suffix (e.g., "test", "debug") - creates separate cache namespace'
43+
required: false
44+
type: string
45+
default: ''
46+
apps_to_rebuild:
47+
description: 'Comma-separated list of specific apps to rebuild (e.g., "app1,app2") - ignores cache for these apps only'
48+
required: false
49+
type: string
50+
default: ''
4151

4252
concurrency:
4353
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/ionos-dev' && github.run_id || github.event.pull_request.number || github.ref }}
@@ -66,7 +76,16 @@ jobs:
6676
apps_sha_map: ${{ steps.detect.outputs.apps_sha_map }}
6777
has_apps_to_build: ${{ steps.detect.outputs.has_apps_to_build }}
6878
has_apps_to_restore: ${{ steps.detect.outputs.has_apps_to_restore }}
79+
effective_cache_version: ${{ steps.compute_cache_version.outputs.effective_cache_version }}
6980
steps:
81+
- name: Compute effective cache version
82+
id: compute_cache_version
83+
run: |
84+
# Compute cache version with optional suffix to create a single source of truth
85+
EFFECTIVE_VERSION="${{ env.CACHE_VERSION }}${{ github.event.inputs.cache_version_suffix && format('-{0}', github.event.inputs.cache_version_suffix) || '' }}"
86+
echo "effective_cache_version=$EFFECTIVE_VERSION" >> "$GITHUB_OUTPUT"
87+
echo "Effective cache version: $EFFECTIVE_VERSION"
88+
7089
- name: Checkout repository
7190
uses: actions/checkout@v5
7291
with:
@@ -182,14 +201,21 @@ jobs:
182201
id: detect
183202
env:
184203
GH_TOKEN: ${{ github.token }}
185-
CACHE_VERSION: ${{ env.CACHE_VERSION }}
204+
CACHE_VERSION: ${{ steps.compute_cache_version.outputs.effective_cache_version }}
186205
FORCE_REBUILD: ${{ github.event.inputs.force_rebuild || 'false' }}
206+
APPS_TO_REBUILD: ${{ github.event.inputs.apps_to_rebuild || '' }}
187207
JF_URL: ${{ secrets.JF_ARTIFACTORY_URL }}
188208
JF_USER: ${{ secrets.JF_ARTIFACTORY_USER }}
189209
JF_ACCESS_TOKEN: ${{ secrets.JF_ACCESS_TOKEN }}
190210
ARTIFACTORY_REPOSITORY_SNAPSHOT: ${{ env.ARTIFACTORY_REPOSITORY_SNAPSHOT }}
191211
GITHUB_REF: ${{ github.ref }}
192212
run: |
213+
# Show effective cache version
214+
echo "Base CACHE_VERSION: ${{ env.CACHE_VERSION }}"
215+
echo "Cache version suffix: ${{ github.event.inputs.cache_version_suffix || '(none)' }}"
216+
echo "Effective CACHE_VERSION: ${CACHE_VERSION}"
217+
echo "Apps to rebuild: ${{ github.event.inputs.apps_to_rebuild || '(none)' }}"
218+
echo ""
193219
bash .github/scripts/detect-app-cache.sh '${{ steps.set_matrix.outputs.matrix }}'
194220
195221
build-external-apps:
@@ -287,7 +313,7 @@ jobs:
287313
uses: actions/cache/save@v4
288314
with:
289315
path: ${{ steps.app-config.outputs.path }}
290-
key: ${{ env.CACHE_VERSION }}-app-build-${{ matrix.app_info.name }}-${{ matrix.app_info.sha }}
316+
key: ${{ needs.prepare-matrix.outputs.effective_cache_version }}-app-build-${{ matrix.app_info.name }}-${{ matrix.app_info.sha }}
291317

292318
# Push to JFrog for ionos-dev branch builds
293319
- name: Setup JFrog CLI
@@ -319,11 +345,15 @@ jobs:
319345
APP_SHA="${{ matrix.app_info.sha }}"
320346
APP_PATH="${{ steps.app-config.outputs.path }}"
321347
348+
# Use precomputed effective cache version
349+
EFFECTIVE_CACHE_VERSION="${{ needs.prepare-matrix.outputs.effective_cache_version }}"
350+
322351
echo "=== JFrog Upload Debug Info ==="
323352
echo "📦 Packaging $APP_NAME for JFrog upload..."
324353
echo "App Name: $APP_NAME"
325354
echo "App SHA: $APP_SHA"
326355
echo "App Path: $APP_PATH"
356+
echo "Cache Version: $EFFECTIVE_CACHE_VERSION"
327357
echo "Repository: ${{ env.ARTIFACTORY_REPOSITORY_SNAPSHOT }}"
328358
echo "==============================="
329359
@@ -355,7 +385,7 @@ jobs:
355385
356386
# Upload to JFrog - store in snapshot repo under dev/apps/
357387
# Include CACHE_VERSION in path to enable complete cache invalidation
358-
JFROG_PATH="${{ env.ARTIFACTORY_REPOSITORY_SNAPSHOT }}/apps/${{ env.CACHE_VERSION }}/${APP_NAME}/${ARCHIVE_NAME}"
388+
JFROG_PATH="${{ env.ARTIFACTORY_REPOSITORY_SNAPSHOT }}/apps/${EFFECTIVE_CACHE_VERSION}/${APP_NAME}/${ARCHIVE_NAME}"
359389
360390
# Build properties for artifact metadata
361391
JFROG_PROPS_LIST=()
@@ -1176,9 +1206,12 @@ jobs:
11761206
echo ""
11771207
echo "### Workflow Inputs (if workflow_dispatch)"
11781208
echo "Force Rebuild: ${{ github.event.inputs.force_rebuild || 'N/A' }}"
1209+
echo "Cache Version Suffix: ${{ github.event.inputs.cache_version_suffix || 'N/A' }}"
1210+
echo "Apps to Rebuild: ${{ github.event.inputs.apps_to_rebuild || 'N/A' }}"
11791211
echo ""
11801212
echo "### Environment Variables"
1181-
echo "CACHE_VERSION: ${{ env.CACHE_VERSION }}"
1213+
echo "Base CACHE_VERSION: ${{ env.CACHE_VERSION }}"
1214+
echo "Effective CACHE_VERSION: ${{ needs.prepare-matrix.outputs.effective_cache_version }}"
11821215
echo "TARGET_PACKAGE_NAME: ${{ env.TARGET_PACKAGE_NAME }}"
11831216
echo "ARTIFACTORY_REPOSITORY_SNAPSHOT: ${{ env.ARTIFACTORY_REPOSITORY_SNAPSHOT }}"
11841217
echo ""

0 commit comments

Comments
 (0)