Skip to content

Commit 52f64eb

Browse files
committed
ci: pre pull debug
Signed-off-by: Teng Fan <tengf@qti.qualcomm.com>
1 parent 3a60c30 commit 52f64eb

File tree

1 file changed

+268
-0
lines changed

1 file changed

+268
-0
lines changed

.github/workflows/pre-pull.yml

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
name: Pre-Pull Check
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
workflow_run_id:
7+
description: "Specific workflow run ID to check (optional, defaults to latest)"
8+
required: false
9+
type: string
10+
default: "21572367142"
11+
job_id:
12+
description: "Specific job ID to download artifacts from (optional, downloads from all jobs if not specified)"
13+
required: false
14+
type: string
15+
default: "62186173260"
16+
schedule:
17+
# Run daily after the nightly build typically completes
18+
- cron: "00 18 * * *"
19+
20+
permissions:
21+
actions: read
22+
contents: read
23+
24+
jobs:
25+
check-and-download:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
- name: Get latest nightly build workflow run
32+
id: get-workflow-run
33+
env:
34+
GH_TOKEN: ${{ github.token }}
35+
run: |
36+
REPO="qualcomm-linux/meta-qcom"
37+
WORKFLOW_FILE="nightly-build.yml"
38+
39+
# Use provided run ID or get the latest
40+
if [ -n "${{ inputs.workflow_run_id }}" ]; then
41+
RUN_ID="${{ inputs.workflow_run_id }}"
42+
echo "Using provided workflow run ID: $RUN_ID"
43+
else
44+
echo "Fetching latest workflow run for $WORKFLOW_FILE..."
45+
RUN_ID=$(gh api \
46+
-H "Accept: application/vnd.github+json" \
47+
-H "X-GitHub-Api-Version: 2022-11-28" \
48+
"/repos/$REPO/actions/workflows/$WORKFLOW_FILE/runs?status=completed&per_page=1" \
49+
--jq '.workflow_runs[0].id')
50+
51+
if [ -z "$RUN_ID" ] || [ "$RUN_ID" = "null" ]; then
52+
echo "Error: No completed workflow runs found"
53+
exit 1
54+
fi
55+
echo "Found latest workflow run ID: $RUN_ID"
56+
fi
57+
58+
echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT
59+
60+
# Get workflow run details
61+
WORKFLOW_URL="https://github.com/$REPO/actions/runs/$RUN_ID"
62+
echo "workflow_url=$WORKFLOW_URL" >> $GITHUB_OUTPUT
63+
echo "Workflow URL: $WORKFLOW_URL"
64+
65+
- name: Install GitHub CLI
66+
run: |
67+
if ! command -v gh &> /dev/null; then
68+
echo "Installing GitHub CLI..."
69+
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
70+
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
71+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
72+
sudo apt update
73+
sudo apt install gh -y
74+
fi
75+
76+
- name: Check all jobs status
77+
id: check-jobs
78+
env:
79+
GH_TOKEN: ${{ github.token }}
80+
run: |
81+
REPO="qualcomm-linux/meta-qcom"
82+
RUN_ID="${{ steps.get-workflow-run.outputs.run_id }}"
83+
84+
echo "Checking job statuses for run ID: $RUN_ID"
85+
86+
# Get all jobs for this workflow run
87+
JOBS_JSON=$(gh api \
88+
-H "Accept: application/vnd.github+json" \
89+
-H "X-GitHub-Api-Version: 2022-11-28" \
90+
"/repos/$REPO/actions/runs/$RUN_ID/jobs?per_page=100")
91+
92+
# Save jobs to file for debugging
93+
echo "$JOBS_JSON" > jobs.json
94+
95+
# Extract job names and conclusions
96+
echo "Job Status Summary:"
97+
echo "==================="
98+
echo "$JOBS_JSON" | jq -r '.jobs[] | "\(.name): \(.conclusion)"'
99+
100+
# Check if all jobs succeeded
101+
FAILED_JOBS=$(echo "$JOBS_JSON" | jq -r '.jobs[] | select(.conclusion != "success" and .conclusion != "skipped") | .name')
102+
103+
if [ -n "$FAILED_JOBS" ]; then
104+
echo ""
105+
echo "❌ The following jobs did not succeed:"
106+
echo "$FAILED_JOBS"
107+
echo "all_success=false" >> $GITHUB_OUTPUT
108+
exit 1
109+
else
110+
echo ""
111+
echo "✅ All jobs completed successfully!"
112+
echo "all_success=true" >> $GITHUB_OUTPUT
113+
fi
114+
115+
- name: Find and download kas-build artifacts
116+
if: steps.check-jobs.outputs.all_success == 'true'
117+
env:
118+
GH_TOKEN: ${{ github.token }}
119+
run: |
120+
REPO="qualcomm-linux/meta-qcom"
121+
RUN_ID="${{ steps.get-workflow-run.outputs.run_id }}"
122+
JOB_ID="${{ inputs.job_id }}"
123+
124+
echo "Searching for kas-build artifacts..."
125+
126+
# Get artifacts for this workflow run
127+
ARTIFACTS_JSON=$(gh api \
128+
-H "Accept: application/vnd.github+json" \
129+
-H "X-GitHub-Api-Version: 2022-11-28" \
130+
"/repos/$REPO/actions/runs/$RUN_ID/artifacts?per_page=100")
131+
132+
# Save artifacts list
133+
echo "$ARTIFACTS_JSON" > artifacts.json
134+
135+
# If job_id is specified, filter artifacts by job
136+
if [ -n "$JOB_ID" ]; then
137+
echo "Filtering artifacts for job ID: $JOB_ID"
138+
139+
# Get job details to find artifacts associated with this job
140+
JOB_JSON=$(gh api \
141+
-H "Accept: application/vnd.github+json" \
142+
-H "X-GitHub-Api-Version: 2022-11-28" \
143+
"/repos/$REPO/actions/jobs/$JOB_ID")
144+
145+
echo "$JOB_JSON" > job.json
146+
JOB_NAME=$(echo "$JOB_JSON" | jq -r '.name')
147+
echo "Job name: $JOB_NAME"
148+
149+
# Note: GitHub API doesn't directly link artifacts to jobs
150+
# We'll download all kas-build artifacts from the run
151+
# In practice, artifacts are associated with the entire workflow run, not individual jobs
152+
echo "Note: Downloading all kas-build artifacts from workflow run $RUN_ID"
153+
echo "GitHub Actions artifacts are associated with workflow runs, not individual jobs"
154+
fi
155+
156+
# Find all kas-build artifacts
157+
KAS_BUILD_ARTIFACTS=$(echo "$ARTIFACTS_JSON" | jq -r '.artifacts[] | select(.name | startswith("kas-build-qcom-distro") and endswith("iq-9075-evk")) | .name')
158+
159+
if [ -z "$KAS_BUILD_ARTIFACTS" ]; then
160+
echo "❌ Error: No kas-build artifacts found"
161+
echo "Available artifacts:"
162+
echo "$ARTIFACTS_JSON" | jq -r '.artifacts[] | .name'
163+
exit 1
164+
fi
165+
166+
echo "Found kas-build artifacts:"
167+
echo "$KAS_BUILD_ARTIFACTS"
168+
echo ""
169+
170+
# Create download directory
171+
mkdir -p kas-build-artifacts
172+
173+
# Download each kas-build artifact
174+
ARTIFACT_COUNT=0
175+
echo "$ARTIFACTS_JSON" | jq -c '.artifacts[] | select(.name | startswith("kas-build-") and endswith("iq-9075-evk"))' | while read -r artifact; do
176+
ARTIFACT_NAME=$(echo "$artifact" | jq -r '.name')
177+
ARTIFACT_ID=$(echo "$artifact" | jq -r '.id')
178+
ARTIFACT_SIZE=$(echo "$artifact" | jq -r '.size_in_bytes')
179+
180+
echo "Downloading: $ARTIFACT_NAME (ID: $ARTIFACT_ID, Size: $ARTIFACT_SIZE bytes)"
181+
182+
# Download the artifact
183+
gh api \
184+
-H "Accept: application/vnd.github+json" \
185+
-H "X-GitHub-Api-Version: 2022-11-28" \
186+
"/repos/$REPO/actions/artifacts/$ARTIFACT_ID/zip" > "kas-build-artifacts/${ARTIFACT_NAME}.zip"
187+
188+
# Verify download
189+
if [ -f "kas-build-artifacts/${ARTIFACT_NAME}.zip" ]; then
190+
FILE_SIZE=$(stat -c%s "kas-build-artifacts/${ARTIFACT_NAME}.zip" 2>/dev/null || stat -f%z "kas-build-artifacts/${ARTIFACT_NAME}.zip" 2>/dev/null || echo "0")
191+
echo "✅ Downloaded ${ARTIFACT_NAME}.zip (Size: $FILE_SIZE bytes)"
192+
193+
# Extract the zip file
194+
echo "Extracting ${ARTIFACT_NAME}.zip..."
195+
mkdir -p "kas-build-artifacts/${ARTIFACT_NAME}"
196+
unzip -q "kas-build-artifacts/${ARTIFACT_NAME}.zip" -d "kas-build-artifacts/${ARTIFACT_NAME}"
197+
198+
# Display content
199+
echo "Content of ${ARTIFACT_NAME}:"
200+
ls -lah "kas-build-artifacts/${ARTIFACT_NAME}/"
201+
202+
# Show kas-build.yml content if exists
203+
if [ -f "kas-build-artifacts/${ARTIFACT_NAME}/kas-build.yml" ]; then
204+
echo "=== kas-build.yml content ==="
205+
cat "kas-build-artifacts/${ARTIFACT_NAME}/kas-build.yml"
206+
fi
207+
echo ""
208+
209+
ARTIFACT_COUNT=$((ARTIFACT_COUNT + 1))
210+
else
211+
echo "❌ Failed to download ${ARTIFACT_NAME}"
212+
fi
213+
done
214+
215+
# Count total artifacts downloaded
216+
TOTAL_ARTIFACTS=$(find kas-build-artifacts -name "kas-build.yml" | wc -l)
217+
echo ""
218+
echo "=========================================="
219+
echo "✅ Successfully downloaded $TOTAL_ARTIFACTS kas-build artifacts"
220+
echo "=========================================="
221+
222+
# List all downloaded artifacts
223+
echo ""
224+
echo "Downloaded artifacts summary:"
225+
find kas-build-artifacts -name "kas-build.yml" -exec dirname {} \; | while read -r dir; do
226+
ARTIFACT_NAME=$(basename "$dir")
227+
echo " - $ARTIFACT_NAME"
228+
done
229+
230+
- name: Upload all kas-build artifacts
231+
if: steps.check-jobs.outputs.all_success == 'true'
232+
uses: actions/upload-artifact@v4
233+
with:
234+
name: kas-build-artifacts-from-nightly
235+
path: kas-build-artifacts/
236+
retention-days: 30
237+
238+
- name: Create summary
239+
if: always()
240+
run: |
241+
echo "## Pre-Pull Check Summary" >> $GITHUB_STEP_SUMMARY
242+
echo "" >> $GITHUB_STEP_SUMMARY
243+
echo "**Workflow Run:** ${{ steps.get-workflow-run.outputs.workflow_url }}" >> $GITHUB_STEP_SUMMARY
244+
echo "**Run ID:** ${{ steps.get-workflow-run.outputs.run_id }}" >> $GITHUB_STEP_SUMMARY
245+
echo "" >> $GITHUB_STEP_SUMMARY
246+
247+
if [ "${{ steps.check-jobs.outputs.all_success }}" = "true" ]; then
248+
echo "**Status:** ✅ All jobs succeeded" >> $GITHUB_STEP_SUMMARY
249+
echo "" >> $GITHUB_STEP_SUMMARY
250+
251+
# Count and list downloaded artifacts
252+
if [ -d "kas-build-artifacts" ]; then
253+
ARTIFACT_COUNT=$(find kas-build-artifacts -name "kas-build.yml" 2>/dev/null | wc -l)
254+
echo "**Downloaded Artifacts:** $ARTIFACT_COUNT kas-build configurations" >> $GITHUB_STEP_SUMMARY
255+
echo "" >> $GITHUB_STEP_SUMMARY
256+
echo "### Artifact List:" >> $GITHUB_STEP_SUMMARY
257+
258+
find kas-build-artifacts -name "kas-build.yml" -exec dirname {} \; 2>/dev/null | while read -r dir; do
259+
ARTIFACT_NAME=$(basename "$dir")
260+
echo "- \`$ARTIFACT_NAME\`" >> $GITHUB_STEP_SUMMARY
261+
done
262+
else
263+
echo "**Artifacts:** No artifacts downloaded" >> $GITHUB_STEP_SUMMARY
264+
fi
265+
else
266+
echo "**Status:** ❌ Some jobs failed or are incomplete" >> $GITHUB_STEP_SUMMARY
267+
echo "**Action:** Please check the workflow run for details" >> $GITHUB_STEP_SUMMARY
268+
fi

0 commit comments

Comments
 (0)