feat: integrate client and server sharing workflows
This commit is contained in:
1 parent
42b93ae2d8
commit
7406e2fe37
101 files changed
+3153
-253
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
const read = (path) => readFileSync(new URL(`../${path}`, import.meta.url), 'utf8');
|
||||
const semver = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
||||
const contract = JSON.parse(read('contracts/api-contract.json'));
|
||||
const fail = (message) => {
|
||||
console.error(`API contract check failed: ${message}`);
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
if (typeof contract.version !== 'string' || !semver.test(contract.version)) {
|
||||
fail('contracts/api-contract.json must contain a SemVer version.');
|
||||
}
|
||||
|
||||
const apiMajor = Number(contract.version.split('.')[0]);
|
||||
const openapi = read('docs/openapi.yaml');
|
||||
const openapiVersion = /^info:\s*\r?\n(?:.*\r?\n)*?\s+version:\s*([^\s#]+)/m.exec(openapi)?.[1];
|
||||
if (openapiVersion !== contract.version) fail(`OpenAPI version ${openapiVersion ?? '(missing)'} differs from ${contract.version}.`);
|
||||
|
||||
const backend = read('server/src/WebDrop.Api/ApiContract.cs');
|
||||
const backendVersion = /const string Version = "([^"]+)"/.exec(backend)?.[1];
|
||||
if (backendVersion !== contract.version) fail(`backend version ${backendVersion ?? '(missing)'} differs from ${contract.version}.`);
|
||||
|
||||
const frontend = read('web/src/core-bridge/contract.ts');
|
||||
const supportedMajor = Number(/SUPPORTED_API_CONTRACT_MAJOR\s*=\s*(\d+)/.exec(frontend)?.[1]);
|
||||
if (supportedMajor !== apiMajor) {
|
||||
fail(`backend contract is ${contract.version}; frontend still supports API major ${supportedMajor || '(missing)'}. Update web/src/core-bridge/contract.ts.`);
|
||||
}
|
||||
|
||||
const tag = process.argv[2];
|
||||
if (tag !== undefined) {
|
||||
if (!tag.startsWith('v')) fail(`release tag ${tag} must start with v.`);
|
||||
const releaseVersion = tag.slice(1);
|
||||
if (!semver.test(releaseVersion) || releaseVersion.includes('+')) {
|
||||
fail(`release tag ${tag} must be a SemVer version usable as an OCI image tag (expected vMAJOR.MINOR.PATCH[-prerelease]).`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`API contract ${contract.version}: backend, OpenAPI, and frontend major ${supportedMajor} agree.`);
|
||||
Reference in new issue
Block a user