Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/cavimg-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: ci

on:
push:
branches:
- main
pull_request:
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

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
with:
ref: ${{ inputs.ref }}

- 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
with:
ref: ${{ inputs.ref }}

- 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 ./...
61 changes: 61 additions & 0 deletions .github/workflows/dev-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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: |
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
82 changes: 82 additions & 0 deletions .github/workflows/github-packages.yaml
Original file line number Diff line number Diff line change
@@ -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}
83 changes: 83 additions & 0 deletions .github/workflows/release-tag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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'
&& github.event.pull_request.head.repo.full_name == github.repository
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"
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 `<canvas>` so it is harder to **casually** copy: no `<img>` to
right-click-save, no drag-to-desktop, and the URL is kept out of the DOM inspector.
Framework-agnostic Web Component (`<cav-img>`). **Casual deterrence only** — see
Expand Down
Loading