From 15041bee653f89b84fc20427760aafd910f6232c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstr=C3=B6m?= Date: Wed, 30 Aug 2023 16:50:43 -0400 Subject: [PATCH] feat: publish new version to npm via ci Also, add the exported type structure. PR: https://github.com/Topsort/analytics.js/pull/198 --- .github/workflows/npm-publish.yml | 70 ---------------------------- .github/workflows/publish-to-npm.yml | 53 +++++++++++++++++++++ package.json | 6 ++- 3 files changed, 57 insertions(+), 72 deletions(-) delete mode 100644 .github/workflows/npm-publish.yml create mode 100644 .github/workflows/publish-to-npm.yml diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml deleted file mode 100644 index 1c0205d..0000000 --- a/.github/workflows/npm-publish.yml +++ /dev/null @@ -1,70 +0,0 @@ -name: npm-publish -on: - release: - types: [published] - -jobs: - test: - name: test - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Setup - uses: actions/setup-node@v3 - with: - node-version: "16" - - - name: Cache node modules - id: cache-node - uses: actions/cache@v3.3.1 - with: - path: node_modules - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - name: Install Dependencies - run: npm ci - - - name: Run tests - run: npm run test - - npm-publish: - name: npm-publish - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Setup - uses: actions/setup-node@v3 - with: - node-version: "16" - - - name: Cache node modules - id: cache-node - uses: actions/cache@v3.3.1 - with: - path: node_modules - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - name: Install Dependencies - run: npm ci - - - name: Publish if version has been updated - uses: pascalgn/npm-publish-action@1.3.9 - with: # All of theses inputs are optional - tag_name: "v%s" - tag_message: "v%s" - create_tag: "true" - commit_pattern: "^Release (\\S+)" - workspace: "." - publish_command: "yarn" - publish_args: "--non-interactive --access public" - env: # More info about the environment variables in the README - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this as is, it's automatically generated - NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} # You need to set this in your repo settings diff --git a/.github/workflows/publish-to-npm.yml b/.github/workflows/publish-to-npm.yml new file mode 100644 index 0000000..b1d1506 --- /dev/null +++ b/.github/workflows/publish-to-npm.yml @@ -0,0 +1,53 @@ +name: Release + +on: + release: + types: [published] + +env: + lockfile: pnpm-lock.yaml + node_version: "18" + pnpm_version: "8" + +jobs: + npm-publish: + name: Publish to NPM + runs-on: ubuntu-22.04 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - uses: pnpm/action-setup@v2 + name: Install PNPM + id: pnpm-install + with: + version: ${{ env.pnpm_version }} + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ env.node_version }} + cache: pnpm + cache-dependency-path: ${{ env.lockfile }} + + - name: Install dependencies + run: pnpm install + + - name: Run ESLint + run: pnpm run lint:ci + + - name: Run tests + run: pnpm run test + + - name: Run tsc + run: node_modules/.bin/tsc + + - name: Build dist + run: pnpm run build + + - name: Publish to npm + id: publish + run: | + pnpm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }} + pnpm publish --access public --no-git-checks diff --git a/package.json b/package.json index 5734ff3..ff5f2b8 100644 --- a/package.json +++ b/package.json @@ -19,11 +19,13 @@ "exports": { ".": { "import": "./dist/ts.mjs", - "require": "./dist/ts.js" + "require": "./dist/ts.js", + "types": "./dist/src/events.d.ts" } }, - "module": "./dist/ts.js", + "module": "./dist/ts.mjs", "files": [ + "dist/src", "dist/ts.js", "dist/ts.mjs", "dist/*.d.ts",