Skip to content

Commit f4deccd

Browse files
authored
create docs-preview-create workflow (#776)
* create docs-preview-create workflow * maybe it's as simple as this?
1 parent 8e11751 commit f4deccd

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Docs preview create
2+
3+
on:
4+
repository_dispatch:
5+
types: [docs-preview-create]
6+
7+
jobs:
8+
Sync:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: pnpm/action-setup@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: 22
16+
cache: pnpm
17+
- run: pnpm install --frozen-lockfile
18+
19+
- name: Checkout
20+
run: git checkout -B refs/heads/sync/${{ github.event.client_payload.package }}/${{ github.event.client_payload.owner }}/${{ github.event.client_payload.branch }}
21+
22+
- name: Sync
23+
run: cd apps/svelte.dev && pnpm sync-docs --owner="${{ github.event.client_payload.owner }}" -p "${{ github.event.client_payload.package }}#${{ github.event.client_payload.branch }}"
24+
25+
- name: Push
26+
run: git add -A && git commit -m "sync docs" && git push -u origin sync/${{ github.event.client_payload.package }}/${{ github.event.client_payload.owner }}/${{ github.event.client_payload.branch }}

apps/svelte.dev/scripts/sync-docs/index.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ const parsed = parseArgs({
3030
pull: {
3131
type: 'boolean',
3232
short: 'p'
33+
},
34+
owner: {
35+
type: 'string',
36+
default: 'sveltejs'
3337
}
3438
},
3539
strict: true,
@@ -40,11 +44,23 @@ const dirname = fileURLToPath(new URL('.', import.meta.url));
4044
const REPOS = path.join(dirname, '../../repos');
4145
const DOCS = path.join(dirname, '../../content/docs');
4246

47+
const branches = {};
48+
49+
for (const option of parsed.positionals) {
50+
const [name, ...rest] = option.split('#');
51+
52+
if (branches[name]) {
53+
throw new Error(`Duplicate branches for ${name}`);
54+
}
55+
56+
branches[name] = rest.join('#') || 'main';
57+
}
58+
4359
const packages: Package[] = [
4460
{
4561
name: 'svelte',
46-
repo: 'sveltejs/svelte',
47-
branch: 'main',
62+
repo: `${parsed.values.owner}/svelte`,
63+
branch: branches['svelte'] ?? 'main',
4864
pkg: 'packages/svelte',
4965
docs: 'documentation/docs',
5066
types: 'types',
@@ -67,8 +83,8 @@ const packages: Package[] = [
6783
},
6884
{
6985
name: 'kit',
70-
repo: 'sveltejs/kit',
71-
branch: 'main',
86+
repo: `${parsed.values.owner}/kit`,
87+
branch: branches['kit'] ?? 'main',
7288
pkg: 'packages/kit',
7389
docs: 'documentation/docs',
7490
types: 'types',
@@ -127,15 +143,15 @@ const packages: Package[] = [
127143
},
128144
{
129145
name: 'cli',
130-
repo: 'sveltejs/cli',
131-
branch: 'main',
146+
repo: `${parsed.values.owner}/cli`,
147+
branch: branches['cli'] ?? 'main',
132148
pkg: 'packages/cli',
133149
docs: 'documentation/docs',
134150
types: null
135151
}
136152
];
137153

138-
const unknown = parsed.positionals.filter((name) => !packages.some((pkg) => pkg.name === name));
154+
const unknown = Object.keys(branches).filter((name) => !packages.some((pkg) => pkg.name === name));
139155

140156
if (unknown.length > 0) {
141157
throw new Error(
@@ -144,9 +160,7 @@ if (unknown.length > 0) {
144160
}
145161

146162
const filtered =
147-
parsed.positionals.length === 0
148-
? packages
149-
: packages.filter((pkg) => parsed.positionals.includes(pkg.name));
163+
parsed.positionals.length === 0 ? packages : packages.filter((pkg) => !!branches[pkg.name]);
150164

151165
/**
152166
* Depending on your setup, this will either clone the Svelte and SvelteKit repositories

apps/svelte.dev/scripts/sync-docs/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export async function clone_repo(repo: string, name: string, branch: string, cwd
88
if (fs.existsSync(dir)) {
99
const opts = { cwd: dir };
1010

11+
if (!repo.startsWith('sveltejs/')) {
12+
console.warn('Ignoring --owner flag for already-cloned repo');
13+
}
14+
1115
if (execSync('git status -s', opts).toString() !== '') {
1216
throw new Error(`${name} repo is dirty — aborting`);
1317
}

0 commit comments

Comments
 (0)