Skip to content

Commit

Permalink
bump js-yaml and semver (#291)
Browse files Browse the repository at this point in the history
* bump js-yaml and semver for latest

* run prettier v3
  • Loading branch information
jbolda authored Jul 26, 2023
1 parent 7498ecc commit cb35f38
Show file tree
Hide file tree
Showing 48 changed files with 1,332 additions and 607 deletions.
5 changes: 5 additions & 0 deletions .changes/js-yaml-4.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@covector/files": patch:deps
---

Bumps `js-yaml` minor to sync on the same version.
6 changes: 6 additions & 0 deletions .changes/semver-7.5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@covector/files": patch:deps
"@covector/apply": patch:deps
---

Bumps `semver` minor to latest.
6 changes: 3 additions & 3 deletions .changes/zod-config-file.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
"@covector/assemble": patch
"@covector/files": minor
"@covector/types": minor
"@covector/assemble": patch:enhance
"@covector/files": minor:enhance
"@covector/types": minor:enhance
---

Implement zod for config file schema parsing and checking. It will throw an error if the `config.json` has entries that do not match the schema.
1,230 changes: 966 additions & 264 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"packages/*"
],
"devDependencies": {
"@effection/jest": "^2.0.4",
"@effection/jest": "^2.0.5",
"@types/jest": "^27.4.1",
"@types/node": "^16.18.12",
"jest": "^27.5.1",
"jest-mock-console": "^1.2.3",
"prettier": "^2.6.2",
"prettier": "^3.0.0",
"rimraf": "^3.0.2",
"ts-jest": "^27.1.4"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"effection": "^2.0.6"
},
"devDependencies": {
"@covector/types": "^0.0.0",
"@covector/types": "0.0.0",
"@vercel/ncc": "^0.36.1",
"fixturez": "^1.1.0",
"tslib": "^2.5.0",
Expand Down
40 changes: 20 additions & 20 deletions packages/action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function* run(): Generator<any, any, any> {
core.setOutput(
`willPublish`,
covectored.response === "No changes." &&
covectored.pkgReadyToPublish.length > 0
covectored.pkgReadyToPublish.length > 0,
);
if (covectored?.pkgReadyToPublish?.length > 0) {
covectored.pkgReadyToPublish.forEach((pkg) => {
Expand All @@ -66,14 +66,14 @@ export function* run(): Generator<any, any, any> {
.replace(/\@/g, "-")
.replace(/\//g, "-")
.replace(/\_/g, "-"),
true
true,
);
core.setOutput(
`version-${pkg.pkg}`
.replace(/\@/g, "-")
.replace(/\//g, "-")
.replace(/\_/g, "-"),
pkg?.pkgFile?.version ?? ""
pkg?.pkgFile?.version ?? "",
);
});
}
Expand All @@ -92,12 +92,12 @@ export function* run(): Generator<any, any, any> {
(text, pkg) => {
if (typeof covectored.commandsRan[pkg].command === "string") {
text = `${text}\n\n\n# ${pkg}\n\n${commandText(
covectored.commandsRan[pkg]
covectored.commandsRan[pkg],
)}`;
}
return text;
},
"# Version Updates\n\nMerging this PR will release new versions of the following packages based on your change files.\n\n"
"# Version Updates\n\nMerging this PR will release new versions of the following packages based on your change files.\n\n",
);
core.setOutput("change", covectoredSmushed);
const payload = JSON.stringify(covectoredSmushed, undefined, 2);
Expand All @@ -112,7 +112,7 @@ export function* run(): Generator<any, any, any> {
core.debug(
`createRelease is ${core.getInput("createRelease")} ${
token ? "with" : "without"
} a token.`
} a token.`,
);
if (core.getInput("createRelease") === "true" && token) {
const octokit = github.getOctokit(token);
Expand Down Expand Up @@ -149,7 +149,7 @@ export function* run(): Generator<any, any, any> {
return pub === "" ? pkg : `${pub},${pkg}`;
}
},
""
"",
);
core.setOutput("packagesPublished", packagesPublished);
core.setOutput("templatePipe", JSON.stringify(covectored.pipeTemplate));
Expand All @@ -172,26 +172,26 @@ export function* run(): Generator<any, any, any> {
const configuredLabel = core.getInput("label");
const previewLabel =
github?.context?.payload?.pull_request?.labels?.filter(
({ name }: { name: String }) => name === configuredLabel
({ name }: { name: String }) => name === configuredLabel,
).length;
const previewVersion = core.getInput("previewVersion");
const versionIdentifier = core.getInput("identifier");

if (github.context.eventName !== "pull_request") {
throw new Error(
`The 'preview' command for the covector action is only meant to run on pull requests.`
`The 'preview' command for the covector action is only meant to run on pull requests.`,
);
}

if (github.context.eventName !== "pull_request") {
throw new Error(
`The 'preview' command for the covector action is only meant to run on pull requests.`
`The 'preview' command for the covector action is only meant to run on pull requests.`,
);
}

if (!previewLabel) {
console.log(
`Not publishing any preview packages because the "${configuredLabel}" label has not been applied to this pull request.`
`Not publishing any preview packages because the "${configuredLabel}" label has not been applied to this pull request.`,
);
} else {
// primarily runs publish
Expand All @@ -205,7 +205,7 @@ export function* run(): Generator<any, any, any> {

if (branchName === "latest") {
throw new Error(
`Using the branch name, 'latest', will conflict with restricted tags when publishing packages. Please create another pull request with a different branch name.`
`Using the branch name, 'latest', will conflict with restricted tags when publishing packages. Please create another pull request with a different branch name.`,
);
}

Expand All @@ -215,7 +215,7 @@ export function* run(): Generator<any, any, any> {
break;
default:
throw new Error(
`Version identifier you specified, "${versionIdentifier}", is invalid.`
`Version identifier you specified, "${versionIdentifier}", is invalid.`,
);
}

Expand All @@ -226,12 +226,12 @@ export function* run(): Generator<any, any, any> {
case "sha":
versionTemplate = `${identifier}.${github.context.payload.after.substring(
0,
7
7,
)}`;
break;
default:
throw new Error(
`Preview version template you specified, "${previewVersion}", is invalid. Please use 'date' or 'sha'.`
`Preview version template you specified, "${previewVersion}", is invalid. Please use 'date' or 'sha'.`,
);
}

Expand All @@ -245,7 +245,7 @@ export function* run(): Generator<any, any, any> {

if (covectored.commandsRan) {
let packagesPublished: any = Object.entries(
covectored.commandsRan
covectored.commandsRan,
).reduce((pub: string[], pkg: any[]) => {
if (pkg[1].published) {
let { name: pkgName, version: pkgVersion }: any =
Expand Down Expand Up @@ -273,7 +273,7 @@ export function* run(): Generator<any, any, any> {
});

const covectorComments = data.filter((comment: any) =>
comment.body.includes("<!-- covector comment -->")
comment.body.includes("<!-- covector comment -->"),
);

let prComment = () => {
Expand All @@ -285,7 +285,7 @@ export function* run(): Generator<any, any, any> {
(result: string, publishedPackage: string) => {
return `${result}- \`${publishedPackage}\`\n`;
},
""
"",
);
} else {
commentHead = "Covector did not publish any preview packages.";
Expand All @@ -311,7 +311,7 @@ export function* run(): Generator<any, any, any> {
}
} else {
throw new Error(
`Github token argument in preview workflow is missing but it is required in order to generate comments on pull requests.`
`Github token argument in preview workflow is missing but it is required in order to generate comments on pull requests.`,
);
}

Expand All @@ -327,7 +327,7 @@ export function* run(): Generator<any, any, any> {
}
} else {
throw new Error(
`Command "${command}" not recognized. See README for which commands are available.`
`Command "${command}" not recognized. See README for which commands are available.`,
);
}
} catch (error: any) {
Expand Down
26 changes: 13 additions & 13 deletions packages/action/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ export const injectPublishFunctions = curry(
if (!config) return config;
if (!Array.isArray(functionsToInject))
throw new Error(
"injectPublishFunctions() in modifyConfig() expects an array"
"injectPublishFunctions() in modifyConfig() expects an array",
);
return {
...config,
pkgManagers: injectIntoPublish(config.pkgManagers, functionsToInject),
packages: injectIntoPublish(config.packages, functionsToInject),
};
}
},
);

const injectIntoPublish = (
packages: { [k: string]: object } | undefined,
functionsToInject: Function[]
functionsToInject: Function[],
) => {
if (!packages) return {};
return Object.keys(packages).reduce((finalConfig, pkg) => {
Expand All @@ -64,7 +64,7 @@ const injectIntoPublish = (
}
return pm;
},
packages![pkg] || {}
packages![pkg] || {},
);

return finalConfig;
Expand Down Expand Up @@ -98,18 +98,18 @@ export const createReleases = curry(
repo: string;
targetCommitish: string;
},
pipe: FunctionPipe
pipe: FunctionPipe,
): Promise<void> => {
if (!pipe.pkgFile) {
console.log(
`skipping Github Release for ${pipe.pkg}, no package file present`
`skipping Github Release for ${pipe.pkg}, no package file present`,
);
return;
}

if (!pipe.releaseTag) {
console.log(
`skipping Github Release for ${pipe.pkg}, releaseTag is null`
`skipping Github Release for ${pipe.pkg}, releaseTag is null`,
);
return;
}
Expand All @@ -123,7 +123,7 @@ export const createReleases = curry(
})
.then((releases) => {
const release = releases.data.find(
(r) => r.draft && r.tag_name === releaseTag
(r) => r.draft && r.tag_name === releaseTag,
);
return release ? release : null;
})
Expand All @@ -132,7 +132,7 @@ export const createReleases = curry(
let releaseResponse;
if (existingRelease && existingRelease.draft) {
console.log(
`updating and publishing Github Release for ${pipe.pkg}@${pipe.pkgFile.version}`
`updating and publishing Github Release for ${pipe.pkg}@${pipe.pkgFile.version}`,
);
releaseResponse = await octokit.rest.repos
.updateRelease({
Expand All @@ -147,7 +147,7 @@ export const createReleases = curry(
.then((response) => response.data);
} else {
console.log(
`creating Github Release for ${pipe.pkg}@${pipe.pkgFile.version}`
`creating Github Release for ${pipe.pkg}@${pipe.pkgFile.version}`,
);
releaseResponse = await octokit.rest.repos
.createRelease({
Expand Down Expand Up @@ -179,7 +179,7 @@ export const createReleases = curry(
core.setOutput(`${cleanPipePkg}-releaseUrl`, releaseResponse.url);
core.setOutput(
`${cleanPipePkg}-releaseUploadUrl`,
releaseResponse.upload_url
releaseResponse.upload_url,
);
core.setOutput(`${cleanPipePkg}-releaseId`, releaseResponse.id);

Expand All @@ -192,7 +192,7 @@ export const createReleases = curry(
try {
for (let asset of pipe.assets) {
console.log(
`uploading asset ${asset.name} for ${pipe.pkg}@${pipe.pkgFile.version}`
`uploading asset ${asset.name} for ${pipe.pkg}@${pipe.pkgFile.version}`,
);
const uploadedAsset = await octokit.rest.repos
.uploadReleaseAsset({
Expand All @@ -215,5 +215,5 @@ export const createReleases = curry(
console.error(error);
}
}
}
},
);
Loading

0 comments on commit cb35f38

Please sign in to comment.