Skip to content

Commit e4e7679

Browse files
committed
Speed up scope-aware production Actions
1 parent 560c03f commit e4e7679

8 files changed

Lines changed: 300 additions & 17 deletions

‎.github/workflows/deploy-production.yml‎

Lines changed: 112 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
push:
55
branches:
66
- main
7+
paths-ignore:
8+
- 'docs/**'
9+
- '*.md'
710
workflow_dispatch:
811

912
permissions:
@@ -14,16 +17,112 @@ concurrency:
1417
cancel-in-progress: true
1518

1619
jobs:
20+
classify:
21+
runs-on: ubuntu-latest
22+
timeout-minutes: 3
23+
outputs:
24+
scope: ${{ steps.scope.outputs.scope }}
25+
steps:
26+
- name: Checkout history for trusted path classification
27+
uses: actions/checkout@v7
28+
with:
29+
fetch-depth: 0
30+
31+
- name: Test the fail-safe classifier
32+
run: npm run actions:scope:test
33+
34+
- name: Classify changed paths
35+
id: scope
36+
env:
37+
BEFORE_SHA: ${{ github.event.before }}
38+
EVENT_NAME: ${{ github.event_name }}
39+
run: |
40+
if [[ "$EVENT_NAME" == 'workflow_dispatch' || -z "$BEFORE_SHA" || "$BEFORE_SHA" =~ ^0+$ ]]; then
41+
printf 'scope=full\n' >> "$GITHUB_OUTPUT"
42+
exit 0
43+
fi
44+
git diff --name-only "$BEFORE_SHA" "$GITHUB_SHA" | node scripts/orbit-actions-scope.mjs
45+
46+
frontend:
47+
needs: classify
48+
if: ${{ needs.classify.outputs.scope != 'docs' }}
49+
runs-on: ubuntu-latest
50+
timeout-minutes: 12
51+
steps:
52+
- name: Checkout exact production candidate
53+
uses: actions/checkout@v7
54+
55+
- name: Set up Node
56+
uses: actions/setup-node@v7
57+
with:
58+
node-version: 24
59+
cache: npm
60+
61+
- name: Install dependencies
62+
run: npm ci
63+
64+
- name: Build and verify the production frontend once
65+
run: npm run verify:frontend:production
66+
67+
- name: Create the verified asset manifest
68+
run: |
69+
find dist/client -type f -print0 \
70+
| sort -z \
71+
| xargs -0 sha256sum > production-assets.sha256
72+
sha256sum --check production-assets.sha256
73+
74+
- name: Upload verified production assets
75+
uses: actions/upload-artifact@v6
76+
with:
77+
name: orbit-production-assets-${{ github.sha }}
78+
path: |
79+
dist/client
80+
production-assets.sha256
81+
if-no-files-found: error
82+
retention-days: 1
83+
84+
backend:
85+
needs: classify
86+
runs-on: ubuntu-latest
87+
timeout-minutes: 12
88+
steps:
89+
- name: Checkout backend candidate
90+
if: ${{ needs.classify.outputs.scope == 'full' }}
91+
uses: actions/checkout@v7
92+
93+
- name: Set up Node
94+
if: ${{ needs.classify.outputs.scope == 'full' }}
95+
uses: actions/setup-node@v7
96+
with:
97+
node-version: 24
98+
cache: npm
99+
100+
- name: Install dependencies
101+
if: ${{ needs.classify.outputs.scope == 'full' }}
102+
run: npm ci
103+
104+
- name: Verify D1, Worker, CLI and security behavior
105+
if: ${{ needs.classify.outputs.scope == 'full' }}
106+
run: npm run test:d1 && npm run orbit:test:cli
107+
108+
- name: Record frontend-only backend decision
109+
if: ${{ needs.classify.outputs.scope != 'full' }}
110+
run: echo 'No backend/security path changed; the fail-safe classifier selected frontend validation.'
111+
17112
deploy:
18-
if: ${{ github.ref == 'refs/heads/main' }}
113+
needs:
114+
- classify
115+
- frontend
116+
- backend
117+
if: ${{ needs.frontend.result == 'success' && needs.backend.result == 'success' }}
19118
runs-on: ubuntu-latest
20-
timeout-minutes: 20
119+
timeout-minutes: 8
21120
environment:
22121
name: production
23122
url: https://orbit.sametbasbug.dev
24123

25124
steps:
26-
- name: Checkout
125+
- name: Checkout the verified commit
27126
uses: actions/checkout@v7
28127

29128
- name: Set up Node
@@ -32,20 +131,21 @@ jobs:
32131
node-version: 24
33132
cache: npm
34133

35-
- name: Install dependencies
134+
- name: Install deployment dependencies
36135
run: npm ci
37136

38-
- name: Verify application and static output
39-
run: |
40-
npm run check
41-
npm run build
137+
- name: Download verified production assets
138+
uses: actions/download-artifact@v7
139+
with:
140+
name: orbit-production-assets-${{ github.sha }}
141+
path: .
42142

43-
- name: Build and verify the live bundle
143+
- name: Verify artifact and commit identity
44144
run: |
45-
npm run production:config:check
46-
npm run worker:build:production:live
145+
test "$(git rev-parse HEAD)" = "$GITHUB_SHA"
146+
sha256sum --check production-assets.sha256
47147
48-
- name: Deploy the main branch
148+
- name: Deploy the verified main artifact
49149
env:
50150
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
51151
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Orbit Full Regression
2+
3+
on:
4+
schedule:
5+
- cron: '30 1 * * *'
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
11+
concurrency:
12+
group: orbit-full-regression
13+
cancel-in-progress: false
14+
15+
jobs:
16+
full-regression:
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 20
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v7
22+
23+
- name: Set up Node
24+
uses: actions/setup-node@v7
25+
with:
26+
node-version: 24
27+
cache: npm
28+
29+
- name: Install dependencies
30+
run: npm ci
31+
32+
- name: Run the complete application regression
33+
run: |
34+
npm run actions:scope:test
35+
npm run check
36+
npm run build
37+
npm run production:config:check
38+
npm run worker:build:production:live

‎docs/FUTURE_PLANS.md‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,27 @@ belge henüz kesin API kontratı değildir.
128128

129129
## Plan 002 — Değişiklik kapsamına duyarlı hızlı GitHub Actions
130130

131-
**Durum:** Kabul edildi
131+
**Durum:** Uygulanıyor
132132

133133
**Karar tarihi:** 19 Temmuz 2026
134134

135-
**Uygulama:** Başlamadı
135+
**Uygulama:** Kod ve workflow değişiklikleri hazırlanıyor
136+
137+
### Uygulanan ilk sürüm
138+
139+
- Repo içindeki fail-safe sınıflandırıcı değişiklikleri `docs`, `frontend` veya
140+
`full` olarak ayırır; bilinmeyen ve karma kapsam doğrudan `full` olur.
141+
- `docs/**` ve kök Markdown dosyalarıyla sınırlı push'lar production workflow'unu
142+
hiç başlatmaz.
143+
- Frontend doğrulaması production Astro çıktısını bir kez üretir; site ve gerçek
144+
tarayıcı testleri aynı `dist/client` artifact'ını sınar.
145+
- Backend/güvenlik paketi yalnız `full` kapsamda frontend işiyle paralel çalışır.
146+
- Deploy işi yalnız iki doğrulama işi de başarılıysa, exact commit ve SHA-256
147+
manifesti doğrulanmış artifact'ı Cloudflare'a gönderir.
148+
- Her gün `01:30 UTC` zamanlı ve manuel başlatılabilir ayrı tam regresyon workflow'u
149+
mevcut test paketinin tamamını korur; production deploy yapmaz.
150+
- İlk yerel ölçümde frontend production doğrulaması yaklaşık 49 saniye, tam D1
151+
ve CLI paketi yaklaşık 45 saniye sürdü; CI'da bunlar paralel çalışacaktır.
136152

137153
### Amaç
138154

‎package.json‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"build": "npm run test:d1 && npm run orbit:test && npm run orbit:validate && npm run og:generate && astro build && npm run site:test && npm run browser:test",
99
"worker:build": "astro build --config astro.worker.config.mjs && wrangler deploy --dry-run --config wrangler.jsonc --outdir dist/worker",
1010
"worker:build:staging": "ORBIT_SITE_URL=https://orbit-v6-staging.samett33710.workers.dev ORBIT_NOINDEX=true astro build --config astro.worker.config.mjs && node scripts/orbit-staging-assets.mjs && wrangler deploy --dry-run --config wrangler.staging.jsonc --outdir dist/worker-staging",
11-
"worker:build:production:live": "ORBIT_SITE_URL=https://orbit.sametbasbug.dev ORBIT_NOINDEX=false astro build --config astro.worker.config.mjs && wrangler deploy --dry-run --config wrangler.production.live.jsonc --outdir dist/worker-production-live",
11+
"worker:assets:production:live": "ORBIT_SITE_URL=https://orbit.sametbasbug.dev ORBIT_NOINDEX=false astro build --config astro.worker.config.mjs",
12+
"worker:bundle:production:live": "wrangler deploy --dry-run --config wrangler.production.live.jsonc --outdir dist/worker-production-live",
13+
"worker:build:production:live": "npm run worker:assets:production:live && npm run worker:bundle:production:live",
1214
"worker:build:production:dark-launch": "ORBIT_SITE_URL=https://orbit-v6-production.samett33710.workers.dev ORBIT_NOINDEX=true astro build --config astro.worker.config.mjs && node scripts/orbit-staging-assets.mjs && wrangler deploy --dry-run --config wrangler.production.dark-launch.jsonc --outdir dist/worker-production-dark-launch",
1315
"worker:dev": "node scripts/orbit-local-dev.mjs",
1416
"d1:migrate:local": "wrangler d1 migrations apply orbit-v6-local --local",
@@ -32,7 +34,11 @@
3234
"orbit:validate": "node scripts/orbit-validate.mjs",
3335
"production:config:check": "node scripts/orbit-production-config-tests.mjs",
3436
"orbit:index": "node scripts/orbit-index.mjs",
35-
"orbit:test": "node scripts/orbit-content-tests.mjs && node scripts/orbit-cli-tests.mjs",
37+
"orbit:test:content": "node scripts/orbit-content-tests.mjs",
38+
"orbit:test:cli": "node scripts/orbit-cli-tests.mjs",
39+
"orbit:test": "npm run orbit:test:content && npm run orbit:test:cli",
40+
"actions:scope:test": "node --test scripts/orbit-actions-scope-tests.mjs",
41+
"verify:frontend:production": "npm run orbit:test:content && npm run check && npm run og:generate && npm run worker:assets:production:live && ORBIT_DIST_DIR=dist/client npm run site:test && ORBIT_DIST_DIR=dist/client npm run browser:test && npm run production:config:check && npm run worker:bundle:production:live",
3642
"site:test": "node scripts/orbit-site-tests.mjs",
3743
"browser:test": "node scripts/orbit-browser-tests.mjs",
3844
"og:generate": "node scripts/orbit-og-images.mjs",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env node
2+
import assert from 'node:assert/strict';
3+
import test from 'node:test';
4+
import { classifyChangedPaths } from './orbit-actions-scope.mjs';
5+
6+
test('classifies documentation-only changes without a deploy', () => {
7+
assert.equal(classifyChangedPaths(['docs/FUTURE_PLANS.md', 'README.md']), 'docs');
8+
});
9+
10+
test('classifies public content and visual changes as frontend', () => {
11+
assert.equal(classifyChangedPaths(['src/components/PostCard.astro']), 'frontend');
12+
assert.equal(classifyChangedPaths(['src/content/records/posts/example/post.md']), 'frontend');
13+
assert.equal(classifyChangedPaths(['public/favicon.svg', 'docs/design.md']), 'frontend');
14+
});
15+
16+
test('classifies backend and security-sensitive changes as full', () => {
17+
assert.equal(classifyChangedPaths(['src/server/http/api.ts']), 'full');
18+
assert.equal(classifyChangedPaths(['migrations/0016_pairing.sql']), 'full');
19+
assert.equal(classifyChangedPaths(['wrangler.production.live.jsonc']), 'full');
20+
assert.equal(classifyChangedPaths(['package-lock.json']), 'full');
21+
assert.equal(classifyChangedPaths(['.github/workflows/deploy-production.yml']), 'full');
22+
});
23+
24+
test('escalates mixed and unknown changes to full', () => {
25+
assert.equal(classifyChangedPaths(['src/styles/global.css', 'src/server/http/api.ts']), 'full');
26+
assert.equal(classifyChangedPaths(['unknown/tool.config']), 'full');
27+
assert.equal(classifyChangedPaths([]), 'full');
28+
});

‎scripts/orbit-actions-scope.mjs‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env node
2+
import fs from 'node:fs';
3+
import { pathToFileURL } from 'node:url';
4+
5+
const FULL_PATTERNS = [
6+
/^\.github\//u,
7+
/^migrations\//u,
8+
/^src\/server\//u,
9+
/^src\/worker\.ts$/u,
10+
/^wrangler(?:\.[^/]+)?\.jsonc$/u,
11+
/^package(?:-lock)?\.json$/u,
12+
/^astro\.worker\.config\.mjs$/u,
13+
/^scripts\/(?!orbit-(?:browser-tests|content-tests|content-utils|index|og-images|site-tests|validate)\.mjs$)/u,
14+
];
15+
16+
const FRONTEND_PATTERNS = [
17+
/^astro\.config\.mjs$/u,
18+
/^public\//u,
19+
/^src\/(?:components|content|data|layouts|lib|pages|scripts|styles)\//u,
20+
/^src\/env\.d\.ts$/u,
21+
/^scripts\/orbit-(?:browser-tests|content-tests|content-utils|index|og-images|site-tests|validate)\.mjs$/u,
22+
];
23+
24+
function normalized(paths) {
25+
return [...new Set(paths.map((file) => file.trim().replace(/^\.\//u, '')).filter(Boolean))];
26+
}
27+
28+
function documentationOnly(file) {
29+
return file.startsWith('docs/') || /^[^/]+\.mdx?$/u.test(file);
30+
}
31+
32+
export function classifyChangedPaths(paths) {
33+
const files = normalized(paths);
34+
if (files.length === 0) return 'full';
35+
let frontend = false;
36+
for (const file of files) {
37+
if (FULL_PATTERNS.some((pattern) => pattern.test(file))) return 'full';
38+
if (FRONTEND_PATTERNS.some((pattern) => pattern.test(file))) {
39+
frontend = true;
40+
continue;
41+
}
42+
if (documentationOnly(file)) continue;
43+
return 'full';
44+
}
45+
return frontend ? 'frontend' : 'docs';
46+
}
47+
48+
function runCli() {
49+
const files = fs.readFileSync(0, 'utf8').split(/\r?\n/u);
50+
const scope = classifyChangedPaths(files);
51+
process.stdout.write(`${scope}\n`);
52+
if (process.env.GITHUB_OUTPUT) {
53+
fs.appendFileSync(process.env.GITHUB_OUTPUT, `scope=${scope}\n`, 'utf8');
54+
}
55+
}
56+
57+
if (import.meta.url === pathToFileURL(process.argv[1]).href) runCli();

‎scripts/orbit-content-utils.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from '../src/lib/record-path.mjs';
1515

1616
export const ROOT = path.resolve(import.meta.dirname, '..');
17-
export const DIST_DIR = path.join(ROOT, 'dist');
17+
export const DIST_DIR = path.resolve(ROOT, process.env.ORBIT_DIST_DIR ?? 'dist');
1818
export const RECORDS_DIR = path.join(ROOT, 'src', 'content', 'records');
1919
export const POSTS_DIR = path.join(RECORDS_DIR, 'posts');
2020
export const RECORD_INDEX_FILE = path.join(RECORDS_DIR, 'index.json');

0 commit comments

Comments
 (0)