From 1370f9298456f85341eba5a53c8f9821687f7e83 Mon Sep 17 00:00:00 2001 From: codfish <1666298+codfish@users.noreply.github.com> Date: Sat, 10 Feb 2024 15:58:47 -0500 Subject: [PATCH 1/4] fix: set default values in the entrypoint The action.yml metadata default values for the branches input wont work if you happen to be referencing a docker image --- action.yml | 20 +++++++++----------- entrypoint.js | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/action.yml b/action.yml index c598a61..99f6c6a 100644 --- a/action.yml +++ b/action.yml @@ -12,17 +12,6 @@ inputs: 'The branches on which releases should happen. https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#branches' required: false - default: | - [ - 'master', - 'main', - 'next', - 'next-major', - '+([0-9])?(.{+([0-9]),x}).x', - { name: 'beta', prerelease: true }, - { name: 'alpha', prerelease: true }, - { name: 'canary', prerelease: true }, - ] extends: description: 'String or array of modules or file paths containing a shareable configuration. @@ -91,3 +80,12 @@ outputs: runs: using: 'docker' image: 'Dockerfile' + args: + - ${{ inputs.branches }} + - ${{ inputs.extends }} + - ${{ inputs.plugins }} + - ${{ inputs.additional-packages }} + - ${{ inputs.dry-run }} + - ${{ inputs.repository-url }} + - ${{ inputs.tag-format }} + - ${{ inputs.branch }} diff --git a/entrypoint.js b/entrypoint.js index 5fcc062..2007d5b 100644 --- a/entrypoint.js +++ b/entrypoint.js @@ -4,11 +4,11 @@ import semanticRelease from 'semantic-release'; import JSON5 from 'json5'; import arrify from 'arrify'; -const parseInput = (input) => { +const parseInput = (input, defaultValue = '') => { try { return JSON5.parse(input); } catch (err) { - return input; + return defaultValue || input; } }; @@ -74,7 +74,16 @@ const setGitConfigSafeDirectory = () => { */ async function run() { const branch = parseInput(core.getInput('branch', { required: false })); - const branches = parseInput(core.getInput('branches', { required: false })); + const branches = parseInput(core.getInput('branches', { required: false }), [ + 'master', + 'main', + 'next', + 'next-major', + '+([0-9])?(.{+([0-9]),x}).x', + { name: 'beta', prerelease: true }, + { name: 'alpha', prerelease: true }, + { name: 'canary', prerelease: true }, + ]); const plugins = parseInput(core.getInput('plugins', { required: false })); const additionalPackages = parseInput(core.getInput('additional-packages', { required: false })) || []; From a7d72350f4dcea7d02ee073a8ff6265225483003 Mon Sep 17 00:00:00 2001 From: codfish <1666298+codfish@users.noreply.github.com> Date: Sat, 10 Feb 2024 16:02:51 -0500 Subject: [PATCH 2/4] feat: bump node to v20.11.0 --- .github/workflows/release.yml | 2 +- .github/workflows/validate.yml | 6 ++++-- .nvmrc | 2 +- Dockerfile | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d4c95b6..68be842 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: semantic-release id: semantic diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 35a159a..7449a45 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -7,11 +7,13 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha || github.ref }} - uses: actions/setup-node@v3 with: - node-version: 18.7.0 + node-version: 20.11.0 - run: npm ci diff --git a/.nvmrc b/.nvmrc index 805b5a4..7ea6a59 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v20.9.0 +v20.11.0 diff --git a/Dockerfile b/Dockerfile index f4e02d5..29e43db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20.9.0 +FROM node:20.11.0 # nice clean home for our action files RUN mkdir /action From 85b714e05ce151518aa6f2db992cf277ae2710ae Mon Sep 17 00:00:00 2001 From: codfish <1666298+codfish@users.noreply.github.com> Date: Sat, 10 Feb 2024 16:03:29 -0500 Subject: [PATCH 3/4] ci: publish docker images on PRs for testing --- .github/workflows/validate.yml | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 7449a45..25e6e61 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -24,25 +24,21 @@ jobs: id: semantic-test uses: ./ with: - dry_run: true branches: | [ '+([0-9])?(.{+([0-9]),x}).x', 'main', + 'fooalpha', + 'foobeta', 'next', 'next-major', - { - name: 'beta', - prerelease: true - }, - { - name: 'alpha', - prerelease: true - } + { name: 'beta', prerelease: true }, + { name: 'alpha', prerelease: true }, ] + dry-run: true repository-url: https://github.com/codfish/semantic-release-action.git - tag-format: 'v${version}' extends: '@semantic-release/apm-config' + tag-format: 'ver${version}' additional-packages: | ['@semantic-release/apm', '@semantic-release/git'] plugins: | @@ -67,3 +63,15 @@ jobs: echo "should be empty: $RELEASE_PATCH" env: OUTPUTS: ${{ toJson(steps.semantic.outputs) }} + + - name: docker login + run: | + echo "$GCR_TOKEN" | docker login ghcr.io -u codfish --password-stdin + env: + GCR_TOKEN: ${{ secrets.GCR_TOKEN }} + + # Dockerhub is auto synced with the repo, no need to explicitly deploy + - name: build and push branch docker image to GCR + run: | + docker build -t ghcr.io/codfish/semantic-release-action:$GITHUB_HEAD_REF . + docker push ghcr.io/codfish/semantic-release-action:$GITHUB_HEAD_REF From fdcdc285b3eb581cde81d276b1357717a9d23803 Mon Sep 17 00:00:00 2001 From: codfish <1666298+codfish@users.noreply.github.com> Date: Sat, 10 Feb 2024 17:04:28 -0500 Subject: [PATCH 4/4] docs: add release notes customization recipe to readme --- README.md | 190 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 130 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 3afa916..35c42a5 100644 --- a/README.md +++ b/README.md @@ -11,66 +11,23 @@ for you to use in subsequent actions containing version numbers. - [Usage](#usage) - - [Basic Usage](#basic-usage) + - [Which Version to Use](#which-version-to-use) - [Why](#why) - [Configuration](#configuration) - [Example with all inputs](#example-with-all-inputs) - [Outputs](#outputs) +- [Recipes](#recipes) + - [Including all commit types in a release](#including-all-commit-types-in-a-release) - [Maintenance](#maintenance) -## Usage - +> [!IMPORTANT] +> > Check the release notes for help > [migrating to v3](https://github.com/codfish/semantic-release-action/releases/tag/v3.0.0). -See [action.yml](action.yml). - -Referencing the major version is -([recommended by GitHub](https://github.com/actions/toolkit/blob/main/docs/action-versioning.md)). - -```yml -steps: - # Reference a docker image from GitHub Container Registry (recommended for speed & security) - - uses: docker://ghcr.io/codfish/semantic-release-action@sha256:e8640e0a620980247fd6e46f2f43f9a42d17181840518ea7fe983eeed65c154e - # Reference the major version of a release - - uses: codfish/semantic-release-action@v3 - # Reference a specific commit - - uses: codfish/semantic-release-action@ee5b4afec556c3bf8b9f0b9cd542aade9e486033 - # Reference a minor version of a release - - uses: codfish/semantic-release-action@v3.0.1 - # Reference a branch - - uses: codfish/semantic-release-action@main -``` - -> **Note**: Whenever you use a custom docker-based GitHub Action like this one, you may notice in -> your run logs, one of the first steps you'll see will be GA building the image for you. You can -> speed up runs by pulling pre-built docker images instead of making GitHub Actions build them on -> every run. - -```yml -steps: - # Reference a docker image from GitHub Container Registry - - uses: docker://ghcr.io/codfish/semantic-release-action:v3 - # Reference a docker image from Dockerhub - - uses: docker://codfish/semantic-release-action:v3 -``` - -**If you're security conscious**, you can -[pin the docker image down to a specific digest](https://francoisbest.com/posts/2020/the-security-of-github-actions#docker-based-actions) -instead of using an image tag, which is a mutable reference. - -```yml -steps: - # Reference a docker image from GitHub Container Registry - - uses: docker://ghcr.io/codfish/semantic-release-action@sha256:e8640e0a620980247fd6e46f2f43f9a42d17181840518ea7fe983eeed65c154e -``` - -Where `` is any -[docker image digest you want here](https://github.com/users/codfish/packages/container/package/semantic-release-action). - -### Basic Usage +## Usage ```yml steps: @@ -149,6 +106,58 @@ steps: If you're _not_ publishing to npm and only want to use this action for GitHub releases, the easiest approach would simply be to add `"private": true,` to your `package.json`. +### Which Version to Use + +See [action.yml](action.yml). + +```yml +steps: + # Recommended: Docker image digest from GitHub Container Registry (best for speed & security) + - uses: docker://ghcr.io/codfish/semantic-release-action@sha256:e8640e0a620980247fd6e46f2f43f9a42d17181840518ea7fe983eeed65c154e + + # Major version of a release + - uses: codfish/semantic-release-action@v3 + + # Minor version of a release + - uses: codfish/semantic-release-action@v3.0.1 + + # Specific commit + - uses: codfish/semantic-release-action@ee5b4afec556c3bf8b9f0b9cd542aade9e486033 + + # Git branch + - uses: codfish/semantic-release-action@main +``` + +> [!NOTE] +> +> Whenever you use a custom docker-based GitHub Action like this one, you may notice in your run +> logs, one of the first steps you'll see will be GA building the image for you. You can speed up +> runs by pulling pre-built docker images instead of making GitHub Actions build them on every run. + +```yml +steps: + # GitHub Container Registry + - uses: docker://ghcr.io/codfish/semantic-release-action:v3 + + # Dockerhub + - uses: docker://codfish/semantic-release-action:v3 +``` + +> [!TIP] +> +> **If you're security conscious**, you can +> [pin the docker image down to a specific digest](https://francoisbest.com/posts/2020/the-security-of-github-actions#docker-based-actions) +> instead of using an image tag, which is a mutable reference. + +```yml +steps: + # Docker image digest from GitHub Container Registry + - uses: docker://ghcr.io/codfish/semantic-release-action@sha256:e8640e0a620980247fd6e46f2f43f9a42d17181840518ea7fe983eeed65c154e +``` + +Where `` is any +[docker image digest you want here](https://github.com/users/codfish/packages/container/package/semantic-release-action). + ## Why It's fairly easy to run `semantic-release` as a "host action," aka something that runs directly on @@ -195,8 +204,10 @@ inputs here, the action will automatically use any [`semantic-release` configuration](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#configuration-file) defined in your repo (`.releaserc`, `release.config.js`, `release` prop in `package.json`) -> **Note**: Each input **will take precedence** over options configured in the configuration file -> and shareable configurations. +> [!NOTE] +> +> Each input **will take precedence** over options configured in the configuration file and +> shareable configurations. | Input Variable | Type | Description | Default | | --------------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | @@ -208,17 +219,23 @@ defined in your repo (`.releaserc`, `release.config.js`, `release` prop in `pack | `repository-url` | `String` | The git repository URL | [Semantic default](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#repositoryurl) | | `tag-format` | `String` | The Git tag format used by semantic-release to identify releases. | [Semantic default](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#tagformat) | -> **Note**: Any package specified in `extends` or `additional-packages` will be installed -> automatically for you as a convenience, allowing you to use this action without adding new -> dependencies to your application or install deps in a separate action step. +> [!NOTE] +> +> Any package specified in `extends` or `additional-packages` will be installed automatically for +> you as a convenience, allowing you to use this action without adding new dependencies to your +> application or install deps in a separate action step. -> **Note**: `additional-packages` won't get used automatically, setting this variable will just -> install them so you can use them. You'll need to actually list them in your `plugins` and/or -> `extends` configuration for **semantic-release** to use them. +> [!NOTE] +> +> `additional-packages` won't get used automatically, setting this variable will just install them +> so you can use them. You'll need to actually list them in your `plugins` and/or `extends` +> configuration for **semantic-release** to use them. -> **Note**: The `branch` input is **DEPRECATED**. Will continue to be supported for v1. Use -> `branches` instead. Previously used in semantic-release v15 to set a single branch on which -> releases should happen. +> [!NOTE] +> +> The `branch` input is **DEPRECATED**. Will continue to be supported for v1. Use `branches` +> instead. Previously used in semantic-release v15 to set a single branch on which releases should +> happen. - **GitHub Actions Inputs:** https://help.github.com/en/articles/metadata-syntax-for-github-actions#inputs @@ -299,6 +316,59 @@ might be so this is a way to cover more cases. | RELEASE_GIT_TAG | The version with v prefix. | | RELEASE_NAME | The release name. | +## Recipes + +### Including all commit types in a release + +By default, `semantic-release` only includes `fix`, `feat`, and `perf` commit types in the release. +A lot of projects want to include all commit types in their release notes, while still using +`semantic-release`'s commit analyzer to only create releases for `fix`, `feat`, and `perf` commits. + +```yml +- run: codfish/semantic-release-action@v3 + with: + additional-packages: ['conventional-changelog-conventionalcommits@7'] + plugins: | + [ + '@semantic-release/commit-analyzer', + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits", + "presetConfig": { + "types": [ + { type: 'feat', section: 'Features', hidden: false }, + { type: 'fix', section: 'Bug Fixes', hidden: false }, + { type: 'perf', section: 'Performance Improvements', hidden: false }, + { type: 'revert', section: 'Reverts', hidden: false }, + { type: 'docs', section: 'Other Updates', hidden: false }, + { type: 'style', section: 'Other Updates', hidden: false }, + { type: 'chore', section: 'Other Updates', hidden: false }, + { type: 'refactor', section: 'Other Updates', hidden: false }, + { type: 'test', section: 'Other Updates', hidden: false }, + { type: 'build', section: 'Other Updates', hidden: false }, + { type: 'ci', section: 'Other Updates', hidden: false } + ] + } + } + ], + '@semantic-release/npm', + '@semantic-release/github' + ] +``` + +This configuration uses the `conventional-changelog-conventionalcommits` package to generate release +notes & configures `@semantic-release/release-notes-generator` to include all commit types. Tweaking +the `types` array will allow you to include or exclude specific commit types & group them to your +liking. + +> [!IMPORTANT] +> +> This example uses the `additional-packages` input to install the +> `conventional-changelog-conventionalcommits` package. This is necessary because `semantic-release` +> doesn't install it by default & it's required for the customization of the `presetConfig` in the +> `@semantic-release/release-notes-generator` plugin. + ## Maintenance > Make the new release available to those binding to the major version tag: Move the major version