diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..b65ce7b4 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,49 @@ +name: Publish +on: + release: + types: [published] + +jobs: + publish: + runs-on: ubuntu-latest + + permissions: + contents: read + id-token: write + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: lts/* + registry-url: https://registry.npmjs.org + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Update package version to latest tag + run: | + npm version from-git --allowSameVersion + git push --follow-tags + + - name: Create jsr.json based on package.json + run: | + node -e ' + const p = require("./package.json"); + const jsrJson = { + name: `@cheerio/${p.name}`, + version: p.version, + ...p.tshy, + }; + require("fs").writeFileSync("./jsr.json", JSON.stringify(jsrJson, null, 2)); + ' + + - name: Publish package to JSR + run: npx jsr publish + + - name: Publish package to NPM + run: npm publish --provenance --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.gitignore b/.gitignore index 0d7b3c30..6e2e2620 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ coverage/ dist/ .tshy/ docs/ +jsr.json diff --git a/package.json b/package.json index ee9250fc..b9770b37 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,6 @@ "src" ], "scripts": { - "build": "tshy", "build:docs": "typedoc --hideGenerator src/index.ts", "build:encode-trie": "node --import=tsx scripts/write-encode-map.ts", "build:trie": "node --import=tsx scripts/write-decode-map.ts", @@ -71,7 +70,7 @@ "lint:es": "eslint . --ignore-path .gitignore", "lint:prettier": "npm run prettier -- --check", "lint:ts": "tsc --noEmit", - "prepare": "npm run build", + "prepublishOnly": "tshy", "prettier": "prettier '**/*.{ts,md,json,yml}'", "test": "npm run test:vi && npm run lint", "test:vi": "vitest run"