Skip to content

chore(ci): update cts and playground dependencies on release #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
41 changes: 41 additions & 0 deletions scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
CheckForCacheOptions,
Generator,
RunOptions,
PackageLocationMap,
} from './types';

export const MAIN_BRANCH = config.mainBranch;
Expand Down Expand Up @@ -280,3 +281,43 @@ export async function emptyDirExceptForDotGit(dir: string): Promise<void> {
}
}
}

export async function readPackageJson(dir: string): Promise<any> {
const filePath = toAbsolutePath(`${dir}/package.json`);
return JSON.parse((await fsp.readFile(filePath)).toString());
}

export async function getPackageLocationMap(): Promise<PackageLocationMap> {
return (await run(`yarn workspaces list --json`))
.split('\n')
.reduce((acc, item) => {
const { name, location } = JSON.parse(item);
return {
...acc,
[name]: location,
};
}, {});
}

export async function updateDependenciesToLocalVersions(
packageDir: string
): Promise<void> {
const packageLocationMap = getPackageLocationMap();

const targetPackageJson = await readPackageJson(packageDir);
for (const packageName of targetPackageJson.dependencies) {
if (!packageLocationMap[packageName]) {
// Skip if it's not a local package.
continue;
}

targetPackageJson.dependencies[packageName] = (
await readPackageJson(packageLocationMap[packageName])
).version;
}

await fsp.writeFile(
toAbsolutePath(`${packageDir}/package.json`),
`${JSON.stringify(targetPackageJson)}\n`
);
}
5 changes: 5 additions & 0 deletions scripts/release/process-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import openapitools from '../../openapitools.json';
import {
ROOT_ENV_PATH,
toAbsolutePath,
updateDependenciesToLocalVersions,
run,
exists,
getGitHubUrl,
Expand Down Expand Up @@ -44,6 +45,10 @@ const BEFORE_CLIENT_GENERATION: {
} = {
javascript: async ({ releaseType, dir }) => {
await run(`yarn release:bump ${releaseType}`, { cwd: dir });

await updateDependenciesToLocalVersions('tests/output/javascript');
await updateDependenciesToLocalVersions('playground/javascript/browser');
await updateDependenciesToLocalVersions('playground/javascript/node');
},
};

Expand Down
4 changes: 4 additions & 0 deletions scripts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export type Spec = {
paths: Path[];
};

export type PackageLocationMap = {
[packageName: string]: string;
};

/**
* Server of a spec.
*/
Expand Down