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/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..a9e4784 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -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 ./... diff --git a/.github/workflows/dev-check.yaml b/.github/workflows/dev-check.yaml new file mode 100644 index 0000000..402a9fd --- /dev/null +++ b/.github/workflows/dev-check.yaml @@ -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 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/.github/workflows/release-tag.yaml b/.github/workflows/release-tag.yaml new file mode 100644 index 0000000..115ec0d --- /dev/null +++ b/.github/workflows/release-tag.yaml @@ -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" 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