From c008c2b1481d78f47a7d0d787118839f00175c4e Mon Sep 17 00:00:00 2001 From: Julian Blacher Date: Sun, 1 Nov 2026 02:29:44 -0300 Subject: [PATCH] Let the action follow a release line with @v0 and @v0.1 A major or minor ref (v0, v0.1), as the action's tag or the version input, installs the newest published vX.Y.Z release in that line. A new workflow moves those tags to each published release that is the newest in its line, and the Release workflow now only runs for vX.Y.Z tags so moving them does not start a release. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 4 ++- .github/workflows/version-tags.yml | 49 ++++++++++++++++++++++++++++++ CHANGELOG.md | 5 +++ CONTRIBUTING.md | 3 ++ README.md | 9 ++++-- action.yml | 32 ++++++++++++++----- 6 files changed, 90 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/version-tags.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9f49195..8833e3b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,7 +4,9 @@ name: Release # The result is a draft GitHub release; publish it by hand after review. on: push: - tags: ["v*"] + # Only version tags; the moving major and minor tags (v1, v1.2) are not + # releases. + tags: ["v[0-9]+.[0-9]+.[0-9]+*"] permissions: contents: write diff --git a/.github/workflows/version-tags.yml b/.github/workflows/version-tags.yml new file mode 100644 index 0000000..3f8db31 --- /dev/null +++ b/.github/workflows/version-tags.yml @@ -0,0 +1,49 @@ +name: Version tags + +# Keeps the major and minor tags (v1, v1.2) on the newest published release in +# their line, so "uses: devblac/docker-lint@v1" gets every compatible update. +# Publishing a patch for an older line leaves the newer lines' tags alone. +on: + release: + types: [published] + +permissions: + contents: write + +jobs: + tags: + if: ${{ !github.event.release.prerelease }} + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v7 + + - name: Move the major and minor tags + env: + TAG: ${{ github.event.release.tag_name }} + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + if ! printf '%s' "$TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then + echo "$TAG is not a vX.Y.Z release; leaving the version tags alone" + exit 0 + fi + + minor="${TAG%.*}" + major="${minor%.*}" + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + for line in "$major" "$minor"; do + newest="$(gh release list --exclude-drafts --exclude-pre-releases \ + --limit 1000 --json tagName --jq "[.[].tagName | select(startswith(\"$line.\")) + | select(test(\"^v[0-9]+\\\\.[0-9]+\\\\.[0-9]+\$\"))] + | sort_by(ltrimstr(\"v\") | split(\".\") | map(tonumber)) | last // empty")" + if [ "$newest" != "$TAG" ]; then + echo "$line stays on $newest" + continue + fi + # A release event checks out the release's tag, so GITHUB_SHA is its commit. + git tag --force --annotate "$line" --message "$line -> $TAG" "$GITHUB_SHA" + git push --force origin "refs/tags/$line" + echo "$line -> $TAG" + done diff --git a/CHANGELOG.md b/CHANGELOG.md index 36eac99..ebd9364 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Major and minor version tags for the GitHub Action: `@v0` and `@v0.1` follow + the newest release in their line and install that release of docker-lint, as + does `version: v0` + ## [0.1.1] - 2026-10-24 First published release. The Changed, Removed and Fixed sections describe diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6e876e6..5c87759 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -122,6 +122,9 @@ release, so nothing is public until a maintainer publishes it. 6. Publishing the release runs the Image workflow, which pushes `ghcr.io/devblac/docker-lint` for linux/amd64 and linux/arm64. The first time, make the package public in its settings on GitHub; packages start out private. + It also runs the Version tags workflow, which moves the major and minor tags + (`v0`, `v0.1`) to the release when it is the newest in their line. Never push + those tags by hand. ## Questions? diff --git a/README.md b/README.md index e09805b..f69c614 100644 --- a/README.md +++ b/README.md @@ -344,7 +344,7 @@ steps: |-------|---------|-------------| | `dockerfile` | `Dockerfile` | Files, directories or glob patterns to lint, one per line | | `config` | | Configuration file (default: `.docker-lint.yaml` at the repository root) | -| `version` | action's tag | docker-lint release to install: by default the one matching the action's tag (`@v0.1.1` installs v0.1.1), or the latest release when the action is used from a branch. Also `latest` or a tag such as `v0.1.1` | +| `version` | action's tag | docker-lint release to install: by default the one matching the action's tag (`@v0.1.1` installs v0.1.1, `@v0` the newest v0.x.y), or the latest release when the action is used from a branch. Also `latest`, a tag such as `v0.1.1` or a line such as `v0` | | `format` | `github` | Log output: `github` (annotations), `text`, `json` or `sarif` | | `strict` | `false` | Fail on warnings, not only on errors | | `quiet` | `false` | Hide informational findings | @@ -358,8 +358,11 @@ steps: | `exit-code` | docker-lint's exit code: `0` clean, `1` lint errors (or warnings with `strict`), `2` fatal error | | `sarif-file` | Path of the SARIF report, when one was written | -Pinning the action pins the linter: `@v0.1.1` installs docker-lint v0.1.1. When you pin the action to a commit -SHA, also set `version` to the matching tag; otherwise the latest release is installed. +Pinning the action pins the linter: `@v0.1.1` installs docker-lint v0.1.1. To get fixes and new rules +without editing the workflow, use `@v0` (or `@v0.1` for fixes only): these tags follow the newest release in +their line, and the action installs that release. Bear in mind that a new rule can fail a build that passed +before. When you pin the action to a commit SHA, also set `version` to the matching tag; otherwise the latest +release is installed. The action fails the step with docker-lint's exit code and exposes it as the `exit-code` output. A SARIF report is still written and uploaded when the lint fails, and covers every Dockerfile that could be parsed; diff --git a/action.yml b/action.yml index 655da53..0cd9be2 100644 --- a/action.yml +++ b/action.yml @@ -20,10 +20,11 @@ inputs: version: description: >- docker-lint release to use. By default, the release matching the tag the - action is used at (uses: devblac/docker-lint@v1.2.3 installs v1.2.3), or - the latest release when the action is used from a branch or commit. Also - accepts "latest", a tag such as "v0.1.1", or "source" to build the - action's own checkout (needs Go; used to test the action). + action is used at (uses: devblac/docker-lint@v1.2.3 installs v1.2.3, and + @v1 the newest v1.x.y), or the latest release when the action is used + from a branch or commit. Also accepts "latest", a tag such as "v0.1.1", a + line such as "v0" or "v0.1", or "source" to build the action's own + checkout (needs Go; used to test the action). default: "" format: description: >- @@ -95,12 +96,16 @@ runs: mkdir -p "$bin_dir" # Pinning the action pins the linter: by default, install the release - # whose tag the action is used at. The runner checks the action out - # under .../_actions///, which also gives the ref when - # github.action_ref is empty, as it is in some nested composite actions. + # whose tag the action is used at. A major or minor tag (v1, v1.2) + # installs the newest release in that line. The runner checks the action + # out under .../_actions///, which also gives the ref + # when github.action_ref is empty, as it is in some nested composite + # actions. + semver='^v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$' + line='^v[0-9]+(\.[0-9]+)?$' if [ -z "$VERSION" ]; then ref="${ACTION_REF:-$(basename "$ACTION_PATH")}" - if printf '%s' "$ref" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+([-+][0-9A-Za-z.-]+)?$'; then + if printf '%s' "$ref" | grep -Eq "$semver|$line"; then VERSION="$ref" else VERSION=latest @@ -115,6 +120,17 @@ runs: tag="$VERSION" if [ "$tag" = latest ]; then tag="$(gh release view --repo "$repo" --json tagName --jq .tagName)" + elif printf '%s' "$tag" | grep -Eq "$line"; then + # The prefix passed the check above, so it is safe inside the filter. + tag="$(gh release list --repo "$repo" --exclude-drafts --exclude-pre-releases \ + --limit 1000 --json tagName --jq "[.[].tagName | select(startswith(\"$tag.\")) + | select(test(\"^v[0-9]+\\\\.[0-9]+\\\\.[0-9]+\$\"))] + | sort_by(ltrimstr(\"v\") | split(\".\") | map(tonumber)) | last // empty")" + if [ -z "$tag" ]; then + echo "::error::docker-lint: no published release matches $VERSION" + exit 1 + fi + echo "docker-lint: $VERSION resolves to $tag" fi ext=tar.gz if [ "$os" = windows ]; then ext=zip; fi