Skip to content
Merged
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
79 changes: 79 additions & 0 deletions .github/actions/check-run/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Post Check Run

description: Posts a GitHub Check Run after uploading artifacts to S3

inputs:
sha:
description: SHA of the commit to check
required: true
repo:
description: GitHub repository (owner/repo)
required: true
s3_location:
description: S3 location for the artifacts
required: true
github_token:
description: GitHub token for authentication
required: true
workflow_name:
description: Workflow name to post check_run
required: false

runs:
using: "composite"
steps:
- name: Post check run
shell: bash
env:
HEAD_SHA: ${{ inputs.sha }}
ACCESS_TOKEN: ${{ inputs.github_token }}
S3_LOCATION: ${{ inputs.s3_location }}
REPO: ${{ inputs.repo }}
WORKFLOW_NAME: ${{ inputs.workflow_name }}
run: |
set -e
post_name="Artifacts${WORKFLOW_NAME} uploaded to S3"

echo "Creating check run for commit: $HEAD_SHA"
CHECK_RUN_ID=$(curl -s -L -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$REPO/check-runs \
-d '{
"name": "'"$post_name"'",
"head_sha": "'"$HEAD_SHA"'",
"status": "in_progress",
"output": {
"title": "Check S3 Location",
"summary": "",
"text": "'"$S3_LOCATION"'"
}
}' | jq -r '.id')

if [ -z "$CHECK_RUN_ID" ]; then
echo "Failed to create check run. Exiting."
exit 1
fi

echo "Check run created with ID: $CHECK_RUN_ID"

echo "Updating check run to completed status..."
curl -s -L -X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$REPO/check-runs/$CHECK_RUN_ID \
-d '{
"name": "'"$post_name"'",
"head_sha": "'"$HEAD_SHA"'",
"status": "completed",
"conclusion": "success",
"output": {
"title": "Check S3 Location",
"summary": "",
"text": "'"$S3_LOCATION"'"
}
}'

echo "Check run updated successfully."
273 changes: 273 additions & 0 deletions .github/actions/resolve-nightly-download-url/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
name: Resolve nightly build URLs
description: >
Finds the most recent master and wrynose nightly builds and resolves SDK/image
artifact URLs by checking latest run attempt first, then falling back
attempt-by-attempt until each artifact URL returns HTTP 200.

inputs:
token:
description: GitHub token with read access to qualcomm-linux/meta-qcom
required: true
artifact-token:
description: Authorization token for Qualcomm artifact downloads
required: true

outputs:
sdk-url:
description: >
JSON object mapping branch name ("master", "wrynose") to the HTTPS download
URL for the SDK toolchain .sh installer.
value: ${{ steps.resolve.outputs.sdk-url }}
image-urls:
description: >
JSON object with top-level branch keys ("master", "wrynose"), each mapping
"<target>/<image-type>" to its download URL.
value: ${{ steps.resolve.outputs.image-urls }}

runs:
using: composite
steps:
- name: Find latest SDK and image URLs from master and wrynose nightlies
id: resolve
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
ARTIFACT_TOKEN: ${{ inputs.artifact-token }}
run: |
set -euo pipefail
shopt -s inherit_errexit

SDK_FILE_PREFIX="qcom-distro-x86_64-qcom-multimedia-proprietary-image-armv8a-qcom-armv8a-toolchain-"
FILESERVER="https://qli-prod-artifacts.qualcomm.com/qcom-prd-gh-artifacts"
WORKFLOW_ID="140524224"

BRANCHES=(
"master"
"wrynose"
)

TARGETS=(
"iq-9075-evk"
"iq-8275-evk"
"iq-615-evk"
"rb3gen2-core-kit"
)

url_exists() {
local URL="$1"
local STATUS=""

STATUS=$(curl -s -L -o /dev/null -w "%{http_code}" \
-H "Authorization: ${ARTIFACT_TOKEN}" \
"$URL" || true)

[ "$STATUS" = "200" ]
}

find_sdk_filename_by_probe() {
local BASE_URL="$1"
# The toolchain version is named differently per branch, e.g.
# wrynose: ...-toolchain-3.1.sh (X.Y)
# master: ...-toolchain-2.99+snapshot.sh (X.YY + "+snapshot")
# so probe both a release ("") and a snapshot ("+snapshot") suffix.
local major minor suffix candidate STATUS
for major in 5 4 3 2 1; do
for minor in 99 9 8 7 6 5 4 3 2 1 0; do
for suffix in "" "+snapshot"; do
candidate="${SDK_FILE_PREFIX}${major}.${minor}${suffix}.sh"
STATUS=$(curl -s -L --max-time 10 -o /dev/null -w "%{http_code}" \
-H "Authorization: ${ARTIFACT_TOKEN}" "${BASE_URL}/${candidate}" || true)
if [ "$STATUS" = "200" ]; then
echo "$candidate"
return 0
fi
done
done
done
return 1
}

resolve_sdk_url() {
local RUN_ID="$1"
local LATEST_ATTEMPT="$2"
local ATTEMPT="$LATEST_ATTEMPT"

while [ "$ATTEMPT" -ge 1 ]; do
local BASE_URL="${FILESERVER}/qualcomm-linux/meta-qcom/${RUN_ID}-${ATTEMPT}/qcom-distro-sdk/qcom-armv8a"
local SDK_FILE
SDK_FILE=$(find_sdk_filename_by_probe "$BASE_URL")

if [ -n "$SDK_FILE" ]; then
echo "Found SDK toolchain at attempt ${RUN_ID}-${ATTEMPT}: ${SDK_FILE}" >&2
echo "${BASE_URL}/${SDK_FILE}"
return 0
else
echo "No SDK toolchain found at attempt ${RUN_ID}-${ATTEMPT}" >&2
fi

ATTEMPT=$((ATTEMPT - 1))
done

echo "::error::Unable to find SDK toolchain for run ${RUN_ID}" >&2
return 1
}

resolve_artifact_url() {
local RUN_ID="$1"
local LATEST_ATTEMPT="$2"
local REL_PATH="$3"
local LABEL="$4"

local ATTEMPT="$LATEST_ATTEMPT"

while [ "$ATTEMPT" -ge 1 ]; do
local URL="${FILESERVER}/qualcomm-linux/meta-qcom/${RUN_ID}-${ATTEMPT}/${REL_PATH}"

echo "Checking ${LABEL} at attempt ${RUN_ID}-${ATTEMPT}" >&2
echo "Candidate URL: ${URL}" >&2

if url_exists "$URL"; then
echo "Found ${LABEL} at attempt ${RUN_ID}-${ATTEMPT}" >&2
echo "$URL"
return 0
fi

ATTEMPT=$((ATTEMPT - 1))
done

echo "::error::Unable to find ${LABEL} from attempt ${LATEST_ATTEMPT} down to 1 for run ${RUN_ID}" >&2
return 1
}

# Finds the most recent run for a branch whose compile_sdk job succeeded.
# Echoes "<run_id>\t<run_attempt>" on stdout; all logging goes to stderr.
find_latest_successful_run() {
local BRANCH="$1"
local RUN_ID=""
local LATEST_ATTEMPT=""
local PAGE=1

while [ -z "$RUN_ID" ]; do
echo "[${BRANCH}] Checking workflow runs page: ${PAGE}" >&2

local RUNS
RUNS=$(gh api \
"repos/qualcomm-linux/meta-qcom/actions/workflows/${WORKFLOW_ID}/runs?per_page=20&page=${PAGE}" \
--jq ".workflow_runs[]
| select(.head_branch==\"${BRANCH}\")
| [.id, .run_attempt, .conclusion]
| @tsv")

if [ -z "$RUNS" ]; then
echo "::error::No more ${BRANCH} nightly runs found." >&2
return 1
fi

while IFS=$'\t' read -r _RUN_ID _RUN_ATTEMPT _CONCLUSION; do
if [ -z "$_RUN_ID" ]; then
continue
fi

if [ "$_CONCLUSION" = "null" ] || [ "$_CONCLUSION" = "cancelled" ]; then
echo "[${BRANCH}] Skipping run ${_RUN_ID}, conclusion=${_CONCLUSION}" >&2
continue
fi

local SDK_JOB_CONCLUSION
SDK_JOB_CONCLUSION=$(gh api \
"repos/qualcomm-linux/meta-qcom/actions/runs/${_RUN_ID}/jobs?per_page=100" \
--jq '.jobs[] | select(.name | contains("compile_sdk")) | .conclusion' 2>/dev/null || true)

if [ "$SDK_JOB_CONCLUSION" != "success" ]; then
echo "[${BRANCH}] Skipping run ${_RUN_ID}, compile_sdk conclusion=${SDK_JOB_CONCLUSION}" >&2
continue
fi

RUN_ID="$_RUN_ID"
LATEST_ATTEMPT="$_RUN_ATTEMPT"
echo "[${BRANCH}] Using nightly run ${RUN_ID}-${LATEST_ATTEMPT}" >&2
break
done <<< "$RUNS"

if [ -n "$RUN_ID" ]; then
break
fi

PAGE=$((PAGE + 1))

if [ "$PAGE" -gt 10 ]; then
echo "::error::Exhausted 10 pages of ${BRANCH} nightly runs without finding a successful compile_sdk." >&2
return 1
fi
done

printf '%s\t%s\n' "$RUN_ID" "$LATEST_ATTEMPT"
}

# Resolves SDK + image URLs for one branch and echoes a JSON object:
# {"sdk-url":"<url>","image-urls":{"<target>/<type>":"<url>",...}}
resolve_branch() {
local BRANCH="$1"
local RUN_INFO RUN_ID LATEST_ATTEMPT

RUN_INFO=$(find_latest_successful_run "$BRANCH")
IFS=$'\t' read -r RUN_ID LATEST_ATTEMPT <<< "$RUN_INFO"

local SDK_URL
SDK_URL=$(resolve_sdk_url "$RUN_ID" "$LATEST_ATTEMPT")
echo "[${BRANCH}] SDK URL: ${SDK_URL}" >&2

local IMAGE_JSON="{"
local SEP=""

for TARGET in "${TARGETS[@]}"; do
for TYPE in multimedia proprietary; do
local FILENAME
if [ "$TYPE" = "proprietary" ]; then
FILENAME="qcom-multimedia-proprietary-image-${TARGET}.rootfs.qcomflash.tar.gz"
else
FILENAME="qcom-multimedia-image-${TARGET}.rootfs.qcomflash.tar.gz"
fi

local REL_PATH="qcom-distro/${TARGET}/${FILENAME}"
local LABEL="${TARGET}/${TYPE}"

local IMAGE_URL
IMAGE_URL=$(resolve_artifact_url "$RUN_ID" "$LATEST_ATTEMPT" "$REL_PATH" "$LABEL")
echo "[${BRANCH}] Image URL [${LABEL}]: ${IMAGE_URL}" >&2

IMAGE_JSON="${IMAGE_JSON}${SEP}\"${LABEL}\":\"${IMAGE_URL}\""
SEP=","
done
done

IMAGE_JSON="${IMAGE_JSON}}"

printf '{"sdk-url":"%s","image-urls":%s}' "$SDK_URL" "$IMAGE_JSON"
}

SDK_JSON="{"
IMAGE_URLS_JSON="{"
BRANCH_SEP=""

for BRANCH in "${BRANCHES[@]}"; do
echo "::group::Resolving ${BRANCH} nightly"
BRANCH_RESULT=$(resolve_branch "$BRANCH")
echo "::endgroup::"

BRANCH_SDK_URL=$(echo "$BRANCH_RESULT" | jq -r '."sdk-url"')
BRANCH_IMAGE_URLS=$(echo "$BRANCH_RESULT" | jq -c '."image-urls"')

SDK_JSON="${SDK_JSON}${BRANCH_SEP}\"${BRANCH}\":\"${BRANCH_SDK_URL}\""
IMAGE_URLS_JSON="${IMAGE_URLS_JSON}${BRANCH_SEP}\"${BRANCH}\":${BRANCH_IMAGE_URLS}"
BRANCH_SEP=","
done

SDK_JSON="${SDK_JSON}}"
IMAGE_URLS_JSON="${IMAGE_URLS_JSON}}"

echo "sdk-url=${SDK_JSON}" >> "$GITHUB_OUTPUT"
echo "image-urls=${IMAGE_URLS_JSON}" >> "$GITHUB_OUTPUT"

echo "Resolved SDK URLs: ${SDK_JSON}"
echo "Resolved image URLs: ${IMAGE_URLS_JSON}"
Loading
Loading