From db5f11fdaecf4b65c8d5aabfd98693b495aac555 Mon Sep 17 00:00:00 2001 From: Russell Dunphy Date: Sat, 31 Jan 2026 10:31:42 +0000 Subject: [PATCH 1/3] Add GitHub Action workflow for preview package publishing Automatically publishes every commit to GitHub Packages with a version like 0.0.0-branch.sha, tagged as 'preview'. Keeps the 50 most recent preview versions. Co-Authored-By: Claude Opus 4.5 --- .github/workflows/publish-preview.yml | 71 +++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/publish-preview.yml diff --git a/.github/workflows/publish-preview.yml b/.github/workflows/publish-preview.yml new file mode 100644 index 0000000..9364523 --- /dev/null +++ b/.github/workflows/publish-preview.yml @@ -0,0 +1,71 @@ +name: Publish Preview Packages + +on: + push: + branches-ignore: + - "dependabot/**" + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 + + - uses: ./.github/actions/ci-setup + + - name: Configure npm for GitHub Packages + run: | + echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> ~/.npmrc + + - name: Build package + run: pnpm build + + - name: Generate version string + id: version + run: | + BRANCH="${GITHUB_REF_NAME}" + # Sanitize branch name for npm (replace invalid chars with -) + BRANCH_SAFE=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9-]/-/g' | sed 's/--*/-/g' | sed 's/^-//' | sed 's/-$//') + SHORT_SHA="${GITHUB_SHA::7}" + VERSION="0.0.0-${BRANCH_SAFE}.${SHORT_SHA}" + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Publishing version: $VERSION" + + - name: Update package version + run: pnpm version ${{ steps.version.outputs.version }} --no-git-tag-version + + - name: Publish package + run: pnpm publish --access public --tag preview --no-git-checks + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Summary + run: | + echo "## Published Package" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "Version: \`${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "Install with:" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY + echo "pnpm add @casekit/unindent@${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + + cleanup: + runs-on: ubuntu-latest + needs: publish + permissions: + packages: write + + steps: + - name: Delete old preview versions + uses: actions/delete-package-versions@v5 + with: + package-name: unindent + package-type: npm + min-versions-to-keep: 50 + delete-only-pre-release-versions: true + token: ${{ secrets.GITHUB_TOKEN }} From f110f1fa9b9f55cdf281ede7ad2a7c0291ab0820 Mon Sep 17 00:00:00 2001 From: Russell Dunphy Date: Sat, 31 Jan 2026 10:36:51 +0000 Subject: [PATCH 2/3] Fix test import and exclude build directory from Vitest - Change test import from #unindent (build path) to relative ./unindent so tests work without building first - Add vitest.config.ts to exclude build/ from test discovery Co-Authored-By: Claude Opus 4.5 --- src/unindent.test.ts | 2 +- vitest.config.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 vitest.config.ts diff --git a/src/unindent.test.ts b/src/unindent.test.ts index e68f84d..def51a1 100644 --- a/src/unindent.test.ts +++ b/src/unindent.test.ts @@ -1,5 +1,5 @@ import { describe, test, expect } from "vitest"; -import { unindent } from "#unindent"; +import { unindent } from "./unindent"; describe("unindent", () => { test("it strips whitespace from the left-hand side of multiline strings", () => { diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..a93c00f --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,7 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + exclude: ["build/**", "node_modules/**"], + }, +}); From 634dab0d537098959a41111292dd518cb9b57b8a Mon Sep 17 00:00:00 2001 From: Russell Dunphy Date: Sat, 31 Jan 2026 10:38:13 +0000 Subject: [PATCH 3/3] Configure publishConfig for GitHub Packages registry Co-Authored-By: Claude Opus 4.5 --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 26d2b42..7c80126 100644 --- a/package.json +++ b/package.json @@ -29,5 +29,8 @@ "vitest": "^1.1.1" }, "author": "Russell Dunphy", - "license": "ISC" + "license": "ISC", + "publishConfig": { + "registry": "https://npm.pkg.github.com" + } }