Add input variables commit and title (#27)

* Add input variables `commit` and `title`

* Update action.yml

Co-authored-by: Mitchell Hamilton <mitchell@hamil.town>
This commit is contained in:
ocavue
2020-04-29 12:29:15 +10:00
committed by GitHub
co-authored by Mitchell Hamilton
parent dfa783e7bc
commit 2eb58c89dc
4 changed files with 24 additions and 15 deletions
+2
View File
@@ -9,6 +9,8 @@ This action for [Changesets](https://github.com/atlassian/changesets) creates a
- publish - The command to use to build and publish packages - publish - The command to use to build and publish packages
- version - The command to update version, edit CHANGELOG, read and delete changesets. Default to `changeset version` if not provided - version - The command to update version, edit CHANGELOG, read and delete changesets. Default to `changeset version` if not provided
- commit - The commit message to use. Default to `Version Packages`
- title - The pull request title. Default to `Version Packages`
### Outputs ### Outputs
+7
View File
@@ -10,6 +10,13 @@ inputs:
version: version:
description: "The command to update version, edit CHANGELOG, read and delete changesets. Default to `changeset version` if not provided" description: "The command to update version, edit CHANGELOG, read and delete changesets. Default to `changeset version` if not provided"
required: false required: false
commit:
description: |
The commit message. Default to `Version Packages`
required: false
title:
description: The pull request title. Default to `Version Packages`
required: false
outputs: outputs:
published: published:
description: A boolean value to indicate whether a publishing is happened or not description: A boolean value to indicate whether a publishing is happened or not
+1 -1
View File
File diff suppressed because one or more lines are too long
+14 -14
View File
@@ -58,16 +58,20 @@ import readChangesets from "@changesets/read";
let hasChangesets = changesets.length !== 0; let hasChangesets = changesets.length !== 0;
let publishScript = core.getInput("publish"); let inputs = {
let versionScript = core.getInput("version"); publishScript: core.getInput("publish"),
versionScript: core.getInput("version"),
commit: core.getInput("commit") || "Version Packages",
prTitle: core.getInput("title") || "Version Packages",
}
core.setOutput('published', 'false'); core.setOutput('published', 'false');
core.setOutput('publishedPackages', '[]'); core.setOutput('publishedPackages', '[]');
if (!hasChangesets && !publishScript) { if (!hasChangesets && !inputs.publishScript) {
console.log("No changesets found"); console.log("No changesets found");
return; return;
} }
if (!hasChangesets && publishScript) { if (!hasChangesets && inputs.publishScript) {
console.log( console.log(
"No changesets found, attempting to publish any unpublished packages to npm" "No changesets found, attempting to publish any unpublished packages to npm"
); );
@@ -86,7 +90,7 @@ import readChangesets from "@changesets/read";
`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}` `//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}`
); );
let [publishCommand, ...publishArgs] = publishScript.split(/\s+/); let [publishCommand, ...publishArgs] = inputs.publishScript.split(/\s+/);
let changesetPublishOutput = await execWithOutput( let changesetPublishOutput = await execWithOutput(
publishCommand, publishCommand,
@@ -176,8 +180,8 @@ import readChangesets from "@changesets/read";
await exec("git", ["reset", "--hard", github.context.sha]); await exec("git", ["reset", "--hard", github.context.sha]);
if (versionScript) { if (inputs.versionScript) {
let [versionCommand, ...versionArgs] = versionScript.split(/\s+/); let [versionCommand, ...versionArgs] = inputs.versionScript.split(/\s+/);
await exec(versionCommand, versionArgs); await exec(versionCommand, versionArgs);
} else { } else {
let changesetsCliPkgJson = await fs.readJson( let changesetsCliPkgJson = await fs.readJson(
@@ -198,7 +202,7 @@ import readChangesets from "@changesets/read";
let prBodyPromise = (async () => { let prBodyPromise = (async () => {
return ( return (
`This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and ${ `This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and ${
publishScript inputs.publishScript
? `the packages will be published to npm automatically` ? `the packages will be published to npm automatically`
: `publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing)` : `publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing)`
}. If you're not ready to do a release yet, that's fine, whenever you add more changesets to ${branch}, this PR will be updated. }. If you're not ready to do a release yet, that's fine, whenever you add more changesets to ${branch}, this PR will be updated.
@@ -244,12 +248,8 @@ ${
); );
})(); })();
const prTitle = `Version Packages${ const prTitle = `${inputs.prTitle}${isInPreMode ? ` (${preState.tag})` : ""}`;
isInPreMode ? ` (${preState.tag})` : "" const commitMsg = `${inputs.commit}${isInPreMode ? ` (${preState.tag})` : ""}`;
}`;
const commitMsg = `ci(changeset): generate PR with changelog &${
isInPreMode ? ` (${preState.tag})` : ""
} version updates`;
await exec("git", ["add", "."]); await exec("git", ["add", "."]);
await exec("git", ["commit", "-m", commitMsg]); await exec("git", ["commit", "-m", commitMsg]);