Skip to content
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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ trim_trailing_whitespace = false

[{*,*.dist}.{yml,yaml}]
indent_size = 2

[*.{hcl,sh}]
indent_size = 2
5 changes: 5 additions & 0 deletions .github/actionlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# actionlint 1.7.12 predates these GitHub-hosted runner labels.
self-hosted-runner:
labels:
- ubuntu-26.04
- ubuntu-26.04-arm
11 changes: 11 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@ jobs:
uses: docker://rhysd/actionlint:latest
with:
args: -color

bake-tests:
name: Bake tests
runs-on: ubuntu-26.04
steps:
- name: Checkout
uses: actions/checkout@v7
with:
persist-credentials: false
- name: Run the specs.hcl fixture tests
run: bake/test/run.sh
8 changes: 8 additions & 0 deletions Taskfile.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ tasks:
--volume "{{.ROOT_DIR}}:/workdir"
--workdir /workdir
rhysd/actionlint:{{.ACTIONLINT_TAG_VERSION}}

test:
desc: Run the bake/specs.hcl fixture tests
cmd: bake/test/run.sh

test:update:
desc: Rewrite the expected output of the bake/specs.hcl fixture tests
cmd: bake/test/run.sh --update
160 changes: 160 additions & 0 deletions bake/specs.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Shared tag, label and annotation rules for images built with specsnl/github-actions bake.yml.
#
# Vendored: copy this file into the consuming repository unchanged and update it when you move bake.yml to a new
# version; the workflow warns when the copy differs. Build locally with:
#
# docker buildx bake -f specs.hcl -f docker-bake.hcl
#
# The variables below are set by bake.yml's plan job. The defaults are what a local build gets.

variable "VERSION" {
default = "dev"
}

# The GitHub event name, i.e. "push", "pull_request", "schedule" or "workflow_dispatch". Empty for a local build.
variable "EVENT" {
default = ""
}

# "tag" or "branch".
variable "REF_TYPE" {
default = ""
}

# The branch or tag name.
variable "REF_NAME" {
default = ""
}

variable "PR_NUMBER" {
default = ""
}

# The tag a workflow_dispatch run publishes under, already lowercased.
variable "DISPATCH_TAG" {
default = "latest"
}

# "true" on a tag push whose version has no "-" in it. Only then do the moving tags (1.2, 1, latest) move.
variable "IS_STABLE" {
default = "false"
}

variable "REVISION" {
default = ""
}

variable "SOURCE" {
default = ""
}

variable "CREATED" {
default = ""
}

# The repository's name, description and SPDX license, the fallbacks for the title, description and licenses labels.
variable "REPOSITORY_NAME" {
default = ""
}

variable "REPOSITORY_DESCRIPTION" {
default = ""
}

variable "LICENSES" {
default = ""
}

# The full tag list for a target: every image name crossed with the tags this run publishes. A non-empty variant is
# appended as a suffix ("1.2.3-alpine"), and on a stable release the bare variant name takes the place of "latest".
#
# tags = specs_tags(["ghcr.io/specsnl/specs-cli"], "alpine")
function "specs_tags" {
params = [images, variant]
result = flatten([
for image in images : [
for tag in specs_tag_names(variant) : "${lower(image)}:${tag}"
]
])
}

# The tags without the image name, see specs_tags.
function "specs_tag_names" {
params = [variant]
result = concat(
[for tag in _specs_base_tags() : _specs_sanitize(variant == "" ? tag : "${tag}-${variant}")],
EVENT == "push" && REF_TYPE == "tag" && IS_STABLE == "true" ? [variant == "" ? "latest" : variant] : [],
)
}

# The org.opencontainers.image.* labels: version, revision, source, url, created, licenses, and the given title and
# description. An empty title or description falls back to the repository's name or description. Empty values are
# left out rather than written as "".
#
# labels = specs_labels("PHP 8.4", "")
function "specs_labels" {
params = [title, description]
result = {
for key, value in {
"org.opencontainers.image.version" = VERSION
"org.opencontainers.image.revision" = REVISION
"org.opencontainers.image.source" = SOURCE
"org.opencontainers.image.url" = SOURCE
"org.opencontainers.image.created" = CREATED
"org.opencontainers.image.licenses" = LICENSES
"org.opencontainers.image.title" = title != "" ? title : REPOSITORY_NAME
"org.opencontainers.image.description" = description != "" ? description : REPOSITORY_DESCRIPTION
} : key => value if value != ""
}
}

# The same values as specs_labels, as annotations on the platform image manifest. The publish job copies them onto the
# index and its descriptors.
#
# annotations = specs_annotations("PHP 8.4", "")
function "specs_annotations" {
params = [title, description]
result = [for key, value in specs_labels(title, description) : "manifest:${key}=${value}"]
}

function "_specs_base_tags" {
params = []
result = (
EVENT == "" ? ["local"] :
EVENT == "push" && REF_TYPE == "tag" ? _specs_release_tags() :
EVENT == "push" && REF_TYPE == "branch" ? [REF_NAME] :
EVENT == "pull_request" || EVENT == "pull_request_target" ? ["pr-${PR_NUMBER}"] :
EVENT == "schedule" ? ["nightly"] :
EVENT == "workflow_dispatch" ? [DISPATCH_TAG] :
[]
)
}

# 1.2.3, plus 1.2 unless it is 0.0.x and 1 unless it is 0.x. A prerelease, or a version that isn't semver, publishes
# only itself.
function "_specs_release_tags" {
params = []
result = (
IS_STABLE == "true" && length(_specs_semver()) == 1 ? _specs_semver_tags(_specs_semver()[0]) : [VERSION]
)
}

function "_specs_semver_tags" {
params = [v]
result = concat(
["${v[0]}.${v[1]}.${v[2]}"],
v[0] == "0" && v[1] == "0" ? [] : ["${v[0]}.${v[1]}"],
v[0] == "0" ? [] : [v[0]],
)
}

function "_specs_semver" {
params = []
result = regexall("^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$", VERSION)
}

# A tag may only contain [A-Za-z0-9_.-], may not start with "." or "-", and is at most 128 characters.
function "_specs_sanitize" {
params = [tag]
result = substr(regex_replace(regex_replace(tag, "[^A-Za-z0-9_.-]", "-"), "^[.-]+", ""), 0, 128)
}
10 changes: 10 additions & 0 deletions bake/test/cases/branch.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
EVENT=push
REF_TYPE=branch
REF_NAME=Feature/Some_thing
VERSION=Feature/Some_thing
REVISION=0123456789abcdef0123456789abcdef01234567
SOURCE=https://github.com/specsnl/example
CREATED=2026-11-09T12:00:00Z
REPOSITORY_NAME=example
REPOSITORY_DESCRIPTION=An example repository
LICENSES=MIT
113 changes: 113 additions & 0 deletions bake/test/cases/branch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"builder": {
"annotations": [
"manifest:org.opencontainers.image.created=2026-11-09T12:00:00Z",
"manifest:org.opencontainers.image.description=An example repository",
"manifest:org.opencontainers.image.licenses=MIT",
"manifest:org.opencontainers.image.revision=0123456789abcdef0123456789abcdef01234567",
"manifest:org.opencontainers.image.source=https://github.com/specsnl/example",
"manifest:org.opencontainers.image.title=PHP 8.4 builder",
"manifest:org.opencontainers.image.url=https://github.com/specsnl/example",
"manifest:org.opencontainers.image.version=Feature/Some_thing"
],
"labels": {
"org.opencontainers.image.created": "2026-11-09T12:00:00Z",
"org.opencontainers.image.description": "An example repository",
"org.opencontainers.image.licenses": "MIT",
"org.opencontainers.image.revision": "0123456789abcdef0123456789abcdef01234567",
"org.opencontainers.image.source": "https://github.com/specsnl/example",
"org.opencontainers.image.title": "PHP 8.4 builder",
"org.opencontainers.image.url": "https://github.com/specsnl/example",
"org.opencontainers.image.version": "Feature/Some_thing"
},
"tags": [
"ghcr.io/specsnl/php84/builder:Feature-Some_thing"
]
},
"cli-alpine": {
"args": {
"SPECS_VERSION": "Feature/Some_thing"
},
"labels": {
"org.opencontainers.image.created": "2026-11-09T12:00:00Z",
"org.opencontainers.image.description": "An example repository",
"org.opencontainers.image.licenses": "MIT",
"org.opencontainers.image.revision": "0123456789abcdef0123456789abcdef01234567",
"org.opencontainers.image.source": "https://github.com/specsnl/example",
"org.opencontainers.image.title": "specs-cli",
"org.opencontainers.image.url": "https://github.com/specsnl/example",
"org.opencontainers.image.version": "Feature/Some_thing"
},
"tags": [
"ghcr.io/specsnl/specs-cli:Feature-Some_thing-alpine"
]
},
"cli-debian": {
"args": {
"SPECS_VERSION": "Feature/Some_thing"
},
"labels": {
"org.opencontainers.image.created": "2026-11-09T12:00:00Z",
"org.opencontainers.image.description": "An example repository",
"org.opencontainers.image.licenses": "MIT",
"org.opencontainers.image.revision": "0123456789abcdef0123456789abcdef01234567",
"org.opencontainers.image.source": "https://github.com/specsnl/example",
"org.opencontainers.image.title": "specs-cli",
"org.opencontainers.image.url": "https://github.com/specsnl/example",
"org.opencontainers.image.version": "Feature/Some_thing"
},
"tags": [
"ghcr.io/specsnl/specs-cli:Feature-Some_thing"
]
},
"runtime": {
"annotations": [
"manifest:org.opencontainers.image.created=2026-11-09T12:00:00Z",
"manifest:org.opencontainers.image.description=PHP 8.4 runtime",
"manifest:org.opencontainers.image.licenses=MIT",
"manifest:org.opencontainers.image.revision=0123456789abcdef0123456789abcdef01234567",
"manifest:org.opencontainers.image.source=https://github.com/specsnl/example",
"manifest:org.opencontainers.image.title=PHP 8.4",
"manifest:org.opencontainers.image.url=https://github.com/specsnl/example",
"manifest:org.opencontainers.image.version=Feature/Some_thing"
],
"labels": {
"org.opencontainers.image.created": "2026-11-09T12:00:00Z",
"org.opencontainers.image.description": "PHP 8.4 runtime",
"org.opencontainers.image.licenses": "MIT",
"org.opencontainers.image.revision": "0123456789abcdef0123456789abcdef01234567",
"org.opencontainers.image.source": "https://github.com/specsnl/example",
"org.opencontainers.image.title": "PHP 8.4",
"org.opencontainers.image.url": "https://github.com/specsnl/example",
"org.opencontainers.image.version": "Feature/Some_thing"
},
"tags": [
"ghcr.io/specsnl/php84:Feature-Some_thing"
]
},
"utils": {
"annotations": [
"manifest:org.opencontainers.image.created=2026-11-09T12:00:00Z",
"manifest:org.opencontainers.image.description=An example repository",
"manifest:org.opencontainers.image.licenses=MIT",
"manifest:org.opencontainers.image.revision=0123456789abcdef0123456789abcdef01234567",
"manifest:org.opencontainers.image.source=https://github.com/specsnl/example",
"manifest:org.opencontainers.image.title=example",
"manifest:org.opencontainers.image.url=https://github.com/specsnl/example",
"manifest:org.opencontainers.image.version=Feature/Some_thing"
],
"labels": {
"org.opencontainers.image.created": "2026-11-09T12:00:00Z",
"org.opencontainers.image.description": "An example repository",
"org.opencontainers.image.licenses": "MIT",
"org.opencontainers.image.revision": "0123456789abcdef0123456789abcdef01234567",
"org.opencontainers.image.source": "https://github.com/specsnl/example",
"org.opencontainers.image.title": "example",
"org.opencontainers.image.url": "https://github.com/specsnl/example",
"org.opencontainers.image.version": "Feature/Some_thing"
},
"tags": [
"ghcr.io/specsnl/utils:Feature-Some_thing"
]
}
}
11 changes: 11 additions & 0 deletions bake/test/cases/dispatch.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
EVENT=workflow_dispatch
REF_TYPE=branch
REF_NAME=main
DISPATCH_TAG=testing
VERSION=testing
REVISION=0123456789abcdef0123456789abcdef01234567
SOURCE=https://github.com/specsnl/example
CREATED=2026-11-09T12:00:00Z
REPOSITORY_NAME=example
REPOSITORY_DESCRIPTION=An example repository
LICENSES=MIT
Loading