Skip to content
Open
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
74 changes: 74 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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 }}
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down