Skip to content

Commit

Permalink
feat(prepare): remove merge on opened PR by default (#215)
Browse files Browse the repository at this point in the history
* feat(prepare): remove merge on opened PR by default

* docs(main): add `keep-branch-updated` input to README

* build(main): update build
  • Loading branch information
benjamin-guibert authored Apr 7, 2024
1 parent 24fab39 commit 4f5cd88
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 59 deletions.
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,20 @@ permissions:

### Inputs

| Name | Description | Default Value |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
| `release-as` | Force a specific version. | |
| `pre-release` | Name of the pre-release version (`alpha`, `beta`, `rc`...). If not empty, will trigger a pre-release. | |
| `labels-ignore`\* | Labels for pull requests to be ignored for the release bump. It should be added to changelog excluded labels (see #usage). | `ignore` |
| `labels-patch`\* | Labels for pull requests to bump a patch version. | `patch`, `fix` |
| `labels-minor`\* | Labels for pull requests to bump a minor version. | `minor`, `feature` |
| `labels-major`\* | Labels for pull requests to bump a major version. | `major`, `breaking` |
| `label-ready` | Label automatically used by Release Action for release PRs. | `release: ready` |
| `label-done` | Label automatically used by Release Action for release PRs that have been processed (current version released). | `release: done` |
| `branch-production` | Branch used for production, the base for all PRs going to production. | `main` |
| `branch-release` | Branch used for release PRs. | `releases/next` |
| `skip-pr-creation` | Skip release PR creation. When there are changes, if the PR exists, it will still be updated. if the PR doesn't exist but the release branch does, the later will still be updated as well. | `false` |
| Name | Description | Default Value |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
| `release-as` | Force a specific version. | |
| `pre-release` | Name of the pre-release version (`alpha`, `beta`, `rc`...). If not empty, will trigger a pre-release. | |
| `labels-ignore`\* | Labels for pull requests to be ignored for the release bump. It should be added to changelog excluded labels (see #usage). | `ignore` |
| `labels-patch`\* | Labels for pull requests to bump a patch version. | `patch`, `fix` |
| `labels-minor`\* | Labels for pull requests to bump a minor version. | `minor`, `feature` |
| `labels-major`\* | Labels for pull requests to bump a major version. | `major`, `breaking` |
| `label-ready` | Label automatically used by Release Action for release PRs. | `release: ready` |
| `label-done` | Label automatically used by Release Action for release PRs that have been processed (current version released). | `release: done` |
| `branch-production` | Branch used for production, the base for all PRs going to production. | `main` |
| `branch-release` | Branch used for release PRs. | `releases/next` |
| `skip-pr-creation` | Skip release PR creation. When there are changes, if the PR exists, it will still be updated. if the PR doesn't exist but the release branch does, the later will still be updated as well. | `false` |
| `keep-branch-updated` | Keep the release branch merged from main when the PR exists. | `false` |

\*Multiple labels can be defined using a multiline block such as follow:

Expand Down Expand Up @@ -291,7 +292,7 @@ jobs:
uses: ./.github/workflows/publish.yml
```

Only create release PRs when manually triggered:
Only create release PRs and merge `main` into existing release PR when manually triggered:

```yaml
name: Release
Expand All @@ -316,6 +317,7 @@ jobs:
uses: cyberspace7/release-action@v0.7.0
with:
skip-pr-creation: ${{ github.event_name == 'workflow_dispatch' }}
keep-branch-updated: ${{ github.event_name == 'workflow_dispatch' }}
```

## Contributing
Expand All @@ -328,6 +330,8 @@ If it concerns a security vulnerability, please email us at `contact@a60.dev`.

For contributing, please check the [Contributing Guidelines](.github/CONTRIBUTING.md).

---

## Authors

- [**Benjamin Guibert**](https://github.com/benjamin-guibert) – main author and contributor.
Expand Down
92 changes: 52 additions & 40 deletions __tests__/prepare.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,14 +686,7 @@ describe("main()", () => {
expect(octokit.rest.repos.generateReleaseNotes).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.getBranch).toHaveBeenCalledTimes(0);
expect(octokit.rest.git.createRef).toHaveBeenCalledTimes(0);
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.merge).toHaveBeenCalledWith({
owner: "owner",
repo: "repository",
base: "releases/next",
head: "main",
commit_message: 'chore(main): merge "main"',
});
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(0);
expect(fileSystem.readFileSync).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.getContent).toHaveBeenCalledTimes(0);
expect(
Expand Down Expand Up @@ -760,14 +753,7 @@ describe("main()", () => {
expect(octokit.rest.repos.generateReleaseNotes).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.getBranch).toHaveBeenCalledTimes(0);
expect(octokit.rest.git.createRef).toHaveBeenCalledTimes(0);
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.merge).toHaveBeenCalledWith({
owner: "owner",
repo: "repository",
base: "releases/next",
head: "main",
commit_message: 'chore(main): merge "main"',
});
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(0);
expect(fileSystem.readFileSync).toHaveBeenCalledTimes(2);
expect(fileSystem.readFileSync).toHaveBeenNthCalledWith(
2,
Expand Down Expand Up @@ -844,14 +830,7 @@ describe("main()", () => {
expect(octokit.rest.repos.generateReleaseNotes).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.getBranch).toHaveBeenCalledTimes(0);
expect(octokit.rest.git.createRef).toHaveBeenCalledTimes(0);
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.merge).toHaveBeenCalledWith({
owner: "owner",
repo: "repository",
base: "releases/next",
head: "main",
commit_message: 'chore(main): merge "main"',
});
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(0);
expect(fileSystem.readFileSync).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.getContent).toHaveBeenCalledTimes(0);
expect(
Expand Down Expand Up @@ -911,14 +890,7 @@ describe("main()", () => {
expect(octokit.rest.repos.generateReleaseNotes).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.getBranch).toHaveBeenCalledTimes(0);
expect(octokit.rest.git.createRef).toHaveBeenCalledTimes(0);
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.merge).toHaveBeenCalledWith({
owner: "owner",
repo: "repository",
base: "releases/next",
head: "main",
commit_message: 'chore(main): merge "main"',
});
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(0);
expect(fileSystem.readFileSync).toHaveBeenCalledTimes(2);
expect(octokit.rest.repos.getContent).toHaveBeenCalledTimes(1);
expect(
Expand Down Expand Up @@ -985,14 +957,7 @@ describe("main()", () => {
expect(octokit.rest.repos.generateReleaseNotes).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.getBranch).toHaveBeenCalledTimes(0);
expect(octokit.rest.git.createRef).toHaveBeenCalledTimes(0);
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.merge).toHaveBeenCalledWith({
owner: "owner",
repo: "repository",
base: "releases/next",
head: "main",
commit_message: 'chore(main): merge "main"',
});
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(0);
expect(fileSystem.readFileSync).toHaveBeenCalledTimes(2);
expect(fileSystem.readFileSync).toHaveBeenNthCalledWith(
2,
Expand All @@ -1014,5 +979,52 @@ describe("main()", () => {
});
expect(octokit.rest.issues.createComment).toHaveBeenCalledTimes(0);
});

it("should prepare when branch update requested", async () => {
mockPullRequestLists({
openRelease: pullRequests.openRelease,
changes: [
{
number: 7,
title: "title",
state: "closed",
labels: [
{ name: "label" },
{ name: "type: feature" },
{ name: "breaking" },
],
},
...changes,
],
});
inputs.keepReleaseBranchUpdated = true;

await main();

expect(core.setFailed).toHaveBeenCalledTimes(0);
expect(core.error).toHaveBeenCalledTimes(0);
expect(core.warning).toHaveBeenCalledTimes(0);
expect(core.notice).toHaveBeenCalledTimes(3);
expect(core.setOutput).toHaveBeenCalledTimes(5);
expect(octokit.rest.repos.generateReleaseNotes).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.getBranch).toHaveBeenCalledTimes(0);
expect(octokit.rest.git.createRef).toHaveBeenCalledTimes(0);
expect(octokit.rest.repos.merge).toHaveBeenCalledTimes(1);
expect(octokit.rest.repos.merge).toHaveBeenCalledWith({
owner: "owner",
repo: "repository",
base: "releases/next",
head: "main",
commit_message: 'chore(main): merge "main"',
});
expect(fileSystem.readFileSync).toHaveBeenCalledTimes(2);
expect(octokit.rest.repos.getContent).toHaveBeenCalledTimes(1);
expect(
octokit.rest.repos.createOrUpdateFileContents,
).toHaveBeenCalledTimes(1);
expect(octokit.rest.pulls.create).toHaveBeenCalledTimes(0);
expect(octokit.rest.pulls.update).toHaveBeenCalledTimes(1);
expect(octokit.rest.issues.createComment).toHaveBeenCalledTimes(0);
});
});
});
6 changes: 4 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32305,6 +32305,7 @@ const inputsSchema = zod__WEBPACK_IMPORTED_MODULE_2__.z.object({
}),
}),
skipPullRequestCreation: zod__WEBPACK_IMPORTED_MODULE_2__.z.boolean().default(false),
keepReleaseBranchUpdated: zod__WEBPACK_IMPORTED_MODULE_2__.z.boolean().default(false),
});
function parseEnvironment() {
return environmentSchema.parse(process.env);
Expand All @@ -32329,6 +32330,7 @@ function parseInputs() {
release: (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)("branch-release"),
},
skipPullRequestCreation: getBooleanInput("skip-pr-creation"),
keepReleaseBranchUpdated: getBooleanInput("keep-branch-updated"),
});
}
const environment = parseEnvironment();
Expand Down Expand Up @@ -32763,10 +32765,10 @@ async function mergeIntoOrTryCreateReleaseBranch() {
}
async function prepare(nextVersion, releaseNotes, releasePullRequest, isManualVersion) {
core.info(`Preparing new release...`);
if (releasePullRequest) {
if (releasePullRequest && inputs/* inputs.keepReleaseBranchUpdated */.FU.keepReleaseBranchUpdated) {
await mergeIntoReleaseBranch();
}
else {
else if (!releasePullRequest) {
await mergeIntoOrTryCreateReleaseBranch();
}
if (!releasePullRequest?.title.includes(nextVersion.version) &&
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/libs/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const inputsSchema = z.object({
}),
}),
skipPullRequestCreation: z.boolean().default(false),
keepReleaseBranchUpdated: z.boolean().default(false),
});

export function parseEnvironment() {
Expand Down Expand Up @@ -130,6 +131,7 @@ export function parseInputs() {
release: getInput("branch-release"),
},
skipPullRequestCreation: getBooleanInput("skip-pr-creation"),
keepReleaseBranchUpdated: getBooleanInput("keep-branch-updated"),
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ export async function prepare(
isManualVersion: boolean,
) {
core.info(`Preparing new release...`);
if (releasePullRequest) {
if (releasePullRequest && inputs.keepReleaseBranchUpdated) {
await mergeIntoReleaseBranch();
} else {
} else if (!releasePullRequest) {
await mergeIntoOrTryCreateReleaseBranch();
}

Expand Down

0 comments on commit 4f5cd88

Please sign in to comment.