@@ -133,6 +133,35 @@ jobs:
133133 echo "SHOULD_BUILD=false" >> $GITHUB_ENV
134134 fi
135135
136+ - name : Download existing release assets (if any)
137+ if : env.SHOULD_BUILD == 'true'
138+ env :
139+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
140+ run : |
141+ echo "📥 Checking for existing 'latest' release assets..."
142+
143+ # Check if latest release exists
144+ if gh release view latest >/dev/null 2>&1; then
145+ echo "✅ Found existing 'latest' release"
146+
147+ # Download existing assets to preserve them
148+ mkdir -p existing_assets
149+ gh release download latest --dir existing_assets 2>/dev/null || echo "No assets to download"
150+
151+ # Move existing assets to artifacts directory
152+ for existing_zip in existing_assets/*.zip; do
153+ if [ -f "$existing_zip" ]; then
154+ FILENAME=$(basename "$existing_zip")
155+ echo "📦 Preserving existing: $FILENAME"
156+ cp "$existing_zip" "artifacts/"
157+ fi
158+ done
159+
160+ rm -rf existing_assets
161+ else
162+ echo "ℹ️ No existing 'latest' release found"
163+ fi
164+
136165 - name : Build quickstart packages from configs
137166 if : env.SHOULD_BUILD == 'true'
138167 run : |
@@ -141,118 +170,154 @@ jobs:
141170 # Store the absolute path to artifacts directory
142171 ARTIFACTS_DIR="$(pwd)/artifacts"
143172
173+ # Get changed files to determine which directories to rebuild
174+ CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "")
175+
176+ # Check if workflow file changed (rebuild all if so)
177+ REBUILD_ALL=false
178+ if echo "$CHANGED_FILES" | grep -q "^\.github/workflows/create-sample-releases\.yml$"; then
179+ echo "🔧 Workflow file changed - rebuilding ALL samples"
180+ REBUILD_ALL=true
181+ elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
182+ echo "🔄 Manual trigger - rebuilding ALL samples"
183+ REBUILD_ALL=true
184+ elif [ "${{ github.event.inputs.force_rebuild }}" = "true" ]; then
185+ echo "🔄 Force rebuild requested - rebuilding ALL samples"
186+ REBUILD_ALL=true
187+ elif [ -z "$CHANGED_FILES" ]; then
188+ echo "📝 No changed files detected - rebuilding ALL samples"
189+ REBUILD_ALL=true
190+ fi
191+
144192 find . -name "release-config.yml" -not -path "./.git/*" | while read config_file; do
145193 sample_dir=$(dirname "$config_file")
194+ clean_dir=$(echo "$sample_dir" | sed 's|^\./||')
146195
147- echo "🔨 Processing: $config_file"
148- cd "$sample_dir"
149-
150- # Check if this sample should be included
151- INCLUDED=$(grep "^included:" release-config.yml | sed 's/included: *//' | tr -d ' ')
152- if [ "$INCLUDED" != "true" ]; then
153- echo "⏭️ Skipping (included: $INCLUDED)"
154- cd - > /dev/null
155- continue
156- fi
157-
158- # Extract configuration using basic shell parsing
159- CATEGORY=$(grep "^category:" release-config.yml | sed 's/category: *"//' | sed 's/"$//' | tr -d ' ')
160- FRAMEWORK=$(grep "^framework:" release-config.yml | sed 's/framework: *"//' | sed 's/"$//' | tr -d ' ')
196+ # Check if this specific directory should be rebuilt
197+ SHOULD_REBUILD=false
161198
162- if [ -z "$CATEGORY" ] || [ -z "$FRAMEWORK" ]; then
163- echo "❌ Missing category or framework in $config_file"
164- cd - > /dev/null
199+ if [ "$REBUILD_ALL" = "true" ]; then
200+ SHOULD_REBUILD=true
201+ echo "🔨 Processing: $config_file (rebuild all)"
202+ elif echo "$CHANGED_FILES" | grep -q "^$clean_dir/"; then
203+ SHOULD_REBUILD=true
204+ echo "🔨 Processing: $config_file (changes detected in $clean_dir)"
205+ else
206+ echo "⏭️ Skipping: $config_file (no changes in $clean_dir)"
165207 continue
166208 fi
167209
168- # Build zip filename from category and framework
169- ZIP_FILENAME="${CATEGORY}-${FRAMEWORK}-sample"
170-
171- echo "📦 Building: $ZIP_FILENAME.zip"
172- echo "🏷️ Category: $CATEGORY, Framework: $FRAMEWORK"
173- echo "📁 Current directory: $(pwd)"
174- echo "📁 Artifacts directory: $ARTIFACTS_DIR"
175-
176- # Create zip with absolute path to artifacts directory
177- zip -r "${ARTIFACTS_DIR}/${ZIP_FILENAME}.zip" . \
178- --exclude=".git/*" \
179- --exclude="node_modules/*" \
180- --exclude="__pycache__/*" \
181- --exclude="*.pyc" \
182- --exclude="*.pyo" \
183- --exclude="dist/*" \
184- --exclude="build/*" \
185- --exclude="venv/*" \
186- --exclude=".venv/*" \
187- --exclude=".pytest_cache/*" \
188- --exclude=".coverage" \
189- --exclude="coverage/*" \
190- --exclude="*.log" \
191- --exclude=".DS_Store" \
192- --exclude="Thumbs.db" \
193- --exclude=".idea/*" \
194- --exclude=".vscode/*" \
195- --exclude="temp/*" \
196- --exclude="tmp/*" \
197- --exclude="*.tmp" \
198- --exclude=".cache/*" \
199- --exclude=".next/*" \
200- --exclude="target/*" \
201- --exclude=".gradle/*" \
202- --exclude="bin/*" \
203- --exclude="obj/*" \
204- --exclude=".env" \
205- --exclude=".env.local" \
206- --exclude=".env.production" \
207- --exclude=".env.development"
208-
209- # Add custom exclusions from config if they exist
210- if grep -q "^exclude_patterns:" release-config.yml; then
211- echo "📋 Adding custom exclusions from config..."
210+ # Only process if this directory should be rebuilt
211+ if [ "$SHOULD_REBUILD" = "true" ]; then
212+ cd "$sample_dir"
213+
214+ # Check if this sample should be included
215+ INCLUDED=$(grep "^included:" release-config.yml | sed 's/included: *//' | tr -d ' ')
216+ if [ "$INCLUDED" != "true" ]; then
217+ echo "⏭️ Skipping (included: $INCLUDED)"
218+ cd - > /dev/null
219+ continue
220+ fi
221+
222+ # Extract configuration using basic shell parsing
223+ CATEGORY=$(grep "^category:" release-config.yml | sed 's/category: *"//' | sed 's/"$//' | tr -d ' ')
224+ FRAMEWORK=$(grep "^framework:" release-config.yml | sed 's/framework: *"//' | sed 's/"$//' | tr -d ' ')
225+
226+ if [ -z "$CATEGORY" ] || [ -z "$FRAMEWORK" ]; then
227+ echo "❌ Missing category or framework in $config_file"
228+ cd - > /dev/null
229+ continue
230+ fi
212231
213- # Create a temporary zip with custom exclusions
214- TEMP_ZIP="${ARTIFACTS_DIR}/temp_${ZIP_FILENAME}.zip"
215- mv "${ARTIFACTS_DIR}/${ZIP_FILENAME}.zip" "$TEMP_ZIP"
232+ # Build zip filename from category and framework
233+ ZIP_FILENAME="${CATEGORY}-${FRAMEWORK}-sample"
216234
217- # Extract and re- zip with custom exclusions
218- mkdir -p temp_extract
219- cd temp_extract
220- unzip -q "$TEMP_ZIP "
235+ echo "📦 Building: $ZIP_FILENAME. zip"
236+ echo "🏷️ Category: $CATEGORY, Framework: $FRAMEWORK"
237+ echo "📁 Current directory: $(pwd)"
238+ echo "📁 Artifacts directory: $ARTIFACTS_DIR "
221239
222- # Apply custom exclusions
223- while IFS= read -r line; do
224- if echo "$line" | grep -q "^ - "; then
225- pattern=$(echo "$line" | sed 's/^ - "//' | sed 's/"$//' | tr -d ' ')
226- if [ ! -z "$pattern" ]; then
227- echo " Excluding custom pattern: $pattern"
228- find . -name "$pattern" -delete 2>/dev/null || true
240+ # Create zip with absolute path to artifacts directory (this will overwrite existing)
241+ zip -r "${ARTIFACTS_DIR}/${ZIP_FILENAME}.zip" . \
242+ --exclude=".git/*" \
243+ --exclude="node_modules/*" \
244+ --exclude="__pycache__/*" \
245+ --exclude="*.pyc" \
246+ --exclude="*.pyo" \
247+ --exclude="dist/*" \
248+ --exclude="build/*" \
249+ --exclude="venv/*" \
250+ --exclude=".venv/*" \
251+ --exclude=".pytest_cache/*" \
252+ --exclude=".coverage" \
253+ --exclude="coverage/*" \
254+ --exclude="*.log" \
255+ --exclude=".DS_Store" \
256+ --exclude="Thumbs.db" \
257+ --exclude=".idea/*" \
258+ --exclude=".vscode/*" \
259+ --exclude="temp/*" \
260+ --exclude="tmp/*" \
261+ --exclude="*.tmp" \
262+ --exclude=".cache/*" \
263+ --exclude=".next/*" \
264+ --exclude="target/*" \
265+ --exclude=".gradle/*" \
266+ --exclude="bin/*" \
267+ --exclude="obj/*" \
268+ --exclude=".env" \
269+ --exclude=".env.local" \
270+ --exclude=".env.production" \
271+ --exclude=".env.development"
272+
273+ # Add custom exclusions from config if they exist
274+ if grep -q "^exclude_patterns:" release-config.yml; then
275+ echo "📋 Adding custom exclusions from config..."
276+
277+ # Create a temporary zip with custom exclusions
278+ TEMP_ZIP="${ARTIFACTS_DIR}/temp_${ZIP_FILENAME}.zip"
279+ mv "${ARTIFACTS_DIR}/${ZIP_FILENAME}.zip" "$TEMP_ZIP"
280+
281+ # Extract and re-zip with custom exclusions
282+ mkdir -p temp_extract
283+ cd temp_extract
284+ unzip -q "$TEMP_ZIP"
285+
286+ # Apply custom exclusions
287+ while IFS= read -r line; do
288+ if echo "$line" | grep -q "^ - "; then
289+ pattern=$(echo "$line" | sed 's/^ - "//' | sed 's/"$//' | tr -d ' ')
290+ if [ ! -z "$pattern" ]; then
291+ echo " Excluding custom pattern: $pattern"
292+ find . -name "$pattern" -delete 2>/dev/null || true
293+ fi
229294 fi
230- fi
231- done < <(grep -A 20 "^exclude_patterns:" ../release-config.yml)
295+ done < <(grep -A 20 "^exclude_patterns:" ../release-config.yml)
296+
297+ # Re-create zip with absolute path
298+ zip -r "${ARTIFACTS_DIR}/${ZIP_FILENAME}.zip" .
299+ cd ..
300+ rm -rf temp_extract "$TEMP_ZIP"
301+ fi
232302
233- # Re-create zip with absolute path
234- zip -r "${ARTIFACTS_DIR}/${ZIP_FILENAME}.zip" .
235- cd ..
236- rm -rf temp_extract "$TEMP_ZIP"
237- fi
238-
239- cd - > /dev/null
240-
241- if [ -f "${ARTIFACTS_DIR}/${ZIP_FILENAME}.zip" ]; then
242- SIZE=$(du -h "${ARTIFACTS_DIR}/${ZIP_FILENAME}.zip" | cut -f1)
243- echo "✅ Created: ${ZIP_FILENAME}.zip ($SIZE)"
244- else
245- echo "❌ Failed to create: ${ZIP_FILENAME}.zip"
303+ cd - > /dev/null
304+
305+ if [ -f "${ARTIFACTS_DIR}/${ZIP_FILENAME}.zip" ]; then
306+ SIZE=$(du -h "${ARTIFACTS_DIR}/${ZIP_FILENAME}.zip" | cut -f1)
307+ echo "✅ Created/Updated: ${ZIP_FILENAME}.zip ($SIZE)"
308+ else
309+ echo "❌ Failed to create: ${ZIP_FILENAME}.zip"
310+ fi
246311 fi
247312 done
248313
249314 # Count artifacts AFTER the loop completes
250315 ARTIFACT_COUNT=$(ls artifacts/*.zip 2>/dev/null | wc -l)
251316 echo "ARTIFACT_COUNT=$ARTIFACT_COUNT" >> $GITHUB_ENV
252- echo "📊 Total artifacts built : $ARTIFACT_COUNT"
317+ echo "📊 Total artifacts for release : $ARTIFACT_COUNT"
253318
254- # Debug: List what was actually created
255- echo "📦 Artifacts created :"
319+ # Debug: List what will be included in the release
320+ echo "📦 Artifacts for release :"
256321 ls -la artifacts/ || echo "No artifacts directory or files found"
257322
258323 - name : Security scan artifacts
@@ -319,7 +384,7 @@ jobs:
319384 TIMESTAMP=$(date +%Y%m%d-%H%M%S)
320385 RELEASE_TAG="test-feat-zip-script-${TIMESTAMP}"
321386
322- echo "📦 Creating test release: $RELEASE_TAG"
387+ echo "📦 Creating test release: $RELEASE_TAG with $ARTIFACT_COUNT artifacts "
323388
324389 # Create test release (not latest)
325390 gh release create "$RELEASE_TAG" \
0 commit comments