Skip to content

Commit

Permalink
ci: use release-please github action to create Gtihub release + pub…
Browse files Browse the repository at this point in the history
…lish on npm (#769)

* ci!: use `release-please` gh to publish on NPM + create Github release

* build: remove `standard-version` and `npm run release`
  • Loading branch information
CJ42 authored Oct 30, 2023
1 parent 0c17386 commit 66e001d
Show file tree
Hide file tree
Showing 7 changed files with 13,634 additions and 17,423 deletions.
49 changes: 0 additions & 49 deletions .github/workflows/build-artifacts.yml

This file was deleted.

51 changes: 0 additions & 51 deletions .github/workflows/create-github-release.yml

This file was deleted.

39 changes: 0 additions & 39 deletions .github/workflows/publish-npm-artifact.yml

This file was deleted.

58 changes: 58 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Github + NPM Release

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@v3
id: release
with:
release-type: node
package-name: "@lukso/lsp-smart-contracts"
bump-minor-pre-major: true
default-branch: main
changelog-types: '[{"type": "feat!","section":"BREAKING CHANGES","hidden": false},{"type": "refactor!","section":"BREAKING CHANGES","hidden": false},{"type": "build!","section":"BREAKING CHANGES","hidden": false},{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false}]'

# The logic below handles the npm publication.
# The `if` statements ensure that a publication only occurs when
# a new release is created:

- uses: actions/checkout@v3
if: ${{ steps.release.outputs.release_created }}

- name: Use Node.js '16.15.0'
uses: actions/setup-node@v2
if: ${{ steps.release.outputs.release_created }}
with:
node-version: "16.15.0"
registry-url: "https://registry.npmjs.org"
scope: "@lukso"
cache: "npm"

- name: Install Dependencies
if: ${{ steps.release.outputs.release_created }}
run: npm ci

# `npm run build:js` will also generate the auto-generated constants for methods, errors and events,
# including extracting their devdocs and userdocs
- name: Prepare artifacts to publish
if: ${{ steps.release.outputs.release_created }}
run: |
npm run build
npm run build:js
npm run package
- name: Publish on NPM
if: ${{ steps.release.outputs.release_created }}
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_KEY }}
79 changes: 40 additions & 39 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,62 @@
# **Release Process**

Releases are published when a commit including an increase in the `package.json` version number is merged to the `main` branch.
Releases are created on the Github repository and published to [npm]() using the [Release Please](https://github.com/googleapis/release-please) via the [`release-please`](https://github.com/google-github-actions/release-please-action#automating-publication-to-npm) Github action.

This function increases the version automatically using [standard-version](https://github.com/conventional-changelog/standard-version):
This package automates CHANGELOG generation, version bumps and npm releases by parsing the git history, looking for [Conventional Commit messages](https://www.conventionalcommits.org/).

```bash
$ npm run release
```

If the current branch contains new commits since the last git tag that contains [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/) prefixes like `feat`, `fix` or `docs`, it will increase the version as follows:

- `feat` will increase the `minor` version
- `fix` and `docs` will increase the `patch` version
When changes and feature PRs are merged from develop to main, release-please will open and maintain a release PR with the updated CHANGELOG and new version number. When this PR is merged, a release will be created and the package published to NPM.

Standard-version then:
1. Merge develop into main.
2. Release Please will create the release PR going to main.
3. Merge the generated release PR.
4. Package will be published to NPM.

1. updates the `package.json` version
2. adds to the `CHANGELOG.md` all commit messages grouped by `Feature`, `Bug Fixes`, `Documentation` or `Other`
3. commits all changes under: `chore(release): <version>`
## Conventional Commit prefixes?

Then push the changes to `develop`:
Commits should follow the [Conventional Commit messages standard](https://www.conventionalcommits.org/).

```bash
$ git push origin develop
```
The following commit prefixes will result in changes in the CHANGELOG:

A NPM and GitHub release is created when a version change in `package.json` is merged into `main`.
- `fix:` which represents bug fixes, and correlates to a [SemVer](https://semver.org/)
patch.
- `feat:` which represents a new feature, and correlates to a minor version increase.
(indicated by the `!`) and will result in a SemVer major version increase.
- `feat!:`, or `fix!:`, `refactor!:`, etc., which represent a breaking change
- `build:` Changes that affect the build system or external dependencies.
- `ci:` Changes to our CI configuration files and scripts.
- `docs:` Documentation only changes.
- `perf:` A code change that improves performance.
- `refactor:` A code change that neither fixes a bug nor adds a feature.
- `style:` Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc).
- `test:` Adding missing tests or correcting existing tests.
- `chore:` Other

A git tag will then be created, a GitHub Release created with the description of the PR to `main` as the release notes with the appended `CHANGELOG.md` content.
At last a release will be published in NPM automatically.
## Release with a custom version number

&nbsp;
When a commit to the main branch has `Release-As: x.x.x` (case insensitive) in the **commit body**, Release Please will open a new pull request for the specified version.

## Specific Version Increases
`git commit --allow-empty -m "chore: release 2.0.0" -m "Release-As: 2.0.0"` results in the following commit message:

To ignore the automatic version increase in favour of a custom version use the `--release-as` flag with the argument `major`, `minor` or `patch` or a specific version number:
```txt
chore: release 2.0.0
```bash
npm run release -- --release-as minor
# Or
npm run release -- --release-as 1.1.0
Release-As: 2.0.0
```

## Prerelease versions
## How can I fix release notes?

To create a pre-release run:
If you have merged a pull request and would like to amend the commit message
used to generate the release notes for that commit, you can edit the body of
the merged pull requests and add a section like:

```bash
npm run release -- --prerelease
```
BEGIN_COMMIT_OVERRIDE
feat: add ability to override merged commit message
If the lastest version is 1.0.0, the pre-release command will change the version to: `1.0.1-0`

To name the pre-release, set the name by adding `--prerelease <name>`

```bash
npm run release -- --prerelease alpha
fix: another message
chore: a third message
END_COMMIT_OVERRIDE
```

If the latest version is 1.0.0 this will change the version to: `1.0.1-alpha.0`
The next time Release Please runs, it will use that override section as the
commit message instead of the merged commit message.
Loading

0 comments on commit 66e001d

Please sign in to comment.