Compare commits
16
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea00c8dbb4 | ||
|
|
27b21b4701 | ||
|
|
e1bf495afa | ||
|
|
fd8eec3c70 | ||
|
|
e5f383786f | ||
|
|
9e97261ef6 | ||
|
|
529971dcf4 | ||
|
|
db36aa2a41 | ||
|
|
75bde7ea38 | ||
|
|
9604812daa | ||
|
|
584eff4c2a | ||
|
|
c57f3012e9 | ||
|
|
20c1f03dff | ||
|
|
3ab85da567 | ||
|
|
07e6e3c5ae | ||
|
|
a8cf867fe0 |
@@ -0,0 +1,68 @@
|
||||
---
|
||||
# Homelab CI — Docker/heavy lane (git-ci-02)
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master, main]
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
jobs:
|
||||
skip-ci-check:
|
||||
runs-on: [homelab, self-hosted, linux]
|
||||
container:
|
||||
image: node:20-bookworm
|
||||
outputs:
|
||||
should-skip: ${{ steps.check.outputs.skip }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 1
|
||||
- id: check
|
||||
run: |
|
||||
SKIP=0
|
||||
BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
|
||||
MSG="${GITHUB_EVENT_HEAD_COMMIT_MESSAGE:-$(git log -1 --pretty=%B 2>/dev/null || true)}"
|
||||
echo "$BRANCH" "$MSG" | grep -qi '@skipci' && SKIP=1
|
||||
echo "skip=$SKIP" >> $GITHUB_OUTPUT
|
||||
|
||||
docker-ci:
|
||||
needs: skip-ci-check
|
||||
if: needs.skip-ci-check.outputs.should-skip != '1'
|
||||
runs-on: [homelab, self-hosted, linux, heavy, docker]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Hadolint
|
||||
run: |
|
||||
shopt -s globstar nullglob
|
||||
found=0
|
||||
for f in Dockerfile docker/**/Dockerfile */Dockerfile; do
|
||||
[ -f "$f" ] || continue
|
||||
found=1
|
||||
# Warnings (unpinned apt/pip) are advisory; only errors fail the job
|
||||
docker run --rm -i hadolint/hadolint hadolint --failure-threshold error - < "$f"
|
||||
done
|
||||
[ "$found" -eq 1 ] || echo "No Dockerfile — skip hadolint"
|
||||
|
||||
- name: Trivy config scan (advisory)
|
||||
run: |
|
||||
docker run --rm -v "$PWD:/repo" aquasec/trivy:latest config /repo || true
|
||||
|
||||
secret-scan:
|
||||
needs: skip-ci-check
|
||||
if: needs.skip-ci-check.outputs.should-skip != '1'
|
||||
runs-on: [homelab, self-hosted, linux, heavy]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Gitleaks
|
||||
run: |
|
||||
extra=""
|
||||
if [ -f .gitleaks.toml ]; then
|
||||
extra="--config /repo/.gitleaks.toml"
|
||||
fi
|
||||
docker run --rm -v "$PWD:/repo" ghcr.io/gitleaks/gitleaks:latest \
|
||||
detect --source /repo --no-banner --redact ${extra}
|
||||
@@ -0,0 +1,28 @@
|
||||
# Homelab bootstrap — gitleaks allowlist (tests, examples, placeholders)
|
||||
#
|
||||
# IMPORTANT: `useDefault = true` is required — without it gitleaks loads ONLY
|
||||
# this file (title + allowlist) with ZERO detection rules, so it would never
|
||||
# flag a real secret. Fixed 2026-07 (security-hardening track); if you're
|
||||
# re-pushing this template to a repo that already had the old version, that
|
||||
# repo's secret scanning was a no-op until this lands.
|
||||
title = "homelab gitea bootstrap"
|
||||
|
||||
[extend]
|
||||
useDefault = true
|
||||
|
||||
[allowlist]
|
||||
description = "Test fixtures and example configs are not production secrets"
|
||||
paths = [
|
||||
'''(?i).*\.test\.(ts|tsx|js|jsx|py)$''',
|
||||
'''(?i).*\.spec\.(ts|tsx|js|jsx)$''',
|
||||
'''(?i).*/tests/.*''',
|
||||
'''(?i).*/__tests__/.*''',
|
||||
'''(?i).*\.example\.(yml|yaml|env|json|toml)$''',
|
||||
'''(?i).*vault\.example\.(yml|yaml)$''',
|
||||
'''(?i).*\.env\.example$''',
|
||||
]
|
||||
regexes = [
|
||||
'''(?i)(invalid|fake|dummy|placeholder|example|changeme|change_me|not-a-real)''',
|
||||
'''(?i)sk-or-invalid''',
|
||||
'''(?i)msk-or-invalid''',
|
||||
]
|
||||
@@ -111,6 +111,12 @@ function parseWorkplaceTypes(
|
||||
}
|
||||
}
|
||||
|
||||
function encodeSearchState(searchState: unknown): string {
|
||||
const json = JSON.stringify(searchState);
|
||||
const urlEncodedJson = encodeURIComponent(json);
|
||||
return Buffer.from(urlEncodedJson, "utf-8").toString("base64");
|
||||
}
|
||||
|
||||
function asRecord(value: unknown): Record<string, unknown> | null {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
||||
return value as Record<string, unknown>;
|
||||
@@ -224,18 +230,7 @@ function extractResultsBatch(payload: unknown): RawHiringCafeJob[] {
|
||||
}
|
||||
|
||||
const payloadRecord = asRecord(payload);
|
||||
if (!payloadRecord) return [];
|
||||
|
||||
const pageProps = asRecord(payloadRecord.pageProps);
|
||||
const ssrHits = pageProps?.ssrHits ?? payloadRecord.ssrHits;
|
||||
if (Array.isArray(ssrHits)) {
|
||||
return ssrHits.filter(
|
||||
(item): item is RawHiringCafeJob =>
|
||||
Boolean(item) && typeof item === "object" && !Array.isArray(item),
|
||||
);
|
||||
}
|
||||
|
||||
const results = payloadRecord.results;
|
||||
const results = payloadRecord?.results;
|
||||
if (!Array.isArray(results)) return [];
|
||||
|
||||
return results.filter(
|
||||
@@ -247,22 +242,7 @@ function extractResultsBatch(payload: unknown): RawHiringCafeJob[] {
|
||||
function parseTotalCount(payload: unknown): number | null {
|
||||
const payloadRecord = asRecord(payload);
|
||||
if (!payloadRecord) return null;
|
||||
|
||||
const pageProps = asRecord(payloadRecord.pageProps);
|
||||
return (
|
||||
toNumberOrNull(pageProps?.ssrTotalCount) ??
|
||||
toNumberOrNull(payloadRecord.ssrTotalCount) ??
|
||||
toNumberOrNull(payloadRecord.total)
|
||||
);
|
||||
}
|
||||
|
||||
function isLastSsrPage(payload: unknown): boolean {
|
||||
const payloadRecord = asRecord(payload);
|
||||
if (!payloadRecord) return true;
|
||||
|
||||
const pageProps = asRecord(payloadRecord.pageProps);
|
||||
const isLastPage = pageProps?.ssrIsLastPage ?? payloadRecord.ssrIsLastPage;
|
||||
return isLastPage === true;
|
||||
return toNumberOrNull(payloadRecord.total);
|
||||
}
|
||||
|
||||
function buildCityLocationId(input: string): string {
|
||||
@@ -521,37 +501,23 @@ function createCitySearchState(args: {
|
||||
};
|
||||
}
|
||||
|
||||
async function readBuildIdFromPage(page: Page): Promise<string> {
|
||||
const buildId = await page.evaluate(() => {
|
||||
const element = document.querySelector("#__NEXT_DATA__");
|
||||
if (!element?.textContent) return null;
|
||||
const data = JSON.parse(element.textContent) as { buildId?: string };
|
||||
return data.buildId ?? null;
|
||||
});
|
||||
if (!buildId) {
|
||||
throw new Error("Hiring Cafe page did not expose Next.js buildId");
|
||||
}
|
||||
return buildId;
|
||||
}
|
||||
|
||||
async function fetchSsrSearchPage(
|
||||
async function callHiringCafeApi(
|
||||
page: Page,
|
||||
buildId: string,
|
||||
searchState: Record<string, unknown>,
|
||||
pageNo: number,
|
||||
endpoint: string,
|
||||
params: Record<string, string>,
|
||||
): Promise<unknown> {
|
||||
const response = await page.evaluate(
|
||||
async ({ buildIdArg, searchStateArg, pageNoArg }) => {
|
||||
const params = new URLSearchParams();
|
||||
params.set("searchState", JSON.stringify(searchStateArg));
|
||||
params.set("page", String(pageNoArg));
|
||||
const url = `/_next/data/${buildIdArg}/index.json?${params.toString()}`;
|
||||
async ({ endpointArg, paramsArg }) => {
|
||||
const url = new URL(endpointArg, window.location.origin);
|
||||
for (const [key, value] of Object.entries(paramsArg)) {
|
||||
url.searchParams.set(key, value);
|
||||
}
|
||||
|
||||
const res = await fetch(url, {
|
||||
const res = await fetch(url.toString(), {
|
||||
method: "GET",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"x-nextjs-data": "1",
|
||||
Accept: "application/json, text/plain, */*",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -573,7 +539,7 @@ async function fetchSsrSearchPage(
|
||||
|
||||
return output;
|
||||
},
|
||||
{ buildIdArg: buildId, searchStateArg: searchState, pageNoArg: pageNo },
|
||||
{ endpointArg: endpoint, paramsArg: params },
|
||||
);
|
||||
|
||||
const result = response as BrowserApiResponse;
|
||||
@@ -581,14 +547,14 @@ async function fetchSsrSearchPage(
|
||||
if (!result.ok) {
|
||||
const snippet = result.responseText.slice(0, 250);
|
||||
throw new Error(
|
||||
`Hiring Cafe SSR search failed (${result.status} ${result.statusText}): ${snippet}`,
|
||||
`Hiring Cafe API ${endpoint} failed (${result.status} ${result.statusText}): ${snippet}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (result.data === null) {
|
||||
const snippet = result.responseText.slice(0, 250);
|
||||
throw new Error(
|
||||
`Hiring Cafe SSR search returned non-JSON response: ${snippet}`,
|
||||
`Hiring Cafe API ${endpoint} returned non-JSON response: ${snippet}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -660,8 +626,6 @@ async function run(): Promise<void> {
|
||||
await initializePage();
|
||||
}
|
||||
|
||||
const buildId = await readBuildIdFromPage(page);
|
||||
|
||||
const countryLocation = resolveHiringCafeCountryLocation(country);
|
||||
const countryLong =
|
||||
countryLocation?.address_components[0]?.long_name ?? "United Kingdom";
|
||||
@@ -700,23 +664,40 @@ async function run(): Promise<void> {
|
||||
dateFetchedPastNDays,
|
||||
workplaceTypes,
|
||||
});
|
||||
let termTarget = maxJobsPerTerm;
|
||||
const encodedSearchState = encodeSearchState(searchState);
|
||||
|
||||
let totalAvailable: number | null = null;
|
||||
try {
|
||||
const countPayload = await callHiringCafeApi(
|
||||
page,
|
||||
"/api/search-jobs/get-total-count",
|
||||
{
|
||||
s: encodedSearchState,
|
||||
},
|
||||
);
|
||||
totalAvailable = parseTotalCount(countPayload);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
console.warn(
|
||||
`Hiring Cafe count request failed for term '${searchTerm}': ${message}`,
|
||||
);
|
||||
}
|
||||
|
||||
const termTarget =
|
||||
totalAvailable !== null
|
||||
? Math.min(maxJobsPerTerm, totalAvailable)
|
||||
: maxJobsPerTerm;
|
||||
|
||||
let pageNo = 0;
|
||||
let termCollected = 0;
|
||||
|
||||
while (termCollected < termTarget && pageNo < PAGE_LIMIT) {
|
||||
const jobsPayload = await fetchSsrSearchPage(
|
||||
page,
|
||||
buildId,
|
||||
searchState,
|
||||
pageNo,
|
||||
);
|
||||
|
||||
const totalAvailable = parseTotalCount(jobsPayload);
|
||||
if (totalAvailable !== null) {
|
||||
termTarget = Math.min(maxJobsPerTerm, totalAvailable);
|
||||
}
|
||||
const size = Math.min(1000, termTarget - termCollected);
|
||||
const jobsPayload = await callHiringCafeApi(page, "/api/search-jobs", {
|
||||
size: String(size),
|
||||
page: String(pageNo),
|
||||
s: encodedSearchState,
|
||||
});
|
||||
|
||||
const batch = extractResultsBatch(jobsPayload);
|
||||
if (batch.length === 0) break;
|
||||
@@ -746,7 +727,7 @@ async function run(): Promise<void> {
|
||||
totalCollected: termCollected,
|
||||
});
|
||||
|
||||
if (isLastSsrPage(jobsPayload)) break;
|
||||
if (batch.length < size) break;
|
||||
pageNo += 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user