Publish on merge to master

This commit is contained in:
Arthur Vivian
2021-06-25 13:32:32 +01:00
parent 5562663acd
commit d676c3d9cf
6 changed files with 66 additions and 3 deletions

27
.github/workflows/publish.yml vendored Normal file
View File

@@ -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

View File

@@ -1,6 +1,5 @@
name: CI
on:
push:
on: push
jobs:
build:
runs-on: ubuntu-latest

View File

@@ -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).

View File

@@ -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",

27
scripts/next_version.js Normal file
View File

@@ -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));

5
scripts/publish.sh Executable file
View File

@@ -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