@@ -280,8 +280,6 @@ runs:
280280 if : ${{ always() }}
281281 shell : bash
282282 run : |
283- # Initialize empty JSON object
284- echo '{}' > formatted_env.json
285283 # Define patterns for variables to include (allowlist approach)
286284 INCLUDE_PATTERNS=(
287285 '^FIX_COPY_.*_OUTCOME='
@@ -307,7 +305,7 @@ runs:
307305 )
308306 # Filter GITHUB_ENV to include only safe, relevant variables
309307 # Initialize a JSON object
310- echo "{" > formatted_env.json
308+ echo "{" > formatted_env.json || true ;
311309 # Filter GITHUB_ENV to include only safe, relevant variables
312310 grep -E "$(IFS='|'; echo "${INCLUDE_PATTERNS[*]}")" "$GITHUB_ENV" | \
313311 grep -viE "$(IFS='|'; echo "${EXCLUDE_PATTERNS[*]}")" | \
@@ -317,17 +315,21 @@ runs:
317315 escaped_key=$(echo "$key" | jq -R @json)
318316 escaped_value=$(echo "$value" | jq -R @json)
319317 echo " $escaped_key: $escaped_value," >> formatted_env.json
320- done
318+ done ;
321319 # Remove the trailing comma and close the JSON object
322320 sed -i '$ s/,$//' formatted_env.json
323321 echo "}" >> formatted_env.json
324322 # Verify the output contains data
325323 if [[ -s formatted_env.json ]] && jq -e 'length > 0' formatted_env.json >/dev/null 2>&1; then
326324 echo "::debug::Successfully created filtered environment JSON with $(jq 'length' formatted_env.json) variables"
327325 else
328- echo "::warning::No matching environment variables found to export"
329- echo '{}' > formatted_env.json
330- fi
326+ if [[ -s formatted_env.json ]] ; then
327+ echo "::debug::Incompletely created environment JSON with unknown variables"
328+ else
329+ echo "::warning::No matching environment variables found to export"
330+ echo '{}' > formatted_env.json
331+ fi ;
332+ fi ;
331333 - name : Upload JSON as artifact
332334 if : ${{ !cancelled() }}
333335 uses : actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
0 commit comments