Skip to content

feat: add preview command to covector #187

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

Merged
merged 30 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
42901a7
Disable workflows and update location of preview action
minkimcello Apr 14, 2021
63bb96e
Specify label and previewVersion inputs for action manifest
minkimcello Apr 14, 2021
540aa65
Add conditional for version bumping for previews
minkimcello Apr 14, 2021
e7fcba9
Add versioning steps for preview command
minkimcello Apr 14, 2021
4236aab
Pass in context and previewVersion into covector from action
minkimcello Apr 14, 2021
e1a2d09
Add publishing steps for preview command
minkimcello Apr 14, 2021
e1a77e9
Run action locally for preview workflow
minkimcello Apr 14, 2021
277f47e
Remove post publish commands from preview
minkimcello Apr 14, 2021
7fb30f1
Double timeout length for preview command
minkimcello Apr 14, 2021
c8eae84
Re-enable the other workflows
minkimcello Apr 14, 2021
e9ed57d
Remove unused argument in apply
minkimcello Apr 15, 2021
6b5e56c
Modify change file to include apply and covector
minkimcello Apr 15, 2021
2db1be9
Add preview label to version PR creator
minkimcello Apr 15, 2021
3d39a5b
Undo doubling timeout for preview
minkimcello Apr 16, 2021
9d951ee
Update invalid template error message
minkimcello Apr 20, 2021
33edeac
Throw error when preview runs on non-pr
minkimcello Apr 20, 2021
670048b
Add action argument for branch identifier
minkimcello Apr 27, 2021
4eb4a25
Change change files to minor bump
minkimcello Apr 28, 2021
4ce8de0
Remove unnecessary argument
minkimcello Apr 28, 2021
8d30081
Fix apply bug for bumpDep
minkimcello Apr 28, 2021
466a77f
Add test for preview apply
minkimcello Apr 28, 2021
af9490e
Add test for preview covector
minkimcello Apr 28, 2021
9a68d1f
Remove obsolete snapshots
minkimcello Apr 28, 2021
7f11f9e
Add console log for preview version bumps
minkimcello Apr 30, 2021
b24a650
Update snapshot
minkimcello May 3, 2021
1423cd0
New fixture for preview
minkimcello May 4, 2021
838380e
New new fixture
minkimcello May 4, 2021
e7cd5ce
Fix rust bug
minkimcello May 4, 2021
ecb1ea6
Make test use new fixture
minkimcello May 4, 2021
a0a3f5f
bug: Fix bumping error (#198)
minkimcello May 5, 2021
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
6 changes: 4 additions & 2 deletions .changes/preview-action-bump.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
"action": patch
"action": minor
"covector": minor
"apply": minor
---

Add 'preview' command for action
Add preview command for versioning and publishing preview packages
2 changes: 1 addition & 1 deletion .github/workflows/run-version-or-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ jobs:
with:
title: "Publish New Versions"
commit-message: "publish new versions"
labels: "version updates"
labels: "version updates, preview"
branch: "release"
body: ${{ steps.covector.outputs.change }}
19 changes: 19 additions & 0 deletions __fixtures__/integration.js-only/.changes/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"pkgManagers": {
"javascript": {
"version": true,
"publish": "echo publishing ${ pkg.pkg } would happen here"
}
},
"packages": {
"package-a": {
"path": "./package-a",
"manager": "javascript",
"dependencies": ["package-b"]
},
"package-b": {
"path": "./package-b",
"manager": "javascript"
}
}
}
5 changes: 5 additions & 0 deletions __fixtures__/integration.js-only/.changes/first-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"package-b": minor
---

Whatever
7 changes: 7 additions & 0 deletions __fixtures__/integration.js-only/package-a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "package-a",
"version": "0.0.1",
"dependencies": {
"package-b": "0.0.1"
}
}
5 changes: 5 additions & 0 deletions __fixtures__/integration.js-only/package-b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "package-b",
"version": "0.0.1",
"dependencies": {}
}
12 changes: 12 additions & 0 deletions packages/action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ inputs:
description: A comma separated list (no spaces) of packages to run commands on rather than everything listed in the config.
required: false
default: ""
label:
description: "the Github pull request label that triggers preview packages"
required: false
default: preview
previewVersion:
description: Template for how the preview packages should be versioned
required: false
default: date
identifier:
description: Identifier for prerelease version template
required: false
default: branch
outputs:
change:
description: The changes that were applied
Expand Down
2 changes: 1 addition & 1 deletion packages/action/dist/index.js

Large diffs are not rendered by default.

90 changes: 55 additions & 35 deletions packages/action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,45 +105,65 @@ export function* run(): Generator<any, any, any> {
return covectored;
}
} else if (command === "preview") {
const previewLabel = github?.context?.payload?.pull_request?.labels?.filter(({ name } : { name: String }) => name === 'preview').length;
const configuredLabel = core.getInput("label");
const previewLabel = github?.context?.payload?.pull_request?.labels?.filter(({ 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.`);
}

if (!previewLabel) {
console.log('Not publishing any preview packages because the "preview" label has not been applied to this pull request.')
console.log(`Not publishing any preview packages because the "${configuredLabel}" label has not been applied to this pull request.`);
} else {
let covectored: Covector;
// if (core.getInput("createRelease") === "true" && token) {
// const octokit = github.getOctokit(token);
// const { owner, repo } = github.context.repo;
// covectored = yield covector({
// command,
// filterPackages,
// cwd,
// modifyConfig: injectPublishFunctions([
// createReleases({ core, octokit, owner, repo }),
// ]),
// });
// } else {
covectored = yield covector({
command,
filterPackages,
cwd,
});
// }
const branchName = github?.context?.payload?.pull_request?.head?.ref;
let identifier;
let versionTemplate;

switch(versionIdentifier){
case "branch":
identifier = branchName.replace(/\_/g, '-').replace(/\//g, '-');
break;
default:
throw new Error(`Version identifier you specified, "${versionIdentifier}", is invalid.`)
}

// if (covectored) {
// let packagesPublished = Object.keys(covectored).reduce((pub, pkg) => {
// if (!covectored[pkg].published) {
// return pub;
// } else {
// return `${pub}${pkg}`;
// }
// }, "");
// core.setOutput("packagesPublished", packagesPublished);
// for (let pkg of Object.keys(covectored)) {
// if (covectored[pkg].command !== false) successfulPublish = true;
// }
// core.setOutput("successfulPublish", successfulPublish);
// core.setOutput("change", covectored);
// }
switch(previewVersion){
case "date":
versionTemplate = `${identifier}.${Date.now()}`;
break;
case "sha":
versionTemplate = `${identifier}.${github.context.payload.after.substring(0, 7)}`;
break;
default:
throw new Error(`Preview version template you specified, "${previewVersion}", is invalid. Please use 'date' or 'sha'.`)
};

covectored = yield covector({
command,
filterPackages,
cwd,
// context: github.context.payload,
previewVersion: versionTemplate
});

if (covectored) {
let packagesPublished = Object.keys(covectored).reduce((pub, pkg) => {
if (!covectored[pkg].published) {
return pub;
} else {
return `${pub}${pkg}`;
}
}, "");
core.setOutput("packagesPublished", packagesPublished);
for (let pkg of Object.keys(covectored)) {
if (covectored[pkg].command !== false) successfulPublish = true;
}
core.setOutput("successfulPublish", successfulPublish);
core.setOutput("change", covectored);
}
}
} else {
throw new Error(`Command "${command}" not recognized. See README for which commands are available.`);
Expand Down
59 changes: 42 additions & 17 deletions packages/apply/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,17 @@ Object {
}
`;

exports[`package file apply bump bumps multi js json 1`] = `
exports[`package file apply bump (async/await) bumps multi rust toml as minor with object dep without version number 1`] = `
Object {
"consoleError": Array [
Array [
"It appears that a dependency within this repo does not have a version specified.",
],
],
}
`;

exports[`package file apply bump (snapshot) bumps multi js json 1`] = `
Object {
"consoleDir": Array [],
"consoleLog": Array [
Expand All @@ -259,7 +269,7 @@ Object {
}
`;

exports[`package file apply bump bumps multi rust toml 1`] = `
exports[`package file apply bump (snapshot) bumps multi rust toml 1`] = `
Object {
"consoleDir": Array [],
"consoleLog": Array [
Expand All @@ -273,7 +283,7 @@ Object {
}
`;

exports[`package file apply bump bumps multi rust toml as minor with object dep missing patch 1`] = `
exports[`package file apply bump (snapshot) bumps multi rust toml as minor with object dep missing patch 1`] = `
Object {
"consoleDir": Array [],
"consoleLog": Array [
Expand All @@ -287,31 +297,35 @@ Object {
}
`;

exports[`package file apply bump bumps multi rust toml as minor with object dep without version number 1`] = `
exports[`package file apply bump (snapshot) bumps multi rust toml as patch with object dep missing patch 1`] = `
Object {
"consoleError": Array [
"consoleDir": Array [],
"consoleLog": Array [
Array [
"It appears that a dependency within this repo does not have a version specified.",
"bumping rust_pkg_a_fixture with patch",
],
Array [
"bumping rust_pkg_b_fixture with patch",
],
],
}
`;

exports[`package file apply bump bumps multi rust toml as patch with object dep missing patch 1`] = `
exports[`package file apply bump (snapshot) bumps multi rust toml with dep missing patch 1`] = `
Object {
"consoleDir": Array [],
"consoleLog": Array [
Array [
"bumping rust_pkg_a_fixture with patch",
"bumping rust_pkg_a_fixture with minor",
],
Array [
"bumping rust_pkg_b_fixture with patch",
"bumping rust_pkg_b_fixture with minor",
],
],
}
`;

exports[`package file apply bump bumps multi rust toml with dep missing patch 1`] = `
exports[`package file apply bump (snapshot) bumps multi rust toml with object dep 1`] = `
Object {
"consoleDir": Array [],
"consoleLog": Array [
Expand All @@ -325,37 +339,48 @@ Object {
}
`;

exports[`package file apply bump bumps multi rust toml with object dep 1`] = `
exports[`package file apply bump (snapshot) bumps single js json 1`] = `
Object {
"consoleDir": Array [],
"consoleLog": Array [
Array [
"bumping rust_pkg_a_fixture with minor",
"bumping js-single-json-fixture with minor",
],
],
}
`;

exports[`package file apply bump (snapshot) bumps single rust toml 1`] = `
Object {
"consoleDir": Array [],
"consoleLog": Array [
Array [
"bumping rust_pkg_b_fixture with minor",
"bumping rust-single-fixture with minor",
],
],
}
`;

exports[`package file apply bump bumps single js json 1`] = `
exports[`packge file applies preview bump bumps multi js json 1`] = `
Object {
"consoleDir": Array [],
"consoleLog": Array [
Array [
"bumping js-single-json-fixture with minor",
"bumping yarn-workspace-base-pkg-a to 1.0.0-branch-name.12345 to publish a preview",
],
Array [
"bumping yarn-workspace-base-pkg-b to 1.0.0-branch-name.12345 to publish a preview",
],
],
}
`;

exports[`package file apply bump bumps single rust toml 1`] = `
exports[`packge file applies preview bump bumps single js json 1`] = `
Object {
"consoleDir": Array [],
"consoleLog": Array [
Array [
"bumping rust-single-fixture with minor",
"bumping js-single-json-fixture to 0.5.9-branch-name.12345 to publish a preview",
],
],
}
Expand Down
Loading