diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..cce7172 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,27 @@ +name: Publish to NPM +on: + pull_request: + types: [closed] + branches: + - main +jobs: + merge_job: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '12.x' + registry-url: 'https://registry.npmjs.org' + - name: Install Modules + run: npm ci + - name: Run type check + run: npm run types:check + - name: Run Linter + run: npm run lint + - name: Run Tests + run: npm test + - name: Build + run: npm build + - name: Publish + run: npm run publish diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0a99e38..c3d723a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,6 +1,5 @@ name: CI -on: - push: +on: push jobs: build: runs-on: ubuntu-latest diff --git a/README.md b/README.md index 89de9b6..1011ca8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +![Build Status](https://github.com/rive-app/rive-react/actions/workflows/tests.yml/badge.svg) +![Discord badge](https://img.shields.io/discord/532365473602600965) +![Twitter handle](https://img.shields.io/twitter/follow/rive_app.svg?style=social&label=Follow) + # Rive React React Runtime for [Rive](https://rive.app). diff --git a/package.json b/package.json index 9e105c1..48418fb 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "build": "bunchee src/index.ts -m --no-sourcemap", "lint": "eslint -c .eslintrc.js 'src/**/*{.ts,.tsx}'", "format": "prettier --write src", - "types:check": "tsc --noEmit" + "types:check": "tsc --noEmit", + "publish": "./scripts/publish.sh" }, "repository": { "type": "git", diff --git a/scripts/next_version.js b/scripts/next_version.js new file mode 100644 index 0000000..060e8bc --- /dev/null +++ b/scripts/next_version.js @@ -0,0 +1,27 @@ +const fs = require('fs'); +const package = require('../package.json'); + +function parseVersion(v) { + return v.split('.').map((n) => Number.parseInt(n, 10)); +} + +const packageVersion = parseVersion(package.version); +// Last version seems to always be latest. +const publishedVersion = parseVersion(JSON.parse(process.argv[2]).pop()); + +const isGreater = (first, second) => { + // Assumes first and second have same number of version number + const zipped = first.map((n, i) => [n, second[i]]); + return zipped.some(([a, b]) => a > b); +}; + +// If package version is greater than what's published, we use that. +if (isGreater(packageVersion, publishedVersion)) { + return; +} + +// Otherwise increment the publishedVersions patch number and push to the package.json +const newVersion = publishedVersion; +newVersion[2]++; +package.version = newVersion.join('.'); +fs.writeFileSync('./package.json', JSON.stringify(package, null, 2)); diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 0000000..1edd196 --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -e +NPM_VERSIONS=`npm show rive-react versions --json` +node ./scripts/next_version.js "$NPM_VERSIONS" +npm publish \ No newline at end of file