ci: manual checkout + ensure single workflow
Some checks failed
CI (node + vitest + lint) / build_test (push) Has been cancelled

This commit is contained in:
greenflame089
2025-08-17 00:45:50 -04:00
parent 0f8eb18183
commit 402ec26cf8
4 changed files with 61 additions and 121 deletions

View File

@@ -1,33 +0,0 @@
name: Q-Blog CI (mirror)
on:
workflow_dispatch:
push:
branches:
- "ci/*"
pull_request:
branches:
- "**"
jobs:
build-test:
runs-on: self-hosted
steps:
- name: Checkout (gitea mirror)
uses: gitea/checkout@v4
- name: Setup Node.js (gitea mirror)
uses: gitea/setup-node@v4
with:
node-version: "20"
- name: Install
run: npm ci
- name: Lint (Phase 0 scope)
run: npm run -s lint:phase0 || true
- name: Tests
env:
CI: "true"
run: npm test --silent -- --run

View File

@@ -1,81 +1,65 @@
name: CI (self-hosted)
name: CI (node + vitest + lint)
on:
push:
branches:
- "**"
branches: ["main", "master", "update", "*"]
pull_request:
branches:
- "**"
workflow_dispatch: {}
jobs:
build_test:
runs-on: [self-hosted, linux, x64]
timeout-minutes: 20
runs-on: ubuntu-latest:host
steps:
- name: Print env
- name: Main · Print env
run: |
echo "Actor: $GITHUB_ACTOR"
echo "Ref: $GITHUB_REF"
echo "SHA: $GITHUB_SHA"
echo "Runner labels: $RUNNER_LABELS"
echo "Workspace: ${GITHUB_WORKSPACE:-$PWD}"
node -v || true
npm -v || true
# Gitea self-hosted runners usually check out the repo contents automatically.
# Add a guard: fail early if package.json is missing (indicates checkout issue).
- name: Ensure repo contents present
# Native Gitea runner doesn't auto-checkout; and marketplace may be disabled.
# Perform a manual checkout of THIS repo at the triggering ref.
- name: Main · Manual checkout (no marketplace)
run: |
test -f package.json || { echo "::error::package.json not found - check Actions checkout"; exit 1; }
- name: Install deps (lockfile-aware)
run: |
set -e
if [ -f package-lock.json ]; then
# Read lockfileVersion without jq
node -e "try{console.log(require('./package-lock.json').lockfileVersion||0)}catch(e){console.log(0)}" > .lockver
v=$(cat .lockver)
echo "lockfileVersion=$v"
if [ "$v" = "3" ] || [ "$v" = "2" ]; then
echo "Using npm ci"
npm ci
set -euxo pipefail
ls -la || true
if [ ! -f package.json ]; then
BASE="${GITHUB_SERVER_URL:-https://gitea.qortal.link}"
REPO="${GITHUB_REPOSITORY}"
REF="${GITHUB_SHA:-}"
echo "Cloning $BASE/$REPO @ ${REF:-$GITHUB_REF}"
git init .
git remote add origin "$BASE/$REPO.git"
if [ -n "$REF" ]; then
git fetch --depth=1 origin "$REF"
git checkout -qf FETCH_HEAD
else
echo "Unknown/old lockfileVersion ($v) → npm install"
npm install
# fall back to branch name from ref
BRANCH="$(echo "${GITHUB_REF:-refs/heads/update}" | sed 's#^refs/heads/##; s#^refs/tags/##')"
git fetch --depth=1 origin "$BRANCH"
git checkout -qf "FETCH_HEAD"
fi
fi
test -f package.json && echo "package.json present" || (echo "::error::package.json still missing"; exit 1)
git status --porcelain -b || true
- name: Main · Install deps (prefer CI clean)
run: |
if [ -f package-lock.json ]; then
npm ci || npm ci --prefer-offline || npm install
else
echo "No package-lock.json → npm install"
npm install
fi
- name: Build (optional, skip if no build script)
- name: Main · Local gate (tests + phase0 lint scope)
run: |
if npm run | grep -qE '^ build'; then
npm run build
else
echo "No build script; skipping."
fi
npm run check
- name: Lint (phase0 scope if available, else best-effort lint)
- name: Artifacts · reports (optional)
if: always()
run: |
if npm run | grep -qE '^ lint:phase0'; then
npm run lint:phase0
elif npm run | grep -qE '^ lint'; then
npm run lint || true
else
echo "No lint script; skipping."
fi
mkdir -p artifacts
if ls reports/* >/dev/null 2>&1; then tar -czf artifacts/reports.tar.gz reports; fi
- name: Tests (vitest / jest autodetect)
run: |
if npm run | grep -qE '^ test'; then
# Prefer vitest if present
if npx --yes vitest --version >/dev/null 2>&1; then
npm run -s test --silent || npm test || true
else
npm test || true
fi
else
echo "No test script; skipping."
fi

View File

@@ -1,20 +1,18 @@
# CI on Gitea (self-hosted runner)
# CI on Gitea (no marketplace)
- Single workflow at `.gitea/workflows/ci.yml`.
- Triggers: `push`, `pull_request`, and `workflow_dispatch` (manual button).
- Runner labels required: `self-hosted`, `linux`, `x64` (match your `config.yaml`).
- Gitea runner may not auto-checkout; and `actions/checkout` might be unavailable.
- Workflow includes a **manual checkout** step using `$GITHUB_SERVER_URL` and `$GITHUB_REPOSITORY`.
- Runner label used: `ubuntu-latest:host` (matches your self-hosted runner config).
- Trigger: `push` (main/master/update) + `pull_request`.
- Gate: `npm run check` (vitest smoke + eslint phase0 scope).
## Common reasons a run doesn't start
If multiple workflows exist, run:
1. **No workflow in the pushed branch**
Ensure `.gitea/workflows/ci.yml` exists in the branch you push to.
2. **Multiple workflows / conflicting filters**
Keep only one file. Run: `bash scripts/dev/ci-ensure-one-workflow.sh` then commit.
3. **Runner offline or labels mismatch**
Runner must show `self-hosted`, `linux`, `x64`. Update `runs-on` or runner labels.
4. **Lockfile vs npm**
If `npm ci` fails with EUSAGE, refresh your `package-lock.json` locally and commit.
```bash
bash scripts/dev/ci-ensure-one-workflow.sh
git commit -m "ci: ensure single workflow"
git push
```
## Manual trigger
- In the repo “Actions” tab, select **CI (self-hosted)****Run workflow** (if enabled).
- Or push a noop commit: `bash scripts/dev/force-ci-push.sh <branch>`.
Troubleshooting:
- Failure: `package.json not found` → manual checkout couldn't determine ref; ensure repo is public or set a read token as secret env `GIT_READ_URL` and replace the clone URL accordingly.

View File

@@ -1,24 +1,15 @@
#!/usr/bin/env bash
set -euo pipefail
shopt -s nullglob
WF_DIR=".gitea/workflows"
LEGACY="$WF_DIR/ci-no-marketplace.yml"
MAIN="$WF_DIR/ci.yml"
echo "== Workflows before =="
ls -1 "$WF_DIR" || true
if [ -f "$LEGACY" ]; then
echo "Removing legacy workflow: $LEGACY"
git rm -f "$LEGACY"
fi
if [ ! -f "$MAIN" ]; then
echo "::error::Missing $MAIN (place updated workflow first)"
exit 1
fi
mkdir -p "$WF_DIR"
kept="$WF_DIR/ci.yml"
git add "$kept" >/dev/null 2>&1 || true
for f in "$WF_DIR"/*.yml "$WF_DIR"/*.yaml; do
[ "$f" = "$kept" ] && continue
echo "Removing stray workflow: $f"
git rm -f "$f" || rm -f "$f"
done
echo "== Workflows after =="
ls -1 "$WF_DIR" || true
git add "$MAIN"
echo "Done. Commit this change to ensure only one CI workflow exists."