Skip to content

Commit eb75a98

Browse files
Merge branch 'main' into pkg-pr-new-version
2 parents 6f84c82 + cbc5e9e commit eb75a98

File tree

4 files changed

+80
-10
lines changed

4 files changed

+80
-10
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Docs preview create
2+
3+
on:
4+
repository_dispatch:
5+
types: [docs-preview-create]
6+
7+
env:
8+
BRANCH: sync/${{ github.event.client_payload.package }}/${{ github.event.client_payload.owner }}/${{ github.event.client_payload.branch }}
9+
10+
jobs:
11+
Sync:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
token: ${{ secrets.GH_TOKEN }}
17+
- uses: pnpm/action-setup@v4
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: 22
21+
cache: pnpm
22+
- run: pnpm install --frozen-lockfile
23+
24+
- name: Checkout
25+
run: git fetch origin ${{ env.BRANCH }} && git checkout ${{ env.BRANCH }} || git checkout -b ${{ env.BRANCH }}
26+
27+
- name: Sync
28+
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 }}"
29+
30+
- name: Configure Git
31+
run: |
32+
git config --global user.name "GitHub Actions Bot"
33+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
34+
35+
- name: Push
36+
run: git add -A && git commit -m "sync docs" && git push -u origin ${{ env.BRANCH }}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Docs preview delete
2+
3+
on:
4+
repository_dispatch:
5+
types: [docs-preview-delete]
6+
7+
jobs:
8+
Sync:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
token: ${{ secrets.GH_TOKEN }}
14+
15+
- name: Delete branch
16+
run: git push 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)