Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .github/actions/get-job-data/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: 'Get Job Data from GitHub Actions'
description: 'Fetches the GitHub Actions job data from the GitHub API'
inputs:
job-name:
description: 'The name of the job to find'
required: true
github-token:
description: 'GitHub token for API authentication'
required: true
repository:
description: 'Repository in owner/repo format'
required: true
run-id:
description: 'GitHub Actions run ID'
required: true
outputs:
job_html_url:
description: 'The HTML URL of the job'
value: ${{ steps.get_url.outputs.job_html_url }}
runs:
using: 'composite'
steps:
- name: Fetch job URL from GitHub API
id: get_url
shell: bash
run: |
# Fetch the numeric job ID from GitHub API
CURL_ERROR_FILE=$(mktemp)
NETRC_FILE=$(mktemp)

# Write GitHub API credentials to a temporary netrc file to avoid
# passing the token directly on the curl command line.
printf '%s\n' \
'machine api.github.com' \
' login x-access-token' \
" password ${{ inputs.github-token }}" \
> "$NETRC_FILE"
chmod 600 "$NETRC_FILE"

# Ensure temporary file cleanup on exit
cleanup() {
if [ -n "$CURL_ERROR_FILE" ] && [ -f "$CURL_ERROR_FILE" ]; then
rm -f "$CURL_ERROR_FILE"
fi
if [ -n "$NETRC_FILE" ] && [ -f "$NETRC_FILE" ]; then
rm -f "$NETRC_FILE"
fi
}
trap cleanup EXIT

API_RESPONSE=$(curl -sS -w "\n%{http_code}" \
--netrc-file "$NETRC_FILE" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${{ inputs.repository }}/actions/runs/${{ inputs.run-id }}/jobs" 2>"$CURL_ERROR_FILE")

CURL_EXIT_CODE=$?
if [ $CURL_EXIT_CODE -ne 0 ]; then
echo "❌ ERROR: curl request to GitHub API failed with exit code $CURL_EXIT_CODE"
if [ -s "$CURL_ERROR_FILE" ]; then
echo "curl error output:"
cat "$CURL_ERROR_FILE"
fi
echo "job_html_url=" >> "$GITHUB_OUTPUT"
exit 0
fi

HTTP_CODE=$(echo "$API_RESPONSE" | tail -n1)
RESPONSE_BODY=$(echo "$API_RESPONSE" | sed '$d')

if [ "$HTTP_CODE" != "200" ]; then
echo "⚠️ WARNING: GitHub API request failed with $HTTP_CODE"
echo "job_html_url=" >> "$GITHUB_OUTPUT"
exit 0
fi

EXPECTED_JOB_NAME="${{ inputs.job-name }}"
JOB_URL=$(echo "$RESPONSE_BODY" | jq -r \
--arg job_name "$EXPECTED_JOB_NAME" \
'.jobs[] | select(.name == $job_name) | .html_url')

if [ -z "$JOB_URL" ] || [ "$JOB_URL" = "null" ]; then
echo "⚠️ WARNING: Failed to extract job URL from response for job name '$EXPECTED_JOB_NAME'."
echo "Possible causes:"
echo " - The job name does not match exactly (including spaces and case)."
echo " - The job has not started yet at the time this action ran."
echo " - The GitHub API response format was unexpected."
echo "Please verify that the job has started before this action runs and double-check the exact job name in the GitHub Actions UI."
echo "job_html_url=" >> "$GITHUB_OUTPUT"
exit 0
fi

echo "job_html_url=$JOB_URL" >> "$GITHUB_OUTPUT"
echo "Job URL: $JOB_URL"
41 changes: 40 additions & 1 deletion .github/scripts/detect-app-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ set -o pipefail # Exit if any command in pipeline fails
: "${FORCE_REBUILD:?FORCE_REBUILD not set}"
: "${ARTIFACTORY_REPOSITORY_SNAPSHOT:?ARTIFACTORY_REPOSITORY_SNAPSHOT not set}"

# Optional JFrog variables
# Optional variables
APPS_TO_REBUILD="${APPS_TO_REBUILD:-}"
JF_URL="${JF_URL:-}"
JF_USER="${JF_USER:-}"
JF_ACCESS_TOKEN="${JF_ACCESS_TOKEN:-}"
Expand All @@ -34,7 +35,11 @@ JF_ACCESS_TOKEN="${JF_ACCESS_TOKEN:-}"
# - has_apps_to_restore: boolean flag

echo "Collecting app SHAs and checking cache status..."
echo "Cache version: $CACHE_VERSION"
echo "Force rebuild mode: $FORCE_REBUILD"
if [ -n "$APPS_TO_REBUILD" ]; then
echo "Apps to rebuild: $APPS_TO_REBUILD"
fi
echo ""

# Setup JFrog CLI if credentials are available
Expand Down Expand Up @@ -92,17 +97,34 @@ echo ""

echo "### 📦 Cache Status Report for ($GITHUB_REF)" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "**Cache Version:** \`$CACHE_VERSION\`" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
if [ "$FORCE_REBUILD" == "true" ]; then
echo "**🔄 FORCE REBUILD MODE ENABLED** - All caches bypassed" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
fi
if [ -n "$APPS_TO_REBUILD" ]; then
echo "**🔨 Specific apps to rebuild:** \`$APPS_TO_REBUILD\`" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
fi
if [ "$JFROG_AVAILABLE" == "true" ]; then
echo "**🎯 JFrog Artifact Cache**: Enabled for all branches" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
fi
echo "| App | SHA | Cache Key | Status |" >> "$GITHUB_STEP_SUMMARY"
echo "|-----|-----|-----------|--------|" >> "$GITHUB_STEP_SUMMARY"

# Convert comma-separated apps list to array for easier checking
if [ -n "$APPS_TO_REBUILD" ]; then
IFS=',' read -ra REBUILD_APPS_ARRAY <<< "$APPS_TO_REBUILD"
# Trim whitespace from each app name using xargs for readability
for i in "${!REBUILD_APPS_ARRAY[@]}"; do
REBUILD_APPS_ARRAY[$i]=$(echo "${REBUILD_APPS_ARRAY[$i]}" | xargs)
done
else
REBUILD_APPS_ARRAY=()
fi

# Iterate through each app in the matrix
while IFS= read -r app_json; do
APP_NAME=$(echo "$app_json" | jq -r '.name')
Expand Down Expand Up @@ -148,6 +170,23 @@ while IFS= read -r app_json; do
continue
fi

# Check if this specific app should be rebuilt (ignore cache)
REBUILD_THIS_APP=false
for rebuild_app in "${REBUILD_APPS_ARRAY[@]}"; do
if [ "$APP_NAME" == "$rebuild_app" ]; then
REBUILD_THIS_APP=true
break
fi
done

if [ "$REBUILD_THIS_APP" == "true" ]; then
echo "🔨 rebuild requested"
echo "| $APP_NAME | \`$SHORT_SHA\` | \`$CACHE_KEY\` | 🔨 Rebuild requested |" >> "$GITHUB_STEP_SUMMARY"
APPS_TO_BUILD=$(echo "$APPS_TO_BUILD" | jq -c --arg app "$APP_NAME" --arg sha "$CURRENT_SHA" '. + [{name: $app, sha: $sha}]')
APPS_TO_BUILD_COUNT=$((APPS_TO_BUILD_COUNT + 1))
continue
fi

# Check JFrog first before GitHub cache (available for all branches)
if [ "$JFROG_AVAILABLE" == "true" ]; then
JFROG_PATH="${ARTIFACTORY_REPOSITORY_SNAPSHOT}/apps/${CACHE_VERSION}/${APP_NAME}/${APP_NAME}-${CURRENT_SHA}.tar.gz"
Expand Down
Loading
Loading