From 7f5f7549cf6f0541f3317fb41db42d7df09d48aa Mon Sep 17 00:00:00 2001 From: Rui Martins Date: Tue, 21 Jan 2025 12:58:23 +0000 Subject: [PATCH] ci: implement release-please to automate release creation (#863) * ci: implement release-please to automate release creation * docs: remove unnecessary validate step from PR checklist * chore: fix current version * docs: update README's Releasing section * ci: add semantic-pull-request validation * docs: add note about versioning in the PR template * chore: address code review feedback --- .github/PULL_REQUEST_TEMPLATE.md | 10 +-- .github/release-please-config.json | 14 ++++ .github/release-please-manifest.json | 3 + .../workflows/check-semantic-pull-request.yml | 25 +++++++ .github/workflows/publish.yml | 8 ++- .github/workflows/release-please.yml | 23 +++++++ README.md | 68 ++++++------------- 7 files changed, 93 insertions(+), 58 deletions(-) create mode 100644 .github/release-please-config.json create mode 100644 .github/release-please-manifest.json create mode 100644 .github/workflows/check-semantic-pull-request.yml create mode 100644 .github/workflows/release-please.yml diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 659adc38e..07f9cc97b 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -6,7 +6,9 @@ Closes #... ## Short description + ## PR Checklist @@ -16,14 +18,8 @@ Feel free to leave unchecked or remove the lines that are not applicable. - [ ] Added tests for bugs / new features - [ ] Updated docs (storybooks, readme) -- [ ] Executed `npm run validate` and made sure no errors / warnings were shown -- [ ] Described changes in `CHANGELOG.md` -- [ ] Bumped version in `package.json` and `package-lock.json` (`npm --no-git-tag-version version `) [ref](https://docs.npmjs.com/cli/v6/commands/npm-version) - [ ] Reviewed and approved Chromatic visual regression tests in CI -## Versioning - diff --git a/.github/release-please-config.json b/.github/release-please-config.json new file mode 100644 index 000000000..a076a211a --- /dev/null +++ b/.github/release-please-config.json @@ -0,0 +1,14 @@ +{ + "packages": { + ".": { + "changelog-path": "CHANGELOG.md", + "release-type": "node", + "bump-minor-pre-major": false, + "bump-patch-for-minor-pre-major": false, + "draft": false, + "prerelease": false, + "include-component-in-tag": false + } + }, + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json" +} diff --git a/.github/release-please-manifest.json b/.github/release-please-manifest.json new file mode 100644 index 000000000..5de267207 --- /dev/null +++ b/.github/release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "27.2.1" +} diff --git a/.github/workflows/check-semantic-pull-request.yml b/.github/workflows/check-semantic-pull-request.yml new file mode 100644 index 000000000..311ecff55 --- /dev/null +++ b/.github/workflows/check-semantic-pull-request.yml @@ -0,0 +1,25 @@ +name: Semantic Pull Request + +on: + pull_request: + types: + - edited + - opened + - synchronize + push: + branches: + - gh-readonly-queue/main/** + +jobs: + validate-title: + name: Validate Title + runs-on: ubuntu-latest + + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + timeout-minutes: 5 + steps: + - name: Validate pull request title + uses: amannn/action-semantic-pull-request@db6e259b93f286e3416eef27aaae88935d16cf2e + with: + validateSingleCommit: true diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8b0df4118..f89c515cf 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,9 +1,9 @@ name: Release @doist/reactist package on: - release: - types: [created] - workflow_dispatch: + push: + tags: + - 'v*' permissions: # Enable the use of OIDC for npm provenance @@ -14,6 +14,8 @@ permissions: jobs: publish: + # Only run if release-please created a release + if: ${{ startsWith(github.ref, 'refs/tags/v') }} runs-on: ubuntu-latest # Based on historical data timeout-minutes: 60 diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 000000000..4f5af95c5 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,23 @@ +name: Release Please + +on: + push: + branches: + - main + +permissions: + contents: write + pull-requests: write + +jobs: + release-please: + runs-on: ubuntu-latest + steps: + - uses: google-github-actions/release-please-action@v4 + id: release + with: + token: ${{ secrets.GITHUB_TOKEN }} + release-type: node + package-name: '@doist/reactist' + config-file: .github/release-please-config.json + manifest-file: .github/release-please-manifest.json diff --git a/README.md b/README.md index a4d4a66c9..2c758d9f3 100644 --- a/README.md +++ b/README.md @@ -203,58 +203,30 @@ When you open a GitHub PR, you'll notice the "UI Review" and "UI Tests" CI steps # Releasing -A new version of reactist is published both on npm and GitHub Package Registry whenever a new release on GitHub is created. +This project uses [release-please](https://github.com/googleapis/release-please) to automate version management and package publishing. -## Before merging your changes +## How it works -In the GitHub PR that contains your new changes, make sure that you also include the following: +1. Make your changes using [Conventional Commits](https://www.conventionalcommits.org/): -1. Add tests for bugs and new feature + - `feat:` for new features (minor version bump) + - `fix:` for bug fixes (patch version bump) + - `feat!:` or `fix!:` for breaking changes (major version bump) + - `docs:` for documentation changes + - `chore:` for maintenance tasks + - `ci:` for CI changes -2. Update relevant docs (storybooks, readme) +2. When commits are pushed to `main`: -3. Execute: + - Release-please automatically creates/updates a release PR + - The PR includes version bump and changelog updates + - Review the PR and merge when ready -```sh -npm run validate -``` - -and make sure no errors nor warnings are shown - -4. Describe your changes in [`CHANGELOG.md`](CHANGELOG.md) - -5. Bump the version in [`package.json`](package.json) and [`package-lock.json`](package-lock.json) by running: - -```sh -npm --no-git-tag-version version -``` - -[ref](https://docs.npmjs.com/cli/v6/commands/npm-version) - -Note that the steps above are also documented in the [PR template](.github/PULL_REQUEST_TEMPLATE.md) that you will be prompted with whenever you open a new reactist GitHub PR. - -## After merging your changes - -Once your changes have been merged to `main`, create a new GitHub release: - -1. Visit https://github.com/Doist/reactist/releases/new - -2. In the "Choose a tag" dropdown, type the new release version (i.e. vX.Y.Z) and select "Create new tag: vX.Y.Z on publish" - -3. In the "Release title" field, type the new release version (i.e. vX.Y.Z) - -4. In the "Describe the release" box, paste the same content you added to the [`CHANGELOG.md`](CHANGELOG.md), but without the title header - -5. Make sure the "Set as the latest release" checkbox is checked - -6. Click "Publish release" - -7. Visit https://github.com/Doist/reactist/actions - -8. Make sure that a new GitHub action is now running (this will automatically perform all the necessary steps to publish the package) - -9. Once the action is complete, check https://npmjs.com/package/@doist/reactist and verify that there's a new public release - -Finally, be sure to update both [todoist-web](https://github.com/Doist/todoist-web) and [twist-web](https://github.com/Doist/twist-web) to use the new reactist version you just published. +3. After merging the release PR: + - A new GitHub release is automatically created + - A new tag is created + - The `publish` workflow is triggered + - The package is published to npm and GitHub Packages + - Storybook documentation is automatically updated -The storybook hosted on GitHub pages will be automatically updated on each push to `main`. Should there be a problem, try running the action manually from the [Actions settings](https://github.com/Doist/reactist/actions). +The storybook hosted on GitHub pages will be automatically updated on each push to `main`. If there's a problem, try running the action manually from the [Actions settings](https://github.com/Doist/reactist/actions).