Skip to content

feat: ✨ Add ability to change tag type #20

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
86 changes: 80 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ The following inputs are available:
`${{ github.ref }}` to get the ref that triggered the action. **REQUIRED**
- force_release: If `true`, the action will treat any build as a release and
tag the image with the appropriate tags. Default: `false`.
- is_scheduled: If `true`, the action will treat the build as a scheduled
build and tag the image with the appropriate tags. Default: `false`.
- schedule_pattern: the string to use for a tag for scheduled images.
Default: `nightly`.
- schedule_date_format: the date format to use for the scheduled image tag.
Default: `YYYYMMDD`.
- **DockerHub**
- dockerhub_image: The name of the image on DockerHub. Default:
`{ dockerhub username }/{ repository name }`.
Expand Down Expand Up @@ -242,6 +248,38 @@ The following outputs are available:
`false` otherwise.
- custom_image: The name of the image on the custom registry.

## Image Tags

### All Builds

All builds -- release, scheduled, or otherwise -- will be tagged with the short
and long SHA hashes of the commit that triggered the build. The short SHA is
the first 7 characters of the SHA hash, and the long SHA is the full SHA hash.

### Release Builds

When `force_release` is `true` or when the tag associated with the build starts
with `v[1-9]`, the action will consider this a "release" build and will tag the
image with semver tags plus the `latest` tag.

### Scheduled Builds

When `is_scheduled` is `true`, the action will consider this a "scheduled"
build and will tag the image with the `schedule_pattern` and give it a date
formatted with the `schedule_date_format` format.

The default `schedule_pattern` is `nightly`, so the image will be tagged with
`nightly`.

The default `schedule_date_format` is `YYYYMMDD`, so the image will be tagged
with the result of calling `date 'YYYYMMDD'`.

### Non-scheduled Builds

When a build is not a scheduled build (e.g., it's a release build), the action
will add the `edge` tag to the image. The `edge` tag is used to indicate that
the image is a "development" build and is not considered a release.

## Examples

### Build and Publish Image to DockerHub
Expand Down Expand Up @@ -411,12 +449,12 @@ Want to be sure? Check the code. It's all there. Here's a link:

[https://github.com/wesley-dean/publish_container/blob/main/action.yml](https://github.com/wesley-dean/publish_container/blob/main/action.yml)

#### Release tags
#### Release Tags

Images associated with releases are given the following tags:

- latest
- edge
- `latest`
- `edge`
- `{major}.{minor}.{patch}`
- `{major}.{minor}`
- `{major}`
Expand All @@ -435,14 +473,50 @@ So, if the tag is `v1.2.3`, the image will be tagged with the following:

(the SHA hashes are made up)

#### Non-release tags
### Scheduled Tags

Images that are not associated with a release are given the following tags:
Images associated with scheduled builds are given the following tags:

- edge
- `nightly` (or whatever the `schedule_pattern` is set to)
- `{{ date 'YYYYMMDD' }}` (or whatever the `schedule_date_format` is set to)
- `{short sha}`
- `{long sha}`

The `schedule_date_format` is the Moment.js date format string to use. The
many strings Moment.js supports are documented here:

[Format](https://momentjs.com/docs/#/displaying/format/)

Dates are specified by the UTC standard.

So, if the schedule pattern is `nightly` and the date format is `YYYYMMDD`,
the image will be tagged with the following (assuming the date is 5th of April
in the year 2025):

- nightly
- 20250405
- abc123
- abc123def456aaa7890123456789abcdef012345

(the SHA hashes are made up)

#### Non-release, non-scheduled tags

Images that are not associated with a release and are not scheduled will given
the following tags:

- `edge`
- `{short sha}`
- `{long sha}`

So, a non-release, non-scheduled image will be tagged with the following:

- edge
- abc123
- abc123def456aaa7890123456789abcdef012345

(the SHA hashes are made up)

### Image descriptions

For images on DockerHub, Quay, and Harbor, the action updates the description
Expand Down
41 changes: 38 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ inputs:
required: false
default: false

is_scheduled:
description: "Whether or not this is a scheduled run"
required: false
default: false

schedule_pattern:
description: "Handlebars-formatted string to use for the scheduled builds"
required: false
default: "nightly"

schedule_date_format:
description: "Date format to use for the scheduled builds"
required: false
default: "YYYYMMDD"

platforms:
description: "Platforms to build for"
required: false
Expand Down Expand Up @@ -187,6 +202,9 @@ runs:
inputs_context: ${{ inputs.context }}
inputs_dockerfile: ${{ inputs.dockerfile }}
inputs_force_release: ${{ inputs.force_release }}
inputs_is_scheduled: ${{ inputs.is_scheduled }}
inputs_schedule_pattern: ${{ inputs.schedule_pattern }}
inputs_schedule_date_format: ${{ inputs.schedule_date_format }}

inputs_dockerhub_username: ${{ inputs.dockerhub_username }}
inputs_dockerhub_token: ${{ inputs.dockerhub_token }}
Expand Down Expand Up @@ -229,6 +247,9 @@ runs:
dockerfile="${inputs_dockerfile}"

force_release="${inputs_force_release}"
is_scheduled="${inputs_is_scheduled}"
schedule_pattern="${inputs_schedule_pattern}"
schedule_date_format="${inputs_schedule_date_format}"

dockerhub_username="${inputs_dockerhub_username}"
dockerhub_token="${inputs_dockerhub_token}"
Expand Down Expand Up @@ -262,13 +283,25 @@ runs:
custom_registry="${inputs_custom_registry}"

echo -n "is_release="
if [[ "${github_ref}" =~ refs/tags/v[1-9].* ]] \
|| [[ "${force_release:-false}" =~ [YyTt].* ]] ; then
if [[ "${force_release:-false}" =~ [YyTt].* ]] \
|| ( [[ "${github_ref}" =~ refs/tags/v[1-9].* ]] \
&& [[ "${is_scheduled:-false}" =~ [NnFf].* ]] ) ; then
echo "true"
else
echo "false"
fi

echo -n "is_scheduled="
if [[ "${is_scheduled:-false}" =~ [YyTt].* ]] \
&& [[ ! "${force_release:-false}" =~ [YyTt].* ]] ; then
echo "true"
else
echo "false"
fi

echo "schedule_pattern=${schedule_pattern:-nightly}"
echo "schedule_date_format=${schedule_date_format:-YYYYMMDD}"

echo "platforms=${platforms:-linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6}"
echo "context=${context:-.}"
echo "dockerfile=${dockerfile:-${context}/Dockerfile}"
Expand Down Expand Up @@ -417,7 +450,9 @@ runs:
type=semver,pattern={{version}},enable=${{ steps.customvars.outputs.is_release == 'true' }}
type=semver,pattern={{major}},enable=${{ steps.customvars.outputs.is_release == 'true' }}
type=semver,pattern={{major}}.{{minor}},enable=${{ steps.customvars.outputs.is_release == 'true' }}
type=edge,branch=main
type=schedule,pattern=${{ steps.customvars.outputs.schedule_pattern }},enable=${{ steps.customvars.outputs.is_scheduled == 'true' }}
type=schedule,pattern={{ date '${{ steps.customvars.outputs.schedule_date_format }}' }},enable=${{ steps.customvars.outputs.is_scheduled == 'true' }}
type=edge,branch=main,enable=${{ steps.customvars.outputs.is_scheduled == 'false' }}
type=sha
type=sha,format=long
env:
Expand Down