htmlSanityCheck
htmlSanityCheck copied to clipboard
Introduce Container‑based GitHub Action
Summary
This PR adds a first‑class, Docker‑based GitHub Action for HTML Sanity Check (HSC) and a reusable container image published to GHCR. It also introduces CI jobs to build, test, and publish multi‑arch Docker images and a scheduled workflow that cleans up old, timestamped image versions from GHCR.
What’s included
- New GitHub Action backed by Docker image
action.ymlruns usingdocker://ghcr.io/aim42/hsc:v2with entrypoint'/hsc.sh'.- Single input
argsto pass through to the CLI (HscCommand).
- Reusable Docker image for independent, container‑based execution of HSC
- Dockerfile based on
eclipse-temurin:21-jre-alpine. - Copies shaded CLI JAR and lightweight
hsc.shentrypoint. - Multi‑arch builds (
linux/amd64,linux/arm64).
- Dockerfile based on
- CI workflow for build, test, and publish
.github/workflows/gradle-build.ymlnow:- Builds artifacts and runs existing tests.
- Pulls the branch‑tagged image, re‑tags as
v2, and executes the new Action end‑to‑end as part of CI. - Publishes Docker images to GHCR via Gradle’s Docker plugin, with optional extra tags via
workflow_dispatchinputadditional_tags.
- GHCR cleanup workflow
.github/workflows/cleanup-ghcr.ymlremoves old timestamped or stale SHA‑only image versions (default retention 14 days), while protectinglatestandv*tags.
Implementation Details
action.ymlruns.using: 'docker'with fixed imageghcr.io/aim42/hsc:v2andentrypoint: '/hsc.sh'.- Note: If the action’s image tag changes (e.g., to
v3), the test ingradle-build.ymlmust be updated accordingly (inline comment present).
htmlSanityCheck-cli/Dockerfile- Labels include
org.opencontainers.image.descriptionandversion(ARG‑driven) for provenance. - Uses
hsc.shto execjava -jar /hsc.jarwith passed arguments.
- Labels include
htmlSanityCheck-cli/build.gradle- Uses
com.fussionlabs.gradle.docker-pluginfor Buildx. - Tagging strategy (
dockerTags):- Always: timestamp
yyyyMMddHHmmssand sanitized branch name. - On
main: also pushv<major>(for the Action) andlatest. - Supports additional tags via
-Ddocker.image.additional.tags.
- Always: timestamp
- Multi‑arch push wired via
dockerBuildMulti;dockerPushdepends on it.
- Uses
.github/workflows/gradle-build.ymltest-gh-actionpulls the branch image, tags it locally asghcr.io/aim42/hsc:v2, and runs the Action from this repo with sample args to validate end‑to‑end behavior.publish-docker-imagesuses the Gradle taskdockerPushwith Buildx multi‑arch and GitHub Packages auth viaGITHUB_TOKEN.
.github/workflows/cleanup-ghcr.yml- Nightly (02:00 UTC) or manual.
- Deletes versions older than retention days when:
- Any timestamp tag (
yyyyMMddHHmmss) is older than cutoff, or - Only SHA‑like tags exist and version
created_at/updated_atis older than cutoff, or - No tags at all and older than cutoff.
- Any timestamp tag (
- Skips versions that contain
latestorv\d+tags. - Defaults to dry‑run on manual dispatch; can be overridden.
Usage
-
In GitHub Actions (recommended)
- name: HTML Sanity Check uses: aim42/htmlSanityCheck@<ref> with: args: >- -r build/gh-action-test-report integration-test/common/build/docs \ --exclude 'https://www\.baeldung\.com/.*' \ --fail-on-errors- Replace
<ref>with a tag, branch, or commit SHA of this repository. - The Action will run the Docker image
ghcr.io/aim42/hsc:v2under the hood.
- Replace
-
As a standalone Docker image
docker run --rm \ -v "$PWD:/work" \ -w /work \ ghcr.io/aim42/hsc:v2 \ -r build/hsc-report path/to/site \ --fail-on-errors
Why this change
- Provides a simple, consistent way to run HSC in CI without managing JDKs or local installs.
- Enables reproducible, containerized execution for local use and other CI systems.
- Keeps GHCR tidy by removing ephemeral, timestamped images after a retention period, saving storage and reducing clutter.
Backward compatibility
- No breaking changes to the core CLI.
- GitHub Action is new; consumers can adopt it incrementally.
Security and Permissions
- Docker images are published to GHCR using
GITHUB_TOKENwithpackages: write. - Cleanup workflow only runs on schedule for
main(or via manual dispatch) and skips protected tags (latest,v*).
Testing
- CI job
test-gh-actionvalidates the Action end‑to‑end using a locally retagged image matchingv2. - Artifacts and a simple report are uploaded for inspection.
Follow‑ups
- When releasing a new major, bump the Action image tag (e.g.,
v3) inaction.ymland the test workflow. - Optionally document the full CLI options in the project docs and link them from
action.yml.
Issues
- Contributes to #343
- Closes #369