Skip to content

Commit

Permalink
Merge pull request #198 from codfish/fix-docker-image
Browse files Browse the repository at this point in the history
fix: include action metadata file in docker image
  • Loading branch information
codfish authored Feb 10, 2024
2 parents 65faef0 + fdcdc28 commit 07170c8
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: semantic-release
id: semantic
Expand Down
34 changes: 22 additions & 12 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -22,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: |
Expand All @@ -65,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
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20.9.0
v20.11.0
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20.9.0
FROM node:20.11.0

# nice clean home for our action files
RUN mkdir /action
Expand Down
190 changes: 130 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,23 @@ for you to use in subsequent actions containing version numbers.
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [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)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## 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 `<digest>` is any
[docker image digest you want here](https://github.com/users/codfish/packages/container/package/semantic-release-action).

### Basic Usage
## Usage

```yml
steps:
Expand Down Expand Up @@ -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 `<digest>` 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
Expand Down Expand Up @@ -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 |
| --------------------- | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 9 additions & 11 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 }}
15 changes: 12 additions & 3 deletions entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand Down Expand Up @@ -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 })) || [];
Expand Down

0 comments on commit 07170c8

Please sign in to comment.