Publish data to npm #23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish data to npm | |
on: | |
schedule: | |
- cron: "0 0 * * MON" | |
push: | |
branches: | |
- master | |
paths: | |
- "packages/es-scraper/**" | |
workflow_dispatch: {} | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
environment: Publish | |
defaults: | |
run: | |
working-directory: ./packages/es-scraper | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: "20.x" | |
registry-url: "https://registry.npmjs.org" | |
cache: yarn | |
- run: yarn install | |
- run: yarn build | |
- name: Test if published data changed | |
uses: actions/github-script@v7 | |
id: check-change | |
with: | |
result-encoding: string | |
script: | | |
const FS = require("node:fs/promises"); | |
const existingEarlyErrors = await fetch("https://unpkg.com/es-scraper/generated/early-errors.json").then((res) => res.text()); | |
const existingIntrinsics = await fetch("https://unpkg.com/es-scraper/generated/intrinsics.json").then((res) => res.text()); | |
const newEarlyErrors = await FS.readFile("${{ github.workspace }}/packages/es-scraper/generated/early-errors.json", "utf-8"); | |
const newIntrinsics = await FS.readFile("${{ github.workspace }}/packages/es-scraper/generated/intrinsics.json", "utf-8"); | |
if (existingEarlyErrors === newEarlyErrors && existingIntrinsics === newIntrinsics) { | |
return "no-change"; | |
} | |
return "changed"; | |
- name: Publish to npm | |
if: steps.check-change.conclusion == 'changed' | |
run: | | |
npm whoami | |
yarn version patch | |
npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Push new version | |
if: steps.check-change.conclusion == 'changed' | |
run: | | |
git config user.name 'github-actions[bot]' | |
git config user.email 'github-actions[bot]@users.noreply.github.com' | |
git add . | |
git commit -m "chore: publish new version [skip ci]" | |
git push |