Skip to content

Commit

Permalink
create docs-preview-create workflow (sveltejs#776)
Browse files Browse the repository at this point in the history
* create docs-preview-create workflow

* maybe it's as simple as this?
  • Loading branch information
Rich-Harris authored Nov 2, 2024
1 parent 8e11751 commit f4deccd
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/docs-preview-create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Docs preview create

on:
repository_dispatch:
types: [docs-preview-create]

jobs:
Sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- run: pnpm install --frozen-lockfile

- name: Checkout
run: git checkout -B refs/heads/sync/${{ github.event.client_payload.package }}/${{ github.event.client_payload.owner }}/${{ github.event.client_payload.branch }}

- name: Sync
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 }}"

- name: Push
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 }}
34 changes: 24 additions & 10 deletions apps/svelte.dev/scripts/sync-docs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const parsed = parseArgs({
pull: {
type: 'boolean',
short: 'p'
},
owner: {
type: 'string',
default: 'sveltejs'
}
},
strict: true,
Expand All @@ -40,11 +44,23 @@ const dirname = fileURLToPath(new URL('.', import.meta.url));
const REPOS = path.join(dirname, '../../repos');
const DOCS = path.join(dirname, '../../content/docs');

const branches = {};

for (const option of parsed.positionals) {
const [name, ...rest] = option.split('#');

if (branches[name]) {
throw new Error(`Duplicate branches for ${name}`);
}

branches[name] = rest.join('#') || 'main';
}

const packages: Package[] = [
{
name: 'svelte',
repo: 'sveltejs/svelte',
branch: 'main',
repo: `${parsed.values.owner}/svelte`,
branch: branches['svelte'] ?? 'main',
pkg: 'packages/svelte',
docs: 'documentation/docs',
types: 'types',
Expand All @@ -67,8 +83,8 @@ const packages: Package[] = [
},
{
name: 'kit',
repo: 'sveltejs/kit',
branch: 'main',
repo: `${parsed.values.owner}/kit`,
branch: branches['kit'] ?? 'main',
pkg: 'packages/kit',
docs: 'documentation/docs',
types: 'types',
Expand Down Expand Up @@ -127,15 +143,15 @@ const packages: Package[] = [
},
{
name: 'cli',
repo: 'sveltejs/cli',
branch: 'main',
repo: `${parsed.values.owner}/cli`,
branch: branches['cli'] ?? 'main',
pkg: 'packages/cli',
docs: 'documentation/docs',
types: null
}
];

const unknown = parsed.positionals.filter((name) => !packages.some((pkg) => pkg.name === name));
const unknown = Object.keys(branches).filter((name) => !packages.some((pkg) => pkg.name === name));

if (unknown.length > 0) {
throw new Error(
Expand All @@ -144,9 +160,7 @@ if (unknown.length > 0) {
}

const filtered =
parsed.positionals.length === 0
? packages
: packages.filter((pkg) => parsed.positionals.includes(pkg.name));
parsed.positionals.length === 0 ? packages : packages.filter((pkg) => !!branches[pkg.name]);

/**
* Depending on your setup, this will either clone the Svelte and SvelteKit repositories
Expand Down
4 changes: 4 additions & 0 deletions apps/svelte.dev/scripts/sync-docs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export async function clone_repo(repo: string, name: string, branch: string, cwd
if (fs.existsSync(dir)) {
const opts = { cwd: dir };

if (!repo.startsWith('sveltejs/')) {
console.warn('Ignoring --owner flag for already-cloned repo');
}

if (execSync('git status -s', opts).toString() !== '') {
throw new Error(`${name} repo is dirty — aborting`);
}
Expand Down

0 comments on commit f4deccd

Please sign in to comment.