All checks were successful
CICD Start / Sanity and Base Decision (pull_request) Successful in 1m2s
Signed-off-by: copilotcoder <copilotcoder@darkhelm.org>
116 lines
3.9 KiB
YAML
116 lines
3.9 KiB
YAML
name: CICD
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
GITEA_REGISTRY_HOST: kankali.darkhelm.lan
|
|
GITEA_REGISTRY_IP: 10.18.75.2
|
|
|
|
concurrency:
|
|
group: cicd-launch-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
launch:
|
|
name: Launch CICD Start
|
|
# Lightweight dispatch-only job; avoid dependency on ubuntu-act image startup.
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 8
|
|
steps:
|
|
- name: Configure registry host resolution
|
|
run: |
|
|
if ! grep -q "${GITEA_REGISTRY_HOST}" /etc/hosts; then
|
|
echo "${GITEA_REGISTRY_IP} ${GITEA_REGISTRY_HOST}" >> /etc/hosts
|
|
fi
|
|
|
|
- name: Dispatch CICD Start workflow
|
|
env:
|
|
ACTIONS_TRIGGER_TOKEN: ${{ secrets.ACTIONS_TRIGGER_TOKEN }}
|
|
PACKAGE_ACCESS_TOKEN: ${{ secrets.PACKAGE_ACCESS_TOKEN }}
|
|
REPO_FULL: ${{ github.repository }}
|
|
HEAD_REF: ${{ github.head_ref }}
|
|
REF_NAME: ${{ github.ref_name }}
|
|
HEAD_SHA: ${{ github.sha }}
|
|
run: |
|
|
set -e
|
|
|
|
DISPATCH_TOKEN="${ACTIONS_TRIGGER_TOKEN:-${PACKAGE_ACCESS_TOKEN:-}}"
|
|
|
|
if [ -z "${DISPATCH_TOKEN}" ]; then
|
|
echo "❌ Missing dispatch token. Set ACTIONS_TRIGGER_TOKEN (repo write scope) or ensure PACKAGE_ACCESS_TOKEN has Actions workflow-dispatch permissions."
|
|
exit 1
|
|
fi
|
|
|
|
if ! grep -q "${GITEA_REGISTRY_HOST}" /etc/hosts; then
|
|
echo "${GITEA_REGISTRY_IP} ${GITEA_REGISTRY_HOST}" >> /etc/hosts
|
|
fi
|
|
|
|
REPO_OWNER="${REPO_FULL%/*}"
|
|
REPO_NAME="${REPO_FULL#*/}"
|
|
TARGET_REF="${HEAD_REF:-${REF_NAME}}"
|
|
TRACE_ID="cicd-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}-${HEAD_SHA:0:8}"
|
|
|
|
echo "trace_id=${TRACE_ID}"
|
|
echo "target_ref=${TARGET_REF}"
|
|
CANDIDATE_API_BASES=()
|
|
if [ -n "${GITHUB_SERVER_URL:-}" ]; then
|
|
CANDIDATE_API_BASES+=("${GITHUB_SERVER_URL%/}/api/v1")
|
|
fi
|
|
CANDIDATE_API_BASES+=("http://${GITEA_REGISTRY_IP}:3001/api/v1")
|
|
CANDIDATE_API_BASES+=("http://${GITEA_REGISTRY_HOST}:3001/api/v1")
|
|
|
|
ensure_curl() {
|
|
if command -v curl >/dev/null 2>&1; then
|
|
return 0
|
|
fi
|
|
if command -v apt-get >/dev/null 2>&1; then
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
apt-get update -qq
|
|
apt-get install -y -qq curl ca-certificates
|
|
fi
|
|
command -v curl >/dev/null 2>&1
|
|
}
|
|
|
|
ensure_curl || { echo "❌ curl unavailable for dispatch"; exit 1; }
|
|
|
|
HELPER_PATH="/tmp/dispatch-workflow.sh"
|
|
|
|
fetch_dispatch_helper() {
|
|
local helper_ref="$1"
|
|
local api_base
|
|
for api_base in "${CANDIDATE_API_BASES[@]}"; do
|
|
helper_url="${api_base}/repos/${REPO_OWNER}/${REPO_NAME}/raw/scripts/dispatch-workflow.sh?ref=${helper_ref}"
|
|
if curl -fsS --connect-timeout 5 --max-time 20 \
|
|
-H "Authorization: token ${DISPATCH_TOKEN}" \
|
|
-H "User-Agent: plex-playlist-cicd" \
|
|
-o "${HELPER_PATH}" \
|
|
"${helper_url}"; then
|
|
chmod +x "${HELPER_PATH}"
|
|
return 0
|
|
fi
|
|
done
|
|
return 1
|
|
}
|
|
|
|
if ! fetch_dispatch_helper "${TARGET_REF}" && ! fetch_dispatch_helper "${HEAD_SHA}"; then
|
|
echo "❌ Failed to fetch scripts/dispatch-workflow.sh from repository"
|
|
exit 1
|
|
fi
|
|
|
|
DISPATCH_ARGS=(
|
|
--token "${DISPATCH_TOKEN}"
|
|
--repo "${REPO_FULL}"
|
|
--workflow "cicd-start.yaml"
|
|
--ref "${TARGET_REF}"
|
|
--head-sha "${HEAD_SHA}"
|
|
--source-workflow "CICD"
|
|
--trace-id "${TRACE_ID}"
|
|
)
|
|
|
|
for API_BASE in "${CANDIDATE_API_BASES[@]}"; do
|
|
DISPATCH_ARGS+=(--api-base "${API_BASE}")
|
|
done
|
|
|
|
"${HELPER_PATH}" "${DISPATCH_ARGS[@]}"
|