Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Check generated artifacts
run: npm run artifacts:check

- name: Run tests
run: npm test
3 changes: 3 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Check generated artifacts
run: npm run artifacts:check

- name: Run tests
run: npm test

Expand Down
4 changes: 1 addition & 3 deletions examples/promote-tested-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ jobs:
node-version: '22'

- name: Run patchlane promote
run: npx patchlane@0.4.0 promote
run: npx patchlane@0.4.1 promote
env:
BASE_BRANCH: main
SYNC_BRANCH: sync/integration
EXPECTED_SYNC_SHA: ${{ github.event.workflow_run.head_sha }}
2 changes: 1 addition & 1 deletion examples/sync-upstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
node-version: '22'

- name: Run patchlane sync
run: npx patchlane@0.4.0 sync
run: npx patchlane@0.4.1 sync
env:
UPSTREAM_SOURCE: ${{ inputs.source }}
PATCH_REFS: ${{ inputs.patch_refs }}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
"node": ">=22"
},
"scripts": {
"build": "node --experimental-strip-types ./scripts/sync-skill-assets.ts && tsc -p tsconfig.json",
"artifacts:sync": "node --experimental-strip-types ./scripts/sync-skill-assets.ts",
"artifacts:check": "node --experimental-strip-types ./scripts/sync-skill-assets.ts --check",
"build": "npm run artifacts:sync && tsc -p tsconfig.json",
"changelog": "node --experimental-strip-types ./scripts/changelog.ts --print",
"changelog:raw": "node --experimental-strip-types ./scripts/raw-changelog.ts",
"release": "gh workflow run draft-release.yml",
"test": "npm run build && tsc -p tsconfig.test.json && vitest run",
"format": "prettier --write .",
"format:check": "prettier --check ."
"format:check": "prettier --check .",
"prepublishOnly": "npm run artifacts:check"
},
"devDependencies": {
"@types/node": "^25.6.0",
Expand Down
79 changes: 66 additions & 13 deletions scripts/sync-skill-assets.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,71 @@
import { copyFileSync, mkdirSync } from 'node:fs';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { format } from 'prettier';
import type { PatchlaneConfig } from '../src/config.ts';
import { renderPromotionWorkflow, renderSyncWorkflow } from '../src/workflow-templates.ts';

const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const rootDir = path.resolve(import.meta.dirname, '..');
const check = process.argv.includes('--check');
const packagePath = path.join(rootDir, 'package.json');
const packageJson = JSON.parse(readFileSync(packagePath, 'utf8')) as { version?: unknown };
if (typeof packageJson.version !== 'string' || !packageJson.version) {
throw new Error('Patchlane package version is missing.');
}

const exampleConfig: PatchlaneConfig = {
upstreamOwner: 'example',
upstreamRepo: 'upstream',
source: 'release:latest',
baseBranch: 'main',
syncBranch: 'sync/integration',
patchRefs: ['patch/sync', 'patch/ci'],
ciWorkflow: 'Fork CI',
};

const prettierOptions = {
filepath: path.join(rootDir, 'examples/sync-upstream.yml'),
singleQuote: true,
};
const syncWorkflow = await format(renderSyncWorkflow(exampleConfig, packageJson.version), prettierOptions);
const promotionWorkflow = await format(renderPromotionWorkflow(exampleConfig, packageJson.version), prettierOptions);
const forkCiWorkflow = readFileSync(path.join(rootDir, 'examples/fork-ci.yml'), 'utf8');

const generatedFiles = new Map([
['examples/sync-upstream.yml', syncWorkflow],
['examples/promote-tested-sync.yml', promotionWorkflow],
['skills/patchlane-fork-setup/assets/sync-upstream.yml', syncWorkflow],
['skills/patchlane-fork-setup/assets/promote-tested-sync.yml', promotionWorkflow],
['skills/patchlane-fork-setup/assets/fork-ci.yml', forkCiWorkflow],
]);

const fileMappings = [
['examples/sync-upstream.yml', 'skills/patchlane-fork-setup/assets/sync-upstream.yml'],
['examples/fork-ci.yml', 'skills/patchlane-fork-setup/assets/fork-ci.yml'],
['examples/promote-tested-sync.yml', 'skills/patchlane-fork-setup/assets/promote-tested-sync.yml'],
];
const stalePaths: string[] = [];
for (const [relativePath, contents] of generatedFiles) {
const filePath = path.join(rootDir, relativePath);
if (existsSync(filePath) && readFileSync(filePath, 'utf8') === contents) continue;
if (check) {
stalePaths.push(relativePath);
} else {
mkdirSync(path.dirname(filePath), { recursive: true });
writeFileSync(filePath, contents);
}
}

const packageLockPath = path.join(rootDir, 'package-lock.json');
const packageLock = JSON.parse(readFileSync(packageLockPath, 'utf8')) as {
version?: unknown;
packages?: { ''?: { version?: unknown } };
};
if (packageLock.version !== packageJson.version || packageLock.packages?.['']?.version !== packageJson.version) {
if (check) {
stalePaths.push('package-lock.json');
} else {
packageLock.version = packageJson.version;
if (!packageLock.packages?.['']) throw new Error('Package lock root package is missing.');
packageLock.packages[''].version = packageJson.version;
writeFileSync(packageLockPath, `${JSON.stringify(packageLock, null, 2)}\n`);
}
}

for (const [sourceRelativePath, destinationRelativePath] of fileMappings) {
const sourcePath = path.join(rootDir, sourceRelativePath);
const destinationPath = path.join(rootDir, destinationRelativePath);
mkdirSync(path.dirname(destinationPath), { recursive: true });
copyFileSync(sourcePath, destinationPath);
if (stalePaths.length) {
throw new Error(`Generated artifacts are stale:\n${stalePaths.map((file) => `- ${file}`).join('\n')}`);
}
4 changes: 1 addition & 3 deletions skills/patchlane-fork-setup/assets/promote-tested-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ jobs:
node-version: '22'

- name: Run patchlane promote
run: npx patchlane@0.4.0 promote
run: npx patchlane@0.4.1 promote
env:
BASE_BRANCH: main
SYNC_BRANCH: sync/integration
EXPECTED_SYNC_SHA: ${{ github.event.workflow_run.head_sha }}
2 changes: 1 addition & 1 deletion skills/patchlane-fork-setup/assets/sync-upstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
node-version: '22'

- name: Run patchlane sync
run: npx patchlane@0.4.0 sync
run: npx patchlane@0.4.1 sync
env:
UPSTREAM_SOURCE: ${{ inputs.source }}
PATCH_REFS: ${{ inputs.patch_refs }}
Expand Down