Skip to content

Commit

Permalink
Make publish config optional
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Oct 13, 2024
1 parent 50750fa commit ac76f06
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-garlics-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/action": minor
---

Make publish config optional
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ This action for [Changesets](https://github.com/atlassian/changesets) creates a

### Inputs

- 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
- commit - The commit message to use. Default to `Version Packages`
- title - The pull request title. Default to `Version Packages`
- setupGitUser - Sets up the git user for commits as `"github-actions[bot]"`. Default to `true`
- createGithubReleases - A boolean value to indicate whether to create Github releases after `publish` or not. Default to `true`
- cwd - Changes node's `process.cwd()` if the project is not located on the root. Default to `process.cwd()`
- publish - The command to use to build and publish packages. Defaults to `changeset publish`
- version - The command to update version, edit CHANGELOG, read and delete changesets. Defaults to `changeset version`
- commit - The commit message to use. Defaults to `Version Packages`
- title - The pull request title. Defaults to `Version Packages`
- setupGitUser - Sets up the git user for commits as `"github-actions[bot]"`. Defaults to `true`
- createGithubReleases - A boolean value to indicate whether to create Github releases after `publish` or not. Defaults to `true`
- cwd - Changes node's `process.cwd()` if the project is not located on the root. Defaults to `process.cwd()`

### Outputs

Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
id: changesets
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
# You can optionally specify a script called release which does a build of your packages and calls changeset publish
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
9 changes: 2 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,18 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;

let { changesets } = await readChangesetState();

let publishScript = core.getInput("publish");
let publishScript = core.getInput("publish") || 'changeset publish';
let hasChangesets = changesets.length !== 0;
const hasNonEmptyChangesets = changesets.some(
(changeset) => changeset.releases.length > 0
);
let hasPublishScript = !!publishScript;

core.setOutput("published", "false");
core.setOutput("publishedPackages", "[]");
core.setOutput("hasChangesets", String(hasChangesets));

switch (true) {
case !hasChangesets && !hasPublishScript:
core.info("No changesets found");
return;
case !hasChangesets && hasPublishScript: {
case !hasChangesets: {
core.info(
"No changesets found, attempting to publish any unpublished packages to npm"
);
Expand Down Expand Up @@ -108,7 +104,6 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
githubToken,
prTitle: getOptionalInput("title"),
commitMessage: getOptionalInput("commit"),
hasPublishScript,
branch: getOptionalInput("branch"),
});

Expand Down
11 changes: 2 additions & 9 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ const requireChangesetsCliPkgJson = (cwd: string) => {
};

type GetMessageOptions = {
hasPublishScript: boolean;
branch: string;
changedPackagesInfo: {
highestLevel: number;
Expand All @@ -235,19 +234,13 @@ type GetMessageOptions = {
preState?: PreState;
};

export async function getVersionPrBody({
hasPublishScript,
async function getVersionPrBody({
preState,
changedPackagesInfo,
prBodyMaxCharacters,
branch,
}: GetMessageOptions) {
let messageHeader = `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 ${
hasPublishScript
? `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)`
}. 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.
`;
let messageHeader = `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 the packages will be published to npm automatically. 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.`;
let messagePrestate = !!preState
? `⚠️⚠️⚠️⚠️⚠️⚠️
Expand Down

0 comments on commit ac76f06

Please sign in to comment.