From 68c8ddbb9b5ddb751eaadc23f560a5aa55584c9a Mon Sep 17 00:00:00 2001 From: "theeraphat.ch" Date: Mon, 3 Aug 2026 23:52:52 +0700 Subject: [PATCH 1/5] ci: add CI on main and dry-run verification on dev No workflow ran on branch pushes or pull requests: cavimg-package.yaml only triggers on v* tags and workflow_dispatch, so typecheck, tests and the Go MCP suite were never exercised before a publish. Add ci.yaml (push/PR on main, plus workflow_call) running cavimg typecheck/test/build and cavimg-mcp vet/test. Add dev-check.yaml (push/PR on dev) which reuses ci.yaml and then runs `npm publish --dry-run` so dev validates the packed tarball and manifest without contacting the registry or publishing. Both pin pnpm/action-setup by commit SHA, declare `permissions: contents: read`, and keep `${{ }}` out of run blocks, matching the hardening in a4ac388. --- .github/workflows/ci.yaml | 72 ++++++++++++++++++++++++++++++++ .github/workflows/dev-check.yaml | 55 ++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/dev-check.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..84d4978 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,72 @@ +name: ci + +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_call: + +permissions: + contents: read + +concurrency: + group: ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + web: + name: cavimg (typecheck / test / build) + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - uses: actions/checkout@v6 + + - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4 + with: + version: 10.27.0 + + - uses: actions/setup-node@v6 + with: + node-version: "24" + package-manager-cache: false + + - name: Install dependencies + run: pnpm install --frozen-lockfile --filter cavimg... --ignore-scripts + + - name: Typecheck + run: pnpm --filter cavimg typecheck + + - name: Test + run: pnpm --filter cavimg test + + - name: Build + run: pnpm --filter cavimg build + + mcp: + name: cavimg-mcp (vet / test) + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-go@v6 + with: + go-version-file: packages/cavimg-mcp/go.mod + cache-dependency-path: packages/cavimg-mcp/go.sum + + - name: Vet + working-directory: packages/cavimg-mcp + run: go vet ./... + + - name: Test + working-directory: packages/cavimg-mcp + run: go test ./... diff --git a/.github/workflows/dev-check.yaml b/.github/workflows/dev-check.yaml new file mode 100644 index 0000000..9460089 --- /dev/null +++ b/.github/workflows/dev-check.yaml @@ -0,0 +1,55 @@ +name: dev-check + +on: + push: + branches: + - dev + pull_request: + branches: + - dev + +permissions: + contents: read + +concurrency: + group: dev-check-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + verify: + name: verify + uses: ./.github/workflows/ci.yaml + permissions: + contents: read + + pack: + name: publish dry-run (no registry write) + needs: verify + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - uses: actions/checkout@v6 + + - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4 + with: + version: 10.27.0 + + - uses: actions/setup-node@v6 + with: + node-version: "24" + package-manager-cache: false + + - name: Install dependencies + run: pnpm install --frozen-lockfile --filter cavimg... --ignore-scripts + + - name: Build + run: pnpm --filter cavimg build + + - name: Pack and inspect manifest + working-directory: packages/cavimg + run: | + echo "::notice::--dry-run packs the tarball only. It does NOT contact the registry, validate OIDC, or publish." + npm publish --dry-run --tag latest From e4dc808c1d6e6cd8e5695b5bdbefe1dad6c74b86 Mon Sep 17 00:00:00 2001 From: "theeraphat.ch" Date: Mon, 3 Aug 2026 23:52:52 +0700 Subject: [PATCH 2/5] feat: add GitHub Packages workflow and update README with npm badges --- .github/workflows/github-packages.yaml | 82 ++++++++++++++++++++++++++ README.md | 4 ++ 2 files changed, 86 insertions(+) create mode 100644 .github/workflows/github-packages.yaml diff --git a/.github/workflows/github-packages.yaml b/.github/workflows/github-packages.yaml new file mode 100644 index 0000000..a0b5f9d --- /dev/null +++ b/.github/workflows/github-packages.yaml @@ -0,0 +1,82 @@ +name: github-packages + +on: + push: + tags: + - "v*" + workflow_dispatch: + inputs: + dry_run: + description: "Pack/manifest check only. Does NOT contact GitHub Packages." + type: boolean + default: false + +permissions: + contents: read + +concurrency: + group: github-packages-${{ github.ref }} + cancel-in-progress: false + +env: + PACKAGE_DIR: packages/cavimg + SCOPED_NAME: "@theeraphatstudent/cavimg" + DRY_RUN: ${{ inputs.dry_run }} + +jobs: + publish: + name: mirror to GitHub Packages + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v6 + + - name: Verify tag matches package version + if: startsWith(github.ref, 'refs/tags/v') + run: | + tag_version="${GITHUB_REF_NAME#v}" + pkg_version="$(node -p "require('./${PACKAGE_DIR}/package.json').version")" + echo "tag=${tag_version} package.json=${pkg_version}" + if [ "$tag_version" != "$pkg_version" ]; then + echo "::error::Tag ${GITHUB_REF_NAME} does not match ${PACKAGE_DIR} version ${pkg_version}" + exit 1 + fi + + - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4 + with: + version: 10.27.0 + + - uses: actions/setup-node@v6 + with: + node-version: "24" + registry-url: "https://npm.pkg.github.com" + scope: "@theeraphatstudent" + package-manager-cache: false + + - name: Install dependencies + run: pnpm install --frozen-lockfile --filter cavimg... --ignore-scripts + + - name: Build + run: pnpm --filter cavimg build + + - name: Publish scoped mirror + working-directory: ${{ env.PACKAGE_DIR }} + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + DRY_RUN="${DRY_RUN:-false}" + + # GitHub Packages rejects unscoped names; rename only the packed copy. + npm pkg set name="${SCOPED_NAME}" + + args="--registry=https://npm.pkg.github.com --tag latest" + if [ "${DRY_RUN}" = "true" ]; then + args="${args} --dry-run" + echo "::warning::--dry-run packs the tarball only; it does NOT contact GitHub Packages." + fi + + npm publish ${args} diff --git a/README.md b/README.md index 02ce05b..ba416c4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # cavimg +[![npm version](https://img.shields.io/npm/v/cavimg?logo=npm&color=cb3837)](https://www.npmjs.com/package/cavimg) +[![npm downloads](https://img.shields.io/npm/dm/cavimg)](https://www.npmjs.com/package/cavimg) +[![license](https://img.shields.io/npm/l/cavimg)](https://www.npmjs.com/package/cavimg) + Render an image to a `` so it is harder to **casually** copy: no `` to right-click-save, no drag-to-desktop, and the URL is kept out of the DOM inspector. Framework-agnostic Web Component (``). **Casual deterrence only** — see From bf2af4d8b27f9fe3cbb5ad862226f676b7d743d7 Mon Sep 17 00:00:00 2001 From: "theeraphat.ch" Date: Mon, 3 Aug 2026 23:52:52 +0700 Subject: [PATCH 3/5] ci: tag main automatically after a merged dev pull request Cutting a release needed a hand-pushed tag, so a merged dev -> main PR left main untagged and cavimg-package.yaml with nothing to trigger it. Add release-tag.yaml, triggered on a closed pull request against main and gated on `merged == true` with head.ref == 'dev'. It reuses ci.yaml to typecheck, test and build the merge commit, and only once that passes reads packages/cavimg/package.json and pushes an annotated v tag at the merge commit. If the tag already exists the run is a no-op and the job summary says so, so doc-only merges cut no release and the version bump stays the release trigger. Give ci.yaml an optional workflow_call `ref` input so the reusable call checks out the merge commit rather than the closed PR's merge ref. Publishing stays manual: tags pushed with GITHUB_TOKEN do not trigger other workflows, so cavimg-package.yaml does not fire. The job summary links the operator to the dispatch button. --- .github/workflows/ci.yaml | 10 ++++ .github/workflows/release-tag.yaml | 80 ++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 .github/workflows/release-tag.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 84d4978..a9e4784 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -8,6 +8,12 @@ on: branches: - main workflow_call: + inputs: + ref: + description: "Git ref or SHA to check out. Empty means the ref that triggered the run." + type: string + required: false + default: "" permissions: contents: read @@ -26,6 +32,8 @@ jobs: steps: - uses: actions/checkout@v6 + with: + ref: ${{ inputs.ref }} - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4 with: @@ -57,6 +65,8 @@ jobs: steps: - uses: actions/checkout@v6 + with: + ref: ${{ inputs.ref }} - uses: actions/setup-go@v6 with: diff --git a/.github/workflows/release-tag.yaml b/.github/workflows/release-tag.yaml new file mode 100644 index 0000000..bd33398 --- /dev/null +++ b/.github/workflows/release-tag.yaml @@ -0,0 +1,80 @@ +name: release-tag + +on: + pull_request: + types: + - closed + branches: + - main + +permissions: + contents: read + +concurrency: + group: release-tag-${{ github.ref }} + cancel-in-progress: false + +jobs: + verify: + name: verify merged main + if: github.event.pull_request.merged == true && github.event.pull_request.head.ref == 'dev' + uses: ./.github/workflows/ci.yaml + permissions: + contents: read + with: + ref: ${{ github.event.pull_request.merge_commit_sha }} + + tag: + name: tag release + needs: verify + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - uses: actions/checkout@v6 + with: + ref: ${{ github.event.pull_request.merge_commit_sha }} + fetch-depth: 0 + + - uses: actions/setup-node@v6 + with: + node-version: "24" + package-manager-cache: false + + - name: Create tag from package version + env: + MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + version="$(node -p "require('./packages/cavimg/package.json').version")" + tag="v${version}" + + if git ls-remote --exit-code --tags origin "refs/tags/${tag}" >/dev/null 2>&1; then + echo "::notice::Tag ${tag} already exists — no release cut." + { + echo "### No release cut" + echo "" + echo "\`packages/cavimg/package.json\` is still at **${version}** and \`${tag}\` already exists." + echo "Bump the version in a PR to \`dev\` to cut the next release." + } >> "$GITHUB_STEP_SUMMARY" + exit 0 + fi + + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git tag -a "${tag}" -m "cavimg ${version} (PR #${PR_NUMBER})" "${MERGE_SHA}" + git push origin "refs/tags/${tag}" + + echo "::notice::Created tag ${tag} at ${MERGE_SHA}" + { + echo "### Tagged ${tag}" + echo "" + echo "Commit: \`${MERGE_SHA}\`" + echo "" + echo "**Publishing is not automatic.** Tags pushed by \`GITHUB_TOKEN\` do not trigger" + echo "other workflows, so \`cavimg-package.yaml\` did not fire." + echo "" + echo "To release: Actions → **cavimg-package** → Run workflow → \`mode: stage\`." + } >> "$GITHUB_STEP_SUMMARY" From 48d39a005db43bfedbf6ed83ab2ddb04d583fc97 Mon Sep 17 00:00:00 2001 From: "theeraphat.ch" Date: Mon, 3 Aug 2026 23:52:52 +0700 Subject: [PATCH 4/5] ci: restrict release tagging to same-repo dev branches A fork branch also named dev would otherwise satisfy the head.ref guard. Compare head.repo.full_name against github.repository so only the upstream dev branch can cut a tag. --- .github/workflows/release-tag.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release-tag.yaml b/.github/workflows/release-tag.yaml index bd33398..115ec0d 100644 --- a/.github/workflows/release-tag.yaml +++ b/.github/workflows/release-tag.yaml @@ -17,7 +17,10 @@ concurrency: jobs: verify: name: verify merged main - if: github.event.pull_request.merged == true && github.event.pull_request.head.ref == 'dev' + if: >- + github.event.pull_request.merged == true + && github.event.pull_request.head.ref == 'dev' + && github.event.pull_request.head.repo.full_name == github.repository uses: ./.github/workflows/ci.yaml permissions: contents: read From 5f72a413a9809bfaf01d4d96ef3bd278ff580635 Mon Sep 17 00:00:00 2001 From: "theeraphat.ch" Date: Mon, 3 Aug 2026 23:57:27 +0700 Subject: [PATCH 5/5] ci: pack locally on dev instead of npm publish --dry-run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `npm publish --dry-run` still queries the registry to check whether the version exists and exits 1 when it does. Once cavimg@1.0.2 went live the dev-check pack job failed on every run with "You cannot publish over the previously published versions: 1.0.2", because dev carries the version that was just released until someone bumps it. Use `npm pack --dry-run`, which is purely local, and follow it with a non-fatal `npm view` probe that reports whether the current version is already on npmjs — turning the old hard failure into the useful signal "bump before merging or no release is cut". Correct the dry_run wording in cavimg-package.yaml, which claimed the flag does not contact the registry. It does, and its dry_run path fails the same way on an already-published version. --- .github/workflows/cavimg-package.yaml | 4 ++-- .github/workflows/dev-check.yaml | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cavimg-package.yaml b/.github/workflows/cavimg-package.yaml index 846c961..8733da3 100644 --- a/.github/workflows/cavimg-package.yaml +++ b/.github/workflows/cavimg-package.yaml @@ -18,7 +18,7 @@ on: type: string default: latest dry_run: - description: "Pack/manifest check only. Does NOT test OIDC auth or contact the registry." + description: "Pack/manifest check. Does NOT test OIDC auth, and fails if the version is already published." type: boolean default: false @@ -106,7 +106,7 @@ jobs: args="--tag ${DIST_TAG} --provenance" if [ "${DRY_RUN}" = "true" ]; then args="${args} --dry-run" - echo "::warning::--dry-run only packs the tarball; it does NOT validate OIDC or trusted publisher config." + echo "::warning::--dry-run does NOT validate OIDC or trusted publisher config, and it still queries the registry — it exits 1 if this version is already published." fi case "${MODE}" in diff --git a/.github/workflows/dev-check.yaml b/.github/workflows/dev-check.yaml index 9460089..402a9fd 100644 --- a/.github/workflows/dev-check.yaml +++ b/.github/workflows/dev-check.yaml @@ -51,5 +51,11 @@ jobs: - name: Pack and inspect manifest working-directory: packages/cavimg run: | - echo "::notice::--dry-run packs the tarball only. It does NOT contact the registry, validate OIDC, or publish." - npm publish --dry-run --tag latest + npm pack --dry-run + + version="$(node -p "require('./package.json').version")" + if npm view "cavimg@${version}" version >/dev/null 2>&1; then + echo "::notice::cavimg@${version} is already on npmjs. Bump packages/cavimg/package.json or merging to main cuts no release." + else + echo "::notice::cavimg@${version} is not on npmjs yet — merging to main will tag and release it." + fi