diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..c8096cd --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,74 @@ +name: Publish Package + +on: + push: + tags: + - 'v*' + +jobs: + build-and-publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 22 + - name: Verify tag matches package version + run: | + TAG=${GITHUB_REF#refs/tags/v} + PKG_VERSION=$(node -p "require('./package.json').version") + if [ "$TAG" != "$PKG_VERSION" ]; then + echo "Tag $TAG doesn't match package version $PKG_VERSION" + exit 1 + fi + echo "Version validation successful: $TAG" + + - name: Setup pnpm + uses: pnpm/action-setup@v2 + with: + version: 8.15.5 + run_install: false + + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - name: Cache pnpm dependencies + uses: actions/cache@v3 + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Typecheck + run: pnpm typecheck + + - name: Lint + run: pnpm lint + + - name: Build + run: pnpm build + + - name: Test + run: pnpm test + + - name: Publish package + run: | + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc + pnpm publish --no-git-checks --access public + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Create GitHub Release + run: gh release create ${GITHUB_REF#refs/tags/} --generate-notes + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/README.md b/README.md index 24a7b06..12dc383 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,33 @@ pnpm test pnpm test:watch ``` +### Releasing + +This package follows semantic versioning. To release a new version: + +1. Choose the appropriate release type based on your changes: + ```bash + # For bug fixes and minor changes (0.0.x) + pnpm release:patch + + # For new features - backward compatible (0.x.0) + pnpm release:minor + + # For breaking changes (x.0.0) + pnpm release:major + ``` + +2. Push the new tag to GitHub: + ```bash + git push --follow-tags + ``` + +3. The GitHub Actions workflow will automatically: + - Validate that the tag version matches the package.json version + - Run tests and build the package + - Publish to npm (requires npm authentication) + - Create a GitHub Release for the tag + ## License MIT \ No newline at end of file diff --git a/package.json b/package.json index 5789ff0..a9e1d69 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,10 @@ "clean": "rm -rf dist", "prepare": "npm run build", "test": "vitest run", - "test:watch": "vitest" + "test:watch": "vitest", + "release:patch": "npm version patch -m \"chore(release): %s\"", + "release:minor": "npm version minor -m \"chore(release): %s\"", + "release:major": "npm version major -m \"chore(release): %s\"" }, "repository": { "type": "git",