diff --git a/.github/scripts/publish-gh-pages.sh b/.github/scripts/publish-gh-pages.sh new file mode 100755 index 0000000..7a9a4c2 --- /dev/null +++ b/.github/scripts/publish-gh-pages.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Copy Artifact Hub metadata into a gh-pages checkout, then commit and push +# every pending change (chart package, index.yaml, metadata) as one commit. + +gh_pages_dir="${1:?usage: publish-gh-pages.sh [commit-message]}" +commit_message="${2:-Publish Artifact Hub repository metadata}" +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" + +install -m 0644 "${repo_root}/artifacthub-repo.yml" "${gh_pages_dir}/artifacthub-repo.yml" +install -m 0644 /dev/null "${gh_pages_dir}/.nojekyll" + +cd "${gh_pages_dir}" +git config user.name "${GITHUB_ACTOR}" +git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" +git add -A +if git diff --cached --quiet; then + echo "gh-pages is already up to date" + exit 0 +fi +git commit -m "${commit_message}" +git push origin gh-pages diff --git a/.github/workflows/chart-release.yaml b/.github/workflows/chart-release.yaml deleted file mode 100644 index 7a8e851..0000000 --- a/.github/workflows/chart-release.yaml +++ /dev/null @@ -1,73 +0,0 @@ -name: Chart Release - -on: - push: - branches: [ main ] - paths: - - .github/workflows/chart-release.yaml - - artifacthub-repo.yml - - charts/** - workflow_dispatch: - -permissions: - contents: write - -jobs: - release: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v6 - with: - fetch-depth: 0 - - - name: Configure Git - run: | - git config user.name "${GITHUB_ACTOR}" - git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" - - - name: Run chart-releaser - uses: helm/chart-releaser-action@v1.7.0 - with: - charts_dir: charts - pages_branch: gh-pages - packages_with_index: true - skip_existing: true - env: - CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - - - name: Publish Artifact Hub repository metadata - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - set -euo pipefail - - if ! git ls-remote --exit-code --heads origin gh-pages >/dev/null 2>&1; then - echo "gh-pages branch does not exist yet; skipping artifacthub-repo.yml publication" - exit 0 - fi - - tmp_dir="$(mktemp -d)" - trap 'rm -rf "${tmp_dir}"' EXIT - - git clone --branch gh-pages --single-branch \ - "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" \ - "${tmp_dir}" - - # GitHub Pages should serve the Helm repo as static files, not through Jekyll. - install -m 0644 /dev/null "${tmp_dir}/.nojekyll" - install -m 0644 artifacthub-repo.yml "${tmp_dir}/artifacthub-repo.yml" - - cd "${tmp_dir}" - if git diff --quiet -- .nojekyll artifacthub-repo.yml; then - echo "artifacthub-repo.yml already up to date on gh-pages" - exit 0 - fi - - git config user.name "${GITHUB_ACTOR}" - git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" - git add .nojekyll - git add artifacthub-repo.yml - git commit -m "Publish Artifact Hub repository metadata" - git push origin gh-pages diff --git a/.github/workflows/build-publish.yaml b/.github/workflows/ci.yaml similarity index 87% rename from .github/workflows/build-publish.yaml rename to .github/workflows/ci.yaml index 22afddd..12950b5 100644 --- a/.github/workflows/build-publish.yaml +++ b/.github/workflows/ci.yaml @@ -43,3 +43,6 @@ jobs: - name: Helm template run: make helm-template + + - name: Build container image + run: docker build --platform linux/amd64 -t readability-js:ci . diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index c0f4cc9..b023c49 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -9,43 +9,19 @@ on: jobs: CodeQL-Build: - # CodeQL runs on ubuntu-latest, windows-latest, and macos-latest runs-on: ubuntu-latest - permissions: - # required for all workflows security-events: write - - # only required for workflows in private repositories actions: read contents: read - steps: - name: Checkout repository uses: actions/checkout@v6 - # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v4 - # Override language selection by uncommenting this and choosing your languages - # with: - # languages: go, javascript, csharp, python, cpp, java, ruby - - # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). - # If this step fails, then you should remove it and run the build manually (see below). - - name: Autobuild - uses: github/codeql-action/autobuild@v4 - - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - # âœī¸ If the Autobuild fails above, remove it and uncomment the following - # three lines and modify them (or add more) to build your code if your - # project uses a compiled language - - #- run: | - # make bootstrap - # make release + with: + languages: javascript-typescript, actions - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v4 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c7f6954..683f356 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -4,70 +4,221 @@ on: push: tags: - "v*" + workflow_dispatch: + +permissions: + contents: read + +env: + IMAGE_NAME: phpdockerio/readability-js-server jobs: - publish: + verify: + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest permissions: - contents: write - env: - IMAGE_NAME: phpdockerio/readability-js-server - + contents: read + outputs: + version: ${{ steps.meta.outputs.version }} + major: ${{ steps.meta.outputs.major }} + minor: ${{ steps.meta.outputs.minor }} steps: - name: Checkout uses: actions/checkout@v6 with: fetch-depth: 0 - - name: Set up QEMU - uses: docker/setup-qemu-action@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 - - - name: Derive release metadata + - name: Validate tag and chart versions id: meta run: | - TAG_NAME="${GITHUB_REF_NAME}" - VERSION="${TAG_NAME#v}" - - if [ "${VERSION}" = "${TAG_NAME}" ]; then - echo "Tag must start with v" >&2 + set -euo pipefail + tag="${GITHUB_REF_NAME}" + if ! printf '%s' "${tag}" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then + echo "Tag ${tag} must match vMAJOR.MINOR.PATCH" >&2 exit 1 fi + version="${tag#v}" + IFS='.' read -r major minor _patch <<< "${version}" - IFS='.' read -r MAJOR MINOR PATCH <&2 + tag_commit="$(git rev-parse "${GITHUB_REF_NAME}^{commit}")" + git fetch --no-tags origin main + if ! git merge-base --is-ancestor "${tag_commit}" origin/main; then + echo "Tag commit ${tag_commit} is not on main" >&2 exit 1 fi + chart_file="charts/readability-js-server/Chart.yaml" + chart_version="$(awk '$1 == "version:" { print $2; exit }' "${chart_file}")" + chart_app_version="$(awk '$1 == "appVersion:" { print $2; exit }' "${chart_file}" | tr -d '"')" + if [ "${chart_version}" != "${version}" ] || [ "${chart_app_version}" != "${version}" ]; then + echo "Chart.yaml version (${chart_version}) and appVersion (${chart_app_version}) must both equal ${version}" >&2 + exit 1 + fi { - echo "version=${VERSION}" - echo "major=${MAJOR}" - echo "minor=${MINOR}" - echo "tags=${IMAGE_NAME}:latest,${IMAGE_NAME}:${VERSION},${IMAGE_NAME}:${MAJOR}.${MINOR},${IMAGE_NAME}:${MAJOR}" + echo "version=${version}" + echo "major=${major}" + echo "minor=${minor}" } >> "${GITHUB_OUTPUT}" - - name: Login to DockerHub + - name: Set up Node.js + uses: actions/setup-node@v5 + with: + node-version: 24 + cache: npm + + - name: Set up Helm + uses: azure/setup-helm@v4 + with: + version: v3.16.3 + + - name: Install dependencies + run: npm ci + + - name: Lint + run: npm run lint + + - name: Test + run: npm test + + - name: Helm lint + run: make helm-lint + + - name: Helm template + run: make helm-template + + image: + needs: verify + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 + + - name: Login to Docker Hub uses: docker/login-action@v4 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build & push container image + - name: Build and push container image uses: docker/build-push-action@v7 with: context: . platforms: linux/amd64,linux/arm64 pull: true push: true - tags: ${{ steps.meta.outputs.tags }} + tags: | + ${{ env.IMAGE_NAME }}:latest + ${{ env.IMAGE_NAME }}:${{ needs.verify.outputs.version }} + ${{ env.IMAGE_NAME }}:${{ needs.verify.outputs.major }}.${{ needs.verify.outputs.minor }} + ${{ env.IMAGE_NAME }}:${{ needs.verify.outputs.major }} + cache-from: type=gha + cache-to: type=gha,mode=max + + chart: + needs: [image, verify] + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + permissions: + contents: write + concurrency: + group: gh-pages-publish + cancel-in-progress: false + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Set up Helm + uses: azure/setup-helm@v4 + with: + version: v3.16.3 + + - name: Clone gh-pages + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -euo pipefail + git clone --branch gh-pages --single-branch \ + "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" \ + "${RUNNER_TEMP}/gh-pages" + - name: Publish chart to gh-pages + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION: ${{ needs.verify.outputs.version }} + GH_PAGES: ${{ runner.temp }}/gh-pages + run: | + set -euo pipefail + index_file="${GH_PAGES}/index.yaml" + if [ ! -f "${index_file}" ]; then + echo "gh-pages/index.yaml is missing; cannot publish the Helm repository" >&2 + exit 1 + fi + + if awk -v want="${VERSION}" '$1 == "version:" && $2 == want { found = 1 } END { exit found ? 0 : 1 }' "${index_file}"; then + echo "Chart ${VERSION} is already in index.yaml; skipping packaging and publication" + else + package_dir="${RUNNER_TEMP}/chart-package" + rm -rf "${package_dir}" + mkdir -p "${package_dir}" + helm package charts/readability-js-server -d "${package_dir}" + test -f "${package_dir}/readability-js-server-${VERSION}.tgz" + helm repo index "${package_dir}" --merge "${index_file}" + install -m 0644 "${package_dir}/readability-js-server-${VERSION}.tgz" "${GH_PAGES}/readability-js-server-${VERSION}.tgz" + install -m 0644 "${package_dir}/index.yaml" "${index_file}" + fi + ./.github/scripts/publish-gh-pages.sh "${GH_PAGES}" "Publish Helm chart ${VERSION}" + + release: + needs: chart + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + permissions: + contents: write + steps: - name: Create GitHub Release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: gh release create "${GITHUB_REF_NAME}" --generate-notes --verify-tag + GH_REPO: ${{ github.repository }} + run: | + set -euo pipefail + if gh release view "${GITHUB_REF_NAME}" >/dev/null 2>&1; then + echo "Release ${GITHUB_REF_NAME} already exists; leaving it unchanged" + else + gh release create "${GITHUB_REF_NAME}" --generate-notes --verify-tag + fi + + metadata: + if: github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + permissions: + contents: write + concurrency: + group: gh-pages-publish + cancel-in-progress: false + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Clone gh-pages + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -euo pipefail + git clone --branch gh-pages --single-branch \ + "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" \ + "${RUNNER_TEMP}/gh-pages" + + - name: Publish Artifact Hub metadata + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_PAGES: ${{ runner.temp }}/gh-pages + run: ./.github/scripts/publish-gh-pages.sh "${GH_PAGES}" "Publish Artifact Hub repository metadata" diff --git a/AGENTS.md b/AGENTS.md index aec8aa0..1c6d1d4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -22,7 +22,7 @@ The Makefile mirrors those workflows with `make install`, `make start`, `make lint`, `make lint-fix`, `make helm-lint`, `make helm-template`, `make helm-verify`, `make build-container`, `make run-container`, `make release-tag`, and `make example-request`. -Release publishing is tag-driven: create a matching `vX.Y.Z` git tag and push it to trigger Docker publish plus GitHub Release creation. The service version is no longer stored in `package.json`. +Release publishing is tag-driven. Pushing one strict `vX.Y.Z` tag runs a single workflow that publishes, in order: Docker images, the Helm chart package and `index.yaml` on `gh-pages`, the Artifact Hub metadata (`artifacthub-repo.yml` and `.nojekyll`), then the GitHub Release with generated notes. The tag commit must be on `main`, and `charts/readability-js-server/Chart.yaml` `version` and `appVersion` must both equal the tag without the `v` prefix. Merging to `main` publishes nothing. A manual `workflow_dispatch` run republishes only the Artifact Hub metadata to `gh-pages`. The service version is no longer stored in `package.json`. ## Testing expectations diff --git a/Makefile b/Makefile index d0c6292..53c4f3a 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ lint-fix: npm run lint:fix HELM_CHART ?= charts/readability-js-server +CHART_FILE ?= $(HELM_CHART)/Chart.yaml HELM_RELEASE_NAME ?= readability-js-server helm-lint: @@ -39,6 +40,29 @@ release-tag: echo "Usage: make release-tag VERSION=x.y.z"; \ exit 1; \ fi + @if ! printf '%s\n' "$(VERSION)" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$$'; then \ + echo "VERSION '$(VERSION)' is not strict MAJOR.MINOR.PATCH (digits only)"; \ + exit 1; \ + fi + @if [ -n "$$(git status --porcelain)" ]; then \ + echo "Working tree is dirty; commit or stash changes before tagging"; \ + exit 1; \ + fi + @git fetch origin main + @if [ "$$(git rev-parse HEAD)" != "$$(git rev-parse origin/main)" ]; then \ + echo "HEAD does not match origin/main; check out main and pull before tagging"; \ + exit 1; \ + fi + @chart_version="$$(awk '$$1 == "version:" { print $$2; exit }' $(CHART_FILE))"; \ + chart_app_version="$$(awk '$$1 == "appVersion:" { print $$2; exit }' $(CHART_FILE) | tr -d '"')"; \ + if [ "$$chart_version" != "$(VERSION)" ]; then \ + echo "$(CHART_FILE) version '$$chart_version' does not match VERSION $(VERSION)"; \ + exit 1; \ + fi; \ + if [ "$$chart_app_version" != "$(VERSION)" ]; then \ + echo "$(CHART_FILE) appVersion '$$chart_app_version' does not match VERSION $(VERSION)"; \ + exit 1; \ + fi git tag v$(VERSION) @echo "Created tag v$(VERSION). Push it with: git push origin v$(VERSION)" diff --git a/README.md b/README.md index 3400138..ab38b31 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ make install make start ``` -Release versions come from the git tag (`vX.Y.Z`). To publish a release, create a `vX.Y.Z` tag and push it. The release workflow publishes Docker images for `X.Y.Z`, `X.Y`, `X`, and `latest`, and creates the matching GitHub Release with generated notes. +Release versions come from the git tag (`vX.Y.Z`). Pushing one tag publishes Docker images for `X.Y.Z`, `X.Y`, `X`, and `latest`, the Helm chart on `gh-pages`, the Artifact Hub metadata, and the GitHub Release with generated notes. Nothing publishes when a change merges to `main`. ## Helm chart @@ -158,15 +158,23 @@ Artifact Hub should reference the external Helm repository URL `https://phpdocke ## Release and versioning -Docker image publishing remains tag-driven. Create the matching `vX.Y.Z` tag and push it to publish the container image and GitHub Release. +Publishing runs from a single workflow triggered by one strict `vX.Y.Z` tag (`^v[0-9]+\.[0-9]+\.[0-9]+$`, no pre-release suffixes). The tag commit must be on `main`, and `charts/readability-js-server/Chart.yaml` `version` and `appVersion` must both equal the tag without the `v` prefix. -Helm chart publishing is separate and runs from chart changes on `master` or an explicit manual trigger. It packages changed charts from `charts/`, updates the GitHub Pages repository on `gh-pages`, and publishes `artifacthub-repo.yml` next to `index.yaml` for Artifact Hub. +Pushing the tag publishes, in order: + +- Docker images for `X.Y.Z`, `X.Y`, `X`, and `latest`. +- The Helm chart package and `index.yaml` on `gh-pages`. +- The Artifact Hub metadata (`artifacthub-repo.yml` and `.nojekyll`) on `gh-pages`. +- The GitHub Release with generated notes. + +Merging to `main` publishes nothing. A manual `workflow_dispatch` run of the release workflow republishes only the Artifact Hub metadata to `gh-pages`; it never builds an image or a chart package. + +`make release-tag VERSION=X.Y.Z` only creates the tag. It refuses to run unless the working tree is clean, `HEAD` matches `origin/main`, `VERSION` is a strict `MAJOR.MINOR.PATCH` value, and `Chart.yaml` `version` and `appVersion` already match. Push the tag to publish. For the chart itself: -- Bump `charts/readability-js-server/Chart.yaml` `version` for any chart package change, including templates, defaults, README content, metadata, or publishing annotations. -- Bump `appVersion` only when the chart's default application image tag changes. -- When the default application image tag changes, bump both `version` and `appVersion`. +- `version` and `appVersion` move together, and both equal the release tag without the `v` prefix. +- A chart-only change still needs a new patch tag, with both `Chart.yaml` fields bumped. ## Testing @@ -219,7 +227,7 @@ docker run --rm -p 3000:3000 readability-js The image is based on `node:24-alpine`, installs production dependencies only, and runs the service as a non-root user. -CI on pull requests and pushes to `master` runs lint, tests, and Helm chart verification. Container publishing happens from the tag-triggered release workflow. +CI on pull requests and pushes to `main` runs lint, tests, Helm chart verification, and an amd64 container build. Publishing happens only from the tag-triggered release workflow. For Docker Compose setup, see [`examples/compose.yaml`](examples/compose.yaml). That example publishes port `3000` and checks `GET /healthz` from inside the container using the `node` runtime that ships in the published image. diff --git a/charts/readability-js-server/README.md b/charts/readability-js-server/README.md index 8ba3a3c..68fa17f 100644 --- a/charts/readability-js-server/README.md +++ b/charts/readability-js-server/README.md @@ -73,14 +73,12 @@ The chart exposes the settings most clusters need without requiring a fork: ## Versioning policy -Chart and application versions are intentionally separate: +Chart and application versions are published together from the same release tag: -- `version` tracks chart package changes. Bump it for any chart content change, including templates, values, `Chart.yaml` metadata, README updates, or Artifact Hub annotations. -- `appVersion` tracks the default Readability JS Server image version used by the chart. +- `version` and `appVersion` must both equal the release tag without the `v` prefix. +- A chart-only change still needs a new patch release, with both fields bumped together. -When the chart changes without a new application release, only the chart `version` should move. When the default image tag changes, bump both the chart `version` and `appVersion`. - -Docker image publishing remains tag-driven from the root release workflow and follows the git tag. Helm chart publishing is separate: pushes to `master` that change `charts/**`, plus explicit manual workflow runs, publish the chart repository to GitHub Pages. +One `vX.Y.Z` tag publishes the Docker image, the chart package and `index.yaml` on `gh-pages`, the Artifact Hub metadata, and the GitHub Release. Merging to `main` publishes nothing. A manual workflow dispatch republishes only the Artifact Hub metadata to `gh-pages`; it never builds an image or a chart package. ## Hosted repository and Artifact Hub @@ -92,7 +90,7 @@ https://phpdocker-io.github.io/readability-js-server Artifact Hub should register that external Helm repository URL. It should not be pointed at GitHub Releases or at the source repository itself. -Repository-level Artifact Hub metadata lives in `artifacthub-repo.yml`. The chart release workflow copies that file onto `gh-pages` so it is served next to `index.yaml`, which is the layout Artifact Hub expects for ownership claims and verified publisher metadata. +Repository-level Artifact Hub metadata lives in `artifacthub-repo.yml`. The release workflow copies `artifacthub-repo.yml` and `.nojekyll` onto `gh-pages` next to `index.yaml`, which is the layout Artifact Hub expects for ownership claims and verified publisher metadata. ## Verification