Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Various fixes and features #10

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1596e8f
chore: Added the `.prettierrc` config file
glitch452 Apr 16, 2024
0826915
chore: Move `package.json` from src to the root
glitch452 Apr 16, 2024
7ac4ccd
chore: Setup eslint and remove standard
glitch452 Apr 16, 2024
44ffebd
chore: Put the license text into the 'LICENSE' file
glitch452 Apr 16, 2024
163c8ae
feat: Add 'DISABLE_GIT_TAG' option
glitch452 Apr 16, 2024
5817c37
fix: Remove redundant 'git push' command in 'entrypoint.sh'
glitch452 Apr 16, 2024
1c4e6f3
chore: Drop unused 'yargs' dependency
glitch452 Apr 16, 2024
2b6423b
refactor: Convert 'merge-release-run.js' to ESM
glitch452 Apr 16, 2024
296fbea
feat: Omit the dev dependencies in the docker image
glitch452 Apr 16, 2024
fa57fd1
feat: Update npm in the docker container
glitch452 Apr 16, 2024
55a16f6
feat: Update docker container to use node v20
glitch452 Apr 16, 2024
ba632b8
feat: Update dependencies in 'package.json'
glitch452 Apr 17, 2024
6acc529
refactor: extract functions in 'merge-release-run.js'
glitch452 Apr 17, 2024
d6ab713
feat: Setup a debug flag and more logging
glitch452 Apr 17, 2024
d350ff1
refactor: Use simple-git async mode instead of promisify
glitch452 Apr 17, 2024
8a328b1
fix: Handle undefined commit body
glitch452 Apr 17, 2024
bdee897
feat: Custom list of minor tags
glitch452 Apr 17, 2024
33cd89a
feat: Custom list of major tags
glitch452 Apr 17, 2024
a6913ee
feat: Support 'BREAKING-CHANGE' footer
glitch452 Apr 17, 2024
c00fa0b
fix: Double 'https://' when using custom registry URL
glitch452 Apr 17, 2024
838ba33
feat: Support GitHub Actions inputs ('with')
glitch452 Apr 17, 2024
c1a795a
docs: Update README
glitch452 Apr 17, 2024
b817d52
feat: Cleanup with restore
glitch452 Apr 17, 2024
8850425
fix: Make sure registry url ends with a /
glitch452 Apr 17, 2024
fdb0d2e
fix: version set in outputs
glitch452 Apr 17, 2024
cf166c1
feat: Define outputs in action.yaml
glitch452 Apr 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 7 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ 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 +28,13 @@ 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
with:
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"
}
9 changes: 6 additions & 3 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,15 @@ 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 . .

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

ENTRYPOINT ["/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.
95 changes: 56 additions & 39 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.
You can configure some aspects of merge-release action by using the `with` properties on the action or passing some environmental variables.

- **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 to 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`

Note: `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

* **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`.
```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)
66 changes: 47 additions & 19 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,67 @@
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

outputs:
version:
description: The new version used as the release version

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
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
SRC_PACKAGE_DIR:
description: The path where the src package.json is found. 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'
MINOR_TYPES:
description: A list of conventional commit types (separated by a |) to consider a release as a minor release
required: false
SRC_PACKAGE_DIR:
description: 'SRC_PACKAGE_DIR'
MAJOR_TYPES:
description: A list of conventional commit types (separated by a |) to consider a release as a major release
required: false
DISABLE_GIT_TAG:
description: Set to `true` to disable the git tag feature
required: false
NPM_CONFIG_USERCONFIG:
description: The path to the user .npmrc file
required: false
NPM_CUSTOM_NPMRC:
description: Provide the contents of a fully-formed .npmrc file
required: false
NPM_STRICT_SSL:
description: 'Set to `false` to enforce http (instead of https) for the NPM_REGISTRY_URL (default: `true`)'
required: false
DEBUG:
description: Enable debug logging
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
56 changes: 39 additions & 17 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,54 @@

set -e

# Respect NPM_CONFIG_USERCONFIG if it is provided, default to $HOME/.npmrc
NPM_CONFIG_USERCONFIG="${NPM_CONFIG_USERCONFIG-"$HOME/.npmrc"}"
# Map the GitHub actions inputs over to the environment variables and export them to support both `env` and `with` methods for backwards-compatibility
export GITHUB_TOKEN="${INPUT_GITHUB_TOKEN:-"$GITHUB_TOKEN"}"
export NPM_AUTH_TOKEN="${INPUT_NPM_AUTH_TOKEN:-"$NPM_AUTH_TOKEN"}"
export NPM_PRIVATE="${INPUT_NPM_PRIVATE:-"$NPM_PRIVATE"}"
export DEPLOY_DIR="${INPUT_DEPLOY_DIR:-"$DEPLOY_DIR"}"
export SRC_PACKAGE_DIR="${INPUT_SRC_PACKAGE_DIR:-"$SRC_PACKAGE_DIR"}"
export NPM_REGISTRY_URL="${INPUT_NPM_REGISTRY_URL:-"$NPM_REGISTRY_URL"}"
export MINOR_TYPES="${INPUT_MINOR_TYPES:-"$MINOR_TYPES"}"
export MAJOR_TYPES="${INPUT_MAJOR_TYPES:-"$MAJOR_TYPES"}"
export DISABLE_GIT_TAG="${INPUT_DISABLE_GIT_TAG:-"$DISABLE_GIT_TAG"}"
export DEBUG="${INPUT_DEBUG:-"$DEBUG"}"
export GIT_TAG_SUFFIX="${INPUT_GIT_TAG_SUFFIX:-"$GIT_TAG_SUFFIX"}"
export GITHUB_SHA="${INPUT_GITHUB_SHA:-"$GITHUB_SHA"}"
export GITHUB_ACTOR="${INPUT_GITHUB_ACTOR:-"$GITHUB_ACTOR"}"
export GITHUB_REPOSITORY="${INPUT_GITHUB_REPOSITORY:-"$GITHUB_REPOSITORY"}"
export NPM_CONFIG_USERCONFIG="${INPUT_NPM_CONFIG_USERCONFIG:-"$NPM_CONFIG_USERCONFIG"}"
export NPM_CUSTOM_NPMRC="${INPUT_NPM_CUSTOM_NPMRC:-"$NPM_CUSTOM_NPMRC"}"
export NPM_STRICT_SSL="${INPUT_NPM_STRICT_SSL:-"$NPM_STRICT_SSL"}"

# Set default values
NPM_STRICT_SSL="${NPM_STRICT_SSL:-"true"}"
NPM_REGISTRY_SCHEME="https"
if ! [ "$NPM_STRICT_SSL" = "true" ]; then NPM_REGISTRY_SCHEME="http"; fi
NPM_REGISTRY_DOMAIN="$(echo "${NPM_REGISTRY_URL:-registry.npmjs.org}" | sed -r 's/https?:\/\///' | sed -r 's/\/+$//')"
NPM_REGISTRY_URL="${NPM_REGISTRY_SCHEME}://$NPM_REGISTRY_DOMAIN"
NPM_CONFIG_USERCONFIG="${NPM_CONFIG_USERCONFIG:-"$HOME/.npmrc"}"

if [ "$DEBUG" = "true" ]; then
echo "Debug Enabled, Printing Environment:"
printenv
echo ""
fi

if [ -n "$NPM_CUSTOM_NPMRC" ]; then
# Use a fully-formed npmrc file if provided
echo "$NPM_CUSTOM_NPMRC" > "$NPM_CONFIG_USERCONFIG"

chmod 0600 "$NPM_CONFIG_USERCONFIG"
elif [ -n "$NPM_AUTH_TOKEN" ]; then
# Respect NPM_CONFIG_USERCONFIG if it is provided, default to $HOME/.npmrc
NPM_CONFIG_USERCONFIG="${NPM_CONFIG_USERCONFIG-"$HOME/.npmrc"}"
NPM_REGISTRY_URL="${NPM_REGISTRY_URL-registry.npmjs.org}"
NPM_STRICT_SSL="${NPM_STRICT_SSL-true}"
NPM_REGISTRY_SCHEME="https"
if ! $NPM_STRICT_SSL; then
NPM_REGISTRY_SCHEME="http"
fi

# Allow registry.npmjs.org to be overridden with an environment variable
printf "//%s/:_authToken=%s\\nregistry=%s\\nstrict-ssl=%s" "$NPM_REGISTRY_URL" "$NPM_AUTH_TOKEN" "${NPM_REGISTRY_SCHEME}://$NPM_REGISTRY_URL" "${NPM_STRICT_SSL}" > "$NPM_CONFIG_USERCONFIG"

printf "//%s/:_authToken=%s\\nregistry=%s\\nstrict-ssl=%s" "$NPM_REGISTRY_DOMAIN" "$NPM_AUTH_TOKEN" "${NPM_REGISTRY_URL}/" "$NPM_STRICT_SSL" > "$NPM_CONFIG_USERCONFIG"
chmod 0600 "$NPM_CONFIG_USERCONFIG"
fi

if [ "$DEBUG" = "true" ]; then
echo "Debug Enabled, Printing user .npmrc file '$NPM_CONFIG_USERCONFIG' contents:"
cat "$NPM_CONFIG_USERCONFIG"
echo "\n"
fi

# initialize git
remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git config --global --add safe.directory "/github/workspace"
Expand All @@ -39,5 +63,3 @@ git branch --verbose

# Dependencies are installed at build time
node /src/merge-release-run.js "$@" || exit 1

git push "${remote_repo}" --tags
4 changes: 4 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import globals from 'globals';
import pluginJs from '@eslint/js';

export default [{ languageOptions: { globals: globals.node } }, pluginJs.configs.recommended];
Loading