Skip to content

Commit

Permalink
feat: Various fixes and features (See below)
Browse files Browse the repository at this point in the history
- fix: Double 'https://' when using a custom registry URL, i.e. for GitHub packages
- fix: Remove redundant `git push remote --tags` command in `entrypoint.sh`

- docs: Update readme

- feat: Add support for a custom list of tags that trigger a major version update
- feat: Add support for a custom list of tags that trigger a minor version update
- feat: Add an option to disable the git tagging feature
- feat: Add a hidden debug option to enable more logging at runtime
- feat: Add support for the GitHub Actions inputs (enable using `with` instead of `env`); while keeping backward-compatibility for `env` users
- feat: Update node dependencies in `package.json`
- feat: Update docker container to use node v20
- feat: Omit the dev dependencies in the docker image
- feat: Drop unused `yargs` dependency
- feat: Switch `merge-release-run.js` to an ESM module

- chore: Put the license text into the `LICENSE` file
- chore: Move `package.json` from src to the root of the repo
- chore: Setup eslint and remove standard
- chore: Added the `.prettierrc` config file
- chore: Various cleanup in `entrypoint.sh`
- chore: Various cleanup in `merge-release-run.js`
  • Loading branch information
glitch452 committed Apr 16, 2024
1 parent 22d66d3 commit 4ecad57
Show file tree
Hide file tree
Showing 14 changed files with 1,485 additions and 3,442 deletions.
10 changes: 10 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
"contributions": [
"code"
]
},
{
"login": "glitch452",
"name": "David Dearden",
"avatar_url": "https://avatars.githubusercontent.com/u/894128?v=4",
"profile": "https://github.com/glitch452",
"contributions": [
"code",
"doc"
]
}
],
"contributorsPerLine": 7,
Expand Down
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
!./README.md
!./entrypoint.sh
!./src
!./src/*
!./src/*
!./package.json
!./package-lock.json
19 changes: 11 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: Build, Test and maybe Publish

on:
push:
branches:
- main
pull_request:

jobs:
test:
name: Build & Test
Expand All @@ -13,11 +15,12 @@ jobs:
- uses: actions/setup-node@v3
with:
cache: npm
cache-dependency-path: src/package-lock.json
cache-dependency-path: package-lock.json
- name: Build
run: cd src && npm install
run: npm install
- name: Test
run: cd src && npm test
run: npm test

publish:
name: Publish
needs: test
Expand All @@ -28,15 +31,15 @@ jobs:
- uses: actions/setup-node@v3
with:
cache: npm
cache-dependency-path: src/package-lock.json
cache-dependency-path: package-lock.json
- name: Build
run: cd src && npm install
run: npm install
- name: Test
run: cd src && npm test
run: npm test
- name: Publish
uses: github-actions-community/merge-release@main
env:
DEPLOY_DIR: src
SRC_PACKAGE_DIR: src
DEPLOY_DIR: .
SRC_PACKAGE_DIR: .
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"jsxSingleQuote": false,
"printWidth": 120,
"quoteProps": "as-needed",
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all"
}
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18-slim
FROM node:20-slim

LABEL version="1.0.0"
LABEL repository="http://github.com/Github-Actions-Community/merge-release"
Expand All @@ -10,12 +10,16 @@ LABEL com.github.actions.description="Release npm package based on commit metada
LABEL com.github.actions.icon="package"
LABEL com.github.actions.color="red"

RUN apt-get update && apt-get -y --no-install-recommends install git jq findutils curl ca-certificates && rm -rf /var/lib/apt/lists/*
RUN apt-get -y update && \
apt-get -y --no-install-recommends install git jq findutils curl ca-certificates && \
rm -rf /var/lib/apt/lists/* && \
npm update -g npm

COPY . .
WORKDIR /usr/app
COPY ./ ./

# Install dependencies here
RUN cd src && npm i
RUN npm ci --omit dev

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/usr/app/entrypoint.sh"]
CMD ["help"]
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ISC License

Copyright 2024 Github-Actions-Community

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
93 changes: 55 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,84 @@
# ![LogoMakr-2ULBLV](https://github.com/Github-Actions-Community/merge-release/assets/3071208/bb7d9b4c-04bd-41c5-9c08-0ee5c91fa4a1)

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

[![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors-)

<!-- ALL-CONTRIBUTORS-BADGE:END -->

GitHub Action for automated npm publishing.

This Action publishes a package to npm. It is meant to be used on every successful merge to main but
This Action publishes a package to npm. It is meant to be used on every successful merge to main but
you'll need to configure that workflow yourself. You can look to the
[`.github/workflows/push.yml`](./.github/workflows/release.yml) file in this project as an example.

### Workflow

* Check for the latest version number published to npm.
* Lookup all commits between the git commit that triggered the action and the latest publish.
* If the package hasn't been published or the prior publish does not include a git hash, we'll
only pull the commit data that triggered the action.
* Based on the commit messages, increment the version from the lastest release.
* If the strings "BREAKING CHANGE" or "!:" are found anywhere in any of the commit messages or descriptions the major
version will be incremented.
* If a commit message begins with the string "feat" then the minor version will be increased. This works
for most common commit metadata for feature additions: `"feat: new API"` and `"feature: new API"`.
* All other changes will increment the patch version.
* Publish to npm using the configured token.
* Push a tag for the new version to GitHub.

- Check for the latest version number published to npm.
- Lookup all commits between the git commit that triggered the action and the latest publish.
- Note: The package needs to have an initial publish in order to pull the package details.
- Based on the commit messages, increment the version from the latest release.
- If the strings "BREAKING CHANGE" is found anywhere in any of the commit messages, or "!:" is found in the first line or a commit message starts with one of the provided major tags (optional), then the major version will be incremented.
- If a commit message begins with the string "feat" (or a tag in the minor tags list) then the minor version will be increased. This works for most common commit metadata for feature additions: `"feat: new API"` and `"feature: new API"`.
- All other changes will increment the patch version.
- Publish to npm (or the provided registry url) using the configured token.
- Push a tag for the new version to GitHub.

### Configuration

You can configure some aspects of merge-release action by passing some environmental variables.

* **GITHUB_TOKEN (required)**
* Github token to allow tagging the version.
* **NPM_AUTH_TOKEN (required)**
* NPM Auth Token to publish to NPM, read [here](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) how to setup it as a secret.
* **DEPLOY_DIR**
* The path where the dist `package.json` is to run npm publish. Defaults to the root dir.
* **SRC_PACKAGE_DIR**
* The path where the src package.json is found. Defaults to the root dir.
* **NPM_REGISTRY_URL**
* NPM Registry URL to use. defaults to: `https://registry.npmjs.org/`
* **NPM_PRIVATE**
* If you wish privately publish your package please ensure you have set this to `true`

`merge-release` will use `npm publish` unless you've defined a `publish` script in your `package.json`.
- **GITHUB_TOKEN (required)**
- Github token to allow tagging the version.
- **NPM_AUTH_TOKEN (required)**
- NPM Auth Token to publish to the registry, read [here](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) how to setup it as a secret.
- **DEPLOY_DIR**
- The path where the dist `package.json` is to run npm publish. Defaults to the root dir. This is a relative file path, relative to the root of the repo.
- **SRC_PACKAGE_DIR**
- The path where the src `package.json` is found. Defaults to the root dir. This is a relative file path, relative to the root of the repo.
- **NPM_REGISTRY_URL**
- NPM Registry URL to use. defaults to: `https://registry.npmjs.org/`. Set it to `https://npm.pkg.github.com` for GitHub Packages.
- **NPM_PRIVATE**
- If you wish privately publish your package please ensure you have set this to `true`
- **DISABLE_GIT_TAG**
- If you wish skip setting the git tag, set this to `true`
- **MAJOR_TAGS**
- A list of tags to check for when considering whether to perform a major version update. The value is a list separated by the `|` character. i.e. `major|my-major-tag`
- **MINOR_TAGS**
- Override the list of tags to check for when considering whether to perform a minor version update. The value is a list separated by the `|` character. i.e. `feat|minor|my-minor-tag`

`merge-release` will use `npm publish` by default; but if you've defined a `publish` script in your `package.json` it will use that instead.

## Examples

```yaml
- name: Publish to NPM
uses: Github-Actions-Community/merge-release@main
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
DEPLOY_DIR: my/deploy/dir
SRC_PACKAGE_DIR: my/src/package
```
```yaml
- uses: Github-Actions-Community/merge-release@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
DEPLOY_DIR: my/deploy/dir
SRC_PACKAGE_DIR: my/src/package
- name: Publish to GitHub Packages
uses: Github-Actions-Community/merge-release@main
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_REGISTRY_URL: https://npm.pkg.github.com/
MINOR_TAGS: feat|docs
```
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<table>
<tbody>
<tr>
Expand All @@ -72,11 +90,10 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
</tbody>
</table>
<!-- ALL-CONTRIBUTORS-LIST:END -->
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
##### Created my free [logo](https://logomakr.com/5sISSS) at [LogoMakr.com](LogoMakr.com)
##### Created my free [logo](https://logomakr.com/5sISSS) at [LogoMakr.com](LogoMakr.com)
57 changes: 38 additions & 19 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,58 @@
name: 'Merge Release'
description: 'Deploy your package to NPM and Github using semantic versioning'
name: Merge Release

description: Deploy your package to NPM and Github using semantic versioning

branding:
icon: 'upload-cloud'
color: 'purple'
runs:
using: 'docker'
image: 'Dockerfile'
icon: upload-cloud
color: purple

runs:
using: docker
image: Dockerfile

inputs:
GITHUB_TOKEN:
description: 'GITHUB_TOKEN'
description: Github token to allow tagging the version.
required: true
NPM_AUTH_TOKEN:
description: 'NPM_AUTH_TOKEN'
description: NPM Auth Token to publish to NPM
required: true
NPM_PRIVATE:
description: 'NPM_PRIVATE'
description: If you wish privately publish your package please ensure you have set this to `true`
required: false
SRC_PACKAGE_DIR:
description: The path where the src package.json is found. Defaults to the root dir.
required: false
DEPLOY_DIR:
description: 'DEPLOY_DIR'
description: The path where the dist `package.json` is to run npm publish. Defaults to the root dir.
required: false
NPM_REGISTRY_URL:
description: 'NPM_REGISTRY_URL'
description: The url of the registry that the package should published to
required: false
GIT_TAG_SUFFIX:
description: 'GIT_TAG_SUFFIX'
DISABLE_GIT_TAG:
description: Set to `true` to disable the git tag feature
required: false
SRC_PACKAGE_DIR:
description: 'SRC_PACKAGE_DIR'
MAJOR_TAGS:
description: A list of commit tags to consider a release as a major release
required: false
MINOR_TAGS:
description: A list of commit tags to consider a release as a minor release
required: false
DEBUG:
description: Enable debug logging
required: false
NPM_CUSTOM_NPMRC:
description: A fully-formed npmrc file
required: false
GIT_TAG_SUFFIX:
description: GIT_TAG_SUFFIX
required: false
GITHUB_SHA:
description: 'GITHUB_SHA'
description: GITHUB_SHA
required: false
GITHUB_ACTOR:
description: 'GITHUB_ACTOR'
description: GITHUB_ACTOR
required: false
GITHUB_REPOSITORY:
description: 'GITHUB_REPOSITORY'
description: GITHUB_REPOSITORY
required: false
Loading

0 comments on commit 4ecad57

Please sign in to comment.