Skip to content

Commit e28a903

Browse files
author
abrulic
committed
deployment fix?
1 parent 68f4f4c commit e28a903

File tree

3 files changed

+84
-55
lines changed

3 files changed

+84
-55
lines changed

.github/workflows/validate.yaml

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: 🚀 Validation Pipeline
22
concurrency:
33
group: ${{ github.repository }}-${{ github.workflow }}-${{ github.ref }}
44
cancel-in-progress: true
5+
56
on:
67
push:
78
branches: [main]
@@ -11,91 +12,92 @@ on:
1112
permissions:
1213
actions: write
1314
contents: read
14-
# Required to put a comment into the pull-request
1515
pull-requests: write
16+
1617
jobs:
1718
lint:
1819
name: ⬣ Biome lint
1920
runs-on: ubuntu-latest
2021
steps:
21-
- name: ⬇️ Checkout repo
22-
uses: actions/checkout@v4
23-
- name: Setup Biome
24-
uses: biomejs/setup-biome@v2
25-
- name: Run Biome
26-
run: biome ci .
22+
- uses: actions/checkout@v4
23+
- uses: biomejs/setup-biome@v2
24+
- run: biome ci .
2725

2826
validate:
2927
name: 🔎 Validate
3028
runs-on: ubuntu-latest
3129
steps:
32-
- name: 🛑 Cancel Previous Runs
33-
uses: styfle/cancel-workflow-action@0.12.1
34-
- name: ⬇️ Checkout repo
35-
uses: actions/checkout@v4
36-
- name: ⎔ Setup node
37-
uses: actions/setup-node@v4
30+
- uses: styfle/cancel-workflow-action@0.12.1
31+
- uses: actions/checkout@v4
32+
- uses: actions/setup-node@v4
3833
with:
3934
node-version: 20
40-
- name: Install pnpm
41-
uses: pnpm/action-setup@v4
42-
- name: Install dependencies
43-
run: pnpm install
44-
- name: 🔎 Validate
45-
run: pnpm run test
46-
35+
- uses: pnpm/action-setup@v4
36+
- run: pnpm install
37+
- run: pnpm run test
4738

4839
build-docs:
4940
if: ${{ github.event_name == 'pull_request' }}
5041
name: Build Docs
5142
runs-on: ubuntu-latest
5243
steps:
53-
- name: Checkout
54-
uses: actions/checkout@v4
44+
- uses: actions/checkout@v4
5545
with:
5646
fetch-depth: 0
57-
- name: Setup pnpm
58-
uses: pnpm/action-setup@v4
59-
- name: Setup Node
60-
uses: actions/setup-node@v4
47+
- uses: pnpm/action-setup@v4
48+
- uses: actions/setup-node@v4
6149
with:
6250
node-version-file: "package.json"
63-
cache: "pnpm"
51+
cache: pnpm
6452

65-
- name: Install deps
66-
run: pnpm install --prefer-offline --frozen-lockfile
53+
- run: pnpm install --prefer-offline --frozen-lockfile
6754

6855
- name: Generate docs
6956
working-directory: docs
70-
run: pnpm run generate:docs
57+
env:
58+
APP_ENV: production
59+
run: pnpm run generate:docs -- --branch ${{ github.event.repository.default_branch }}
7160

72-
- name: Upload generated docs artifact
61+
- name: Pack generated docs (tarball)
62+
run: tar -czf docs-generated.tgz -C docs generated-docs
63+
64+
- name: Upload generated docs (tgz)
7365
uses: actions/upload-artifact@v4
7466
with:
75-
name: docs-generated
76-
path: |
77-
docs/generated-docs/**
78-
docs/app/utils/versions.ts
67+
name: docs-generated-tgz
68+
path: docs-generated.tgz
69+
if-no-files-found: error
70+
71+
- name: Upload versions file
72+
uses: actions/upload-artifact@v4
73+
with:
74+
name: docs-versions
75+
path: docs/app/utils/versions.ts
7976
if-no-files-found: error
8077

8178
deploy-docs-pr-preview:
8279
if: ${{ github.event_name == 'pull_request' }}
8380
name: 🚀 Deploy Docs
84-
needs: [lint, validate, build-docs]
81+
needs: [lint, validate, build-docs]
8582
runs-on: ubuntu-latest
86-
environment:
87-
name: docs-release
8883
steps:
8984
- uses: actions/checkout@v4
90-
- name: Download generated docs
85+
86+
- name: Download generated docs (tgz)
87+
uses: actions/download-artifact@v4
88+
with:
89+
name: docs-generated-tgz
90+
path: .
91+
92+
- name: Unpack generated docs into docs/
93+
run: tar -xzf docs-generated.tgz -C docs
94+
95+
- name: Download versions file
9196
uses: actions/download-artifact@v4
9297
with:
93-
name: docs-generated
94-
path: docs
98+
name: docs-versions
99+
path: docs/app/utils
95100

96-
# check TODO remove this
97-
- name: List generated payload
98-
run: ls -laR docs/generated-docs | head -n 200
99101
- uses: forge-42/fly-deploy@v1.0.0-rc.2
100102
id: deploy
101103
env:

docs/Dockerfile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,26 @@ RUN npm install -g pnpm@$PNPM_VERSION
1313
# --- Build stage ---
1414
FROM base AS build
1515

16-
# System deps only if you have native modules; otherwise you can drop this
16+
# If you DON'T have native deps, you can remove this apt-get block.
1717
RUN apt-get update -qq && \
1818
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3 && \
1919
rm -rf /var/lib/apt/lists/*
2020

21-
# Install deps
22-
COPY .npmrc package.json ./
23-
RUN pnpm install --prod=false
21+
# Install deps (use lockfile for reproducible builds if present)
22+
COPY .npmrc package.json pnpm-lock.yaml ./
23+
RUN pnpm install --frozen-lockfile --prod=false
2424

25-
# Copy the application (including the previously downloaded artifact under docs/)
25+
# Copy the application (includes pre-generated docs & versions.ts from CI)
2626
COPY . .
2727

28-
# IMPORTANT: we no longer generate docs here; they were provided by CI
29-
# Build the app (should read from docs/generated-docs/* and versions.ts that CI uploaded)
28+
# Build the app (no docs generation here)
3029
RUN pnpm run build
3130

3231
# Prune dev deps
3332
RUN pnpm prune --prod
3433

3534
# --- Runtime stage ---
3635
FROM base
37-
3836
COPY --from=build /app /app
39-
4037
EXPOSE 3000
4138
CMD ["pnpm","run","start"]

docs/scripts/generate-docs.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ const contentDir = "content"
3535
const outputDir = "generated-docs"
3636
const APP_ENV = getServerEnv().APP_ENV as "development" | "production"
3737
const currentDocsWorkspace = process.cwd()
38-
const docsRelative = run("git rev-parse --show-prefix", { cwd: currentDocsWorkspace }).replace(/\/?$/, "")
38+
39+
// Make docsRelative safe even if something odd happens with git in CI
40+
let docsRelative = ""
41+
try {
42+
docsRelative = run("git rev-parse --show-prefix", { cwd: currentDocsWorkspace }).replace(/\/?$/, "")
43+
} catch {
44+
docsRelative = ""
45+
}
3946

4047
const allTags = () => run("git tag --list").split("\n").filter(Boolean)
4148

@@ -105,6 +112,28 @@ function buildRef(ref: string, labelForOutDir: string) {
105112
}
106113
}
107114

115+
function hasLocalRef(ref: string) {
116+
try {
117+
run(`git show-ref --verify --quiet ${ref}`)
118+
return true
119+
} catch {
120+
return false
121+
}
122+
}
123+
124+
function buildBranch(branch: string, labelForOutDir: string) {
125+
// Ensure we have the remote branch locally available
126+
run(`git fetch --tags --prune origin ${branch}`, {
127+
cwd: currentDocsWorkspace,
128+
inherit: true,
129+
})
130+
131+
const localRef = `refs/heads/${branch}`
132+
const targetRef = hasLocalRef(localRef) ? localRef : `origin/${branch}`
133+
134+
return buildRef(targetRef, labelForOutDir)
135+
}
136+
108137
function buildTag(tag: string) {
109138
return buildRef(`refs/tags/${tag}`, tag)
110139
}
@@ -121,6 +150,7 @@ function buildSpecifiedTags(spec: string, envLabel: "dev" | "prod"): string[] {
121150
for (const tag of tags) buildTag(tag)
122151
return tags
123152
}
153+
124154
;(async () => {
125155
const { values } = parseArgs({
126156
args: process.argv.slice(2),
@@ -151,7 +181,7 @@ function buildSpecifiedTags(spec: string, envLabel: "dev" | "prod"): string[] {
151181
// PROD + no --versions => build content from default branch only
152182
// biome-ignore lint/suspicious/noConsole: keep console log for debugging
153183
console.log(chalk.cyan(`(prod) Building docs from '${branch}' branch only → ${branch}`))
154-
buildRef(`refs/heads/${branch}`, branch)
184+
buildBranch(branch, branch) // << use local refs/heads/<branch> if present, else origin/<branch>
155185
builtVersions = [branch]
156186
} else {
157187
builtVersions = buildSpecifiedTags(values.versions as string, APP_ENV === "development" ? "dev" : "prod")

0 commit comments

Comments
 (0)