Skip to content

Commit

Permalink
feat(prepare): add skip-pr-creation input (#195)
Browse files Browse the repository at this point in the history
* feat(prepare): add `skip-pr-creation` input

* fix(prepare): fix pull request creation skip

* docs(main): update README and CONTRIBUTING
  • Loading branch information
benjamin-guibert authored Apr 2, 2024
1 parent 152c14c commit 8256251
Show file tree
Hide file tree
Showing 14 changed files with 412 additions and 92 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
dist
node_modules
pnpm-lock.yaml
34 changes: 34 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,37 @@ However, **we are not currently accepting new contributions**.

Check out the contributing section of the [`README`](https://github.com/cyberspace7/release-action#contributing)
file to find out how else you can contribute to this project.

## Development

See [`package.json`](package.json) for the list of available scripts.

### Prerequisites

This project require the following dependencies:

- [Node.js](https://nodejs.org)
- [pnpm](https://pnpm.io)

### Setup

Install the dependencies:

```bash
pnpm install
```

### Build

[Source files](src) are are compiled into a single file with all dependencies, into [`dist`](dist).
The `dist` directory must be commited into the repository.

```bash
pnpm build
```

### Release

Releases are automatic, following the merge of the release pull request (see [Release Action](https://github.com/cyberspace7/release-action#readme)).
A release PR can be explicitely generated by running manually
[this workflow](https://github.com/cyberspace7/release-action/actions/workflows/release.yml).
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ body:
attributes:
value: |
Thank you for taking the time to fill out this bug report, your help is much appreciated!
If you're not sure that this is a bug, please ask us in the [Discussions](https://github.com/cyberspace7/release-action/discussions/categories/q-a) first.
- type: textarea
id: description
attributes:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ yarn-error.log*

*.tsbuildinfo

# IDE

.vscode

# Miscellanous

.DS_Store
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
dist
node_modules
pnpm-lock.yaml
131 changes: 89 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,25 @@ PR-based Github Action for releasing Node.js projects.
[here](https://github.com/cyberspace7/release-action/milestones), don't hesitate to upvote
issues you want to be treated.
If you have any question, remark, suggestion, ... They are most welcome in the
[discussions](https://github.com/cyberspace7/release-action/discussions)!
[Discussions](https://github.com/cyberspace7/release-action/discussions)!

## Table of Contents

- [Release Action](#release-action)
- [Table of Contents](#table-of-contents)
- [Description](#description)
- [When it should be used](#when-it-should-be-used)
- [When it should not be used](#when-it-should-not-be-used)
- [Usage](#usage)
- [Permissions](#permissions)
- [Inputs](#inputs)
- [Outputs](#outputs)
- [Secrets](#secrets)
- [Environment variables](#environment-variables)
- [Examples](#examples)
- [Contributing](#contributing)
- [Authors](#authors)
- [Licensing](#licensing)

## Description

Expand Down Expand Up @@ -142,6 +160,8 @@ jobs:
pre-release: ${{ inputs.pre-release != '' }}
```
See the [examples](#examples) for more use cases.
> [!WARNING]
> Use a manual version (like in the example bellow) until a `v1` becomes available.
> Remember that this version **is not production ready**.
Expand Down Expand Up @@ -196,18 +216,19 @@ 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` |
| 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` |

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

Expand Down Expand Up @@ -237,43 +258,65 @@ _None._
| -------------- | ------------------------------------------- |
| `GITHUB_TOKEN` | Authentification token used for GitHub API. |

## Development

See [`package.json`](package.json) for the list of available scripts.

### Prerequisites

This project require the following dependencies:
### Examples

- [Node.js](https://nodejs.org)
- [pnpm](https://pnpm.io)

### Setup

Install the dependencies:

```bash
pnpm install
```
Execute another job when a release has been made:

### Build
```yaml
name: Release
[Source files](src) are are compiled into a single file with all dependencies, into [`dist`](dist).
The `dist` directory must be commited into the repository.
on:
push:
branches:
- main
```bash
pnpm build
jobs:
release:
name: Release
runs-on: ubuntu-latest
outputs:
is-released: ${{ steps.action.outputs.is-released }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Execute action
id: action
uses: cyberspace7/release-action@v0.6.0
publish:
name: Publish
needs: release
if: needs.release.outputs.is-released == 'true'
uses: ./.github/workflows/publish.yml
```

### Release
Only create release PRs when manually triggered:

Releases are automatic, following the merge of the release pull request (see [Release Action](https://github.com/cyberspace7/release-action#readme)).
A release PR can be explicitely generated by running manually
[this workflow](https://github.com/cyberspace7/release-action/actions/workflows/release.yml).
```yaml
name: Release
## Authors
on:
push:
branches:
- main
workflow_dispatch:
- [**Benjamin Guibert**](https://github.com/benjamin-guibert) – main author and contributor.
jobs:
release:
name: Release
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Execute action
id: action
uses: cyberspace7/release-action@v0.6.0
with:
skip-pr-creation: ${{ github.event_name == 'workflow_dispatch' }}
```

## Contributing

Expand All @@ -283,7 +326,11 @@ in the [discussions](https://github.com/cyberspace7/release-action/discussions/c
If you find a bug concerning this project, please fill a [bug report](https://github.com/cyberspace7/release-action/issues/new?assignees=&labels=bug-report&projects=&template=bug-report.yml).
If it concerns a security vulnerability, please email us at `contact@a60.dev`.

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

## Authors

- [**Benjamin Guibert**](https://github.com/benjamin-guibert) – main author and contributor.

## Licensing

Expand Down
22 changes: 21 additions & 1 deletion __tests__/libs/inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function mockInputs(inputs: {
production?: string;
release?: string;
};
skipPullRequestCreation?: string;
}) {
core.getInput
.mockReturnValueOnce(inputs.preRelease ?? "")
Expand All @@ -28,7 +29,9 @@ export function mockInputs(inputs: {
.mockReturnValueOnce(inputs.releaseLabels?.ready ?? "")
.mockReturnValueOnce(inputs.releaseLabels?.done ?? "")
.mockReturnValueOnce(inputs.branches?.production ?? "")
.mockReturnValueOnce(inputs.branches?.release ?? "");
.mockReturnValueOnce(inputs.branches?.release ?? "")
.mockReturnValueOnce(inputs.skipPullRequestCreation ?? "")
.mockReturnValue("");
}

describe("parseInputs()", () => {
Expand Down Expand Up @@ -170,4 +173,21 @@ describe("parseInputs()", () => {
});
});
});

describe("when `skipPullRequestCreation`", () => {
test.each([
[false, ""],
[false, "false"],
[false, "0"],
[true, "true"],
[true, "True"],
[true, "1"],
])("should return`%p` when `%p`", (expected, input) => {
mockInputs({ skipPullRequestCreation: input });

const result = parseInputs();

expect(result.skipPullRequestCreation).toEqual(expected);
});
});
});
Loading

0 comments on commit 8256251

Please sign in to comment.