From 764863e3d2c8d84d2485795c36d1a0ea7d514146 Mon Sep 17 00:00:00 2001 From: Darsh Patel Date: Mon, 17 Mar 2025 19:30:23 -0700 Subject: [PATCH 1/2] feat: publish pipeline --- .github/workflows/publish.yml | 82 +++++++++++++++++++++++++++++++++++ README.md | 27 ++++++++++++ package.json | 5 ++- 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..767ad34 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,82 @@ +name: Publish Package + +on: + push: + tags: + - 'v*' + +jobs: + validate-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - 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" + + build-and-publish: + needs: validate-version + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 18 + registry-url: 'https://registry.npmjs.org' + + - 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", From e45ddee03a97185b4ad25c5064d35f50325eee5b Mon Sep 17 00:00:00 2001 From: Darsh Patel Date: Tue, 18 Mar 2025 13:53:15 -0700 Subject: [PATCH 2/2] chore: bump node --- .github/workflows/publish.yml | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 767ad34..c8096cd 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,11 +6,17 @@ on: - 'v*' jobs: - validate-version: + 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} @@ -21,20 +27,6 @@ jobs: fi echo "Version validation successful: $TAG" - build-and-publish: - needs: validate-version - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 18 - registry-url: 'https://registry.npmjs.org' - - name: Setup pnpm uses: pnpm/action-setup@v2 with: