Skip to content
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

chore: add option to provide fixed release name and changelog path #6

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ inputs:
description: "A boolean value to indicate whether to create Github releases after `publish` or not"
required: false
default: true
releaseVersion:
description: Use this if you want to provide a static release version
required: false
changelogPath:
description: The path of where the changelog file will be created
required: false
outputs:
published:
description: A boolean value to indicate whether a publishing is happened or not
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@changesets/action",
"version": "2.1.0",
"version": "2.2.0",
"main": "dist/index.js",
"license": "MIT",
"devDependencies": {
Expand Down
41 changes: 3 additions & 38 deletions src/__snapshots__/run.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,7 @@ exports[`version creates simple PR 1`] = `
Array [
Object {
"base": "some-branch",
"body": "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 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 some-branch, this PR will be updated.

# Releases
## [email protected]

### Minor Changes

- Awesome feature

### Patch Changes

- Updated dependencies
- [email protected]

## [email protected]

### Minor Changes

- Awesome feature
",
"body": "See [docs/releases/vundefined-changelog.md](https://github.com/backstage/backstage/blob/master/docs/releases/vundefined-changelog.md) for more information.",
"head": "changeset-release/some-branch",
"owner": "changesets",
"repo": "action",
Expand All @@ -36,15 +17,7 @@ exports[`version doesn't include ignored package that got a dependency update in
Array [
Object {
"base": "some-branch",
"body": "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 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 some-branch, this PR will be updated.

# Releases
## [email protected]

### Minor Changes

- Awesome feature
",
"body": "See [docs/releases/vundefined-changelog.md](https://github.com/backstage/backstage/blob/master/docs/releases/vundefined-changelog.md) for more information.",
"head": "changeset-release/some-branch",
"owner": "changesets",
"repo": "action",
Expand All @@ -57,15 +30,7 @@ exports[`version only includes bumped packages in the PR body 1`] = `
Array [
Object {
"base": "some-branch",
"body": "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 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 some-branch, this PR will be updated.

# Releases
## [email protected]

### Minor Changes

- Awesome feature
",
"body": "See [docs/releases/vundefined-changelog.md](https://github.com/backstage/backstage/blob/master/docs/releases/vundefined-changelog.md) for more information.",
"head": "changeset-release/some-branch",
"owner": "changesets",
"repo": "action",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
githubToken,
prTitle: getOptionalInput("title"),
commitMessage: getOptionalInput("commit"),
releaseVersion: getOptionalInput("releaseVersion"),
changelogPath: getOptionalInput("changelogPath"),
hasPublishScript,
});

Expand Down
18 changes: 12 additions & 6 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ type VersionOptions = {
prTitle?: string;
commitMessage?: string;
hasPublishScript?: boolean;
changelogPath?: string;
releaseVersion?: string;
};

type RunVersionResult = {
Expand All @@ -185,9 +187,11 @@ export async function runVersion({
script,
githubToken,
cwd = process.cwd(),
releaseVersion,
prTitle = "Version Packages",
commitMessage = "Version Packages",
hasPublishScript = false,
changelogPath = "docs/releases",
}: VersionOptions): Promise<RunVersionResult> {
let repo = `${github.context.repo.owner}/${github.context.repo.repo}`;
let branch = github.context.ref.replace("refs/heads/", "");
Expand Down Expand Up @@ -219,9 +223,10 @@ export async function runVersion({
});
let changedPackages = await getChangedPackages(cwd, versionsByDirectory);

const { version: releaseVersion } = await fs.readJson(
const { version: versionFromPackageJson } = await fs.readJson(
path.resolve(cwd, "package.json")
);
const toUseReleaseVersion = releaseVersion || versionFromPackageJson;

const changelogEntries = await Promise.all(
changedPackages.map(async (pkg) => {
Expand All @@ -241,9 +246,9 @@ export async function runVersion({
})
);
let changelogBody = `
# Release v${releaseVersion}
# Release v${toUseReleaseVersion}

Upgrade Helper: [https://backstage.github.io/upgrade-helper/?to=${releaseVersion}](https://backstage.github.io/upgrade-helper/?to=${releaseVersion})
Upgrade Helper: [https://backstage.github.io/upgrade-helper/?to=${toUseReleaseVersion}](https://backstage.github.io/upgrade-helper/?to=${toUseReleaseVersion})

${changelogEntries
.filter((x) => x)
Expand All @@ -252,7 +257,8 @@ ${changelogEntries
.join("\n")}
`;

const changelogPath = `docs/releases/v${releaseVersion}-changelog.md`;
const file = `v${releaseVersion}-changelog.md`;
const fullChangelogPath = `${changelogPath}/${file}`;

try {
const prettier = require(resolveFrom(cwd, "prettier"));
Expand All @@ -263,9 +269,9 @@ ${changelogEntries
});
} catch {}

await fs.writeFile(changelogPath, changelogBody);
await fs.writeFile(fullChangelogPath, changelogBody);

const prBody = `See [${changelogPath}](https://github.com/backstage/backstage/blob/master/${changelogPath}) for more information.`;
const prBody = `See [${fullChangelogPath}](https://github.com/backstage/backstage/blob/master/${fullChangelogPath}) for more information.`;

const finalPrTitle = `${prTitle}${!!preState ? ` (${preState.tag})` : ""}`;

Expand Down