From 4cce3067a7bce0d66a17b0347c4d87a9d090da0b Mon Sep 17 00:00:00 2001 From: Zach Plata Date: Tue, 20 Jun 2023 14:13:17 -0500 Subject: [PATCH] chore: move to manual npm publish workflow --- .github/workflows/publish.yml | 85 +++++++++++++---------------------- .release-it.json | 10 ++++- npm/react-canvas/package.json | 26 +++++++++++ npm/react-webgl/package.json | 26 +++++++++++ package.json | 9 +++- scripts/bump_all_versions.sh | 11 ----- scripts/bump_version.sh | 12 ----- scripts/nextVersion.js | 33 -------------- scripts/publish_all.sh | 2 +- scripts/setup_all_packages.sh | 9 ++-- 10 files changed, 108 insertions(+), 115 deletions(-) create mode 100644 npm/react-canvas/package.json create mode 100644 npm/react-webgl/package.json delete mode 100755 scripts/bump_all_versions.sh delete mode 100755 scripts/bump_version.sh delete mode 100644 scripts/nextVersion.js diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1edd0bd..6416b69 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,43 +1,28 @@ name: Publish to NPM on: - pull_request: - types: [closed] - branches: - - main + workflow_dispatch: + inputs: + major: + description: 'Major' + type: boolean + default: false + minor: + description: 'Minor' + type: boolean + default: false jobs: - determine_version: - name: Determine the next build version - if: github.event.pull_request.merged == true + publish_job: runs-on: ubuntu-latest - outputs: - version: ${{ steps.echo_version.outputs.version }} steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Install dependencies - run: npm install - working-directory: ./ - - name: Git config + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Setup Git config run: | git config --local user.email 'hello@rive.app' git config --local user.name ${{ github.actor }} - name: Authenticate with registry run: npm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }} - - id: determine_version - name: Get Version - run: npm run release -- --ci --release-version | tail -n 1 > RELEASE_VERSION - working-directory: ./ - env: - GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }} - - id: echo_version - run: echo "::set-output name=version::$(cat ./RELEASE_VERSION)" - - merge_job: - if: github.event.pull_request.merged == true - runs-on: ubuntu-latest - needs: [determine_version] - steps: - - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: '16.x' @@ -50,30 +35,24 @@ jobs: run: npm run lint - name: Run Tests run: npm test - - name: Build main dist - run: npm run build - - name: Copy separated builds - run: ./scripts/build.sh - - name: Copy package jsons to separate react outputs - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - run: ./scripts/setup_all_packages.sh - - name: Bump Versions of react outputs - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - RELEASE_VERSION: ${{ needs.determine_version.outputs.version }} - run: ./scripts/bump_all_versions.sh - - name: Git config - run: | - git config --local user.email 'hello@rive.app' - git config --local user.name ${{ github.actor }} - - name: Authenticate with registry - run: npm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }} - - name: Release rive-react + - if: ${{ inputs.major == true }} + name: Major Release - Bump version number, update changelog, push and tag + run: npm run release:major env: GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }} - run: npm run release -- --ci - - name: Release @rive-app/react-* variants + PAT_GITHUB: ${{ secrets.PAT_GITHUB }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - if: ${{inputs.major == false && inputs.minor == true}} + name: Minor release - Bump version number, update changelog, push and tag + run: npm run release:minor env: GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }} - run: ./scripts/publish_all.sh + PAT_GITHUB: ${{ secrets.PAT_GITHUB }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - if: ${{inputs.major == false && inputs.minor == false}} + name: Patch release - Bump version number, update changelog, push and tag + run: npm run release:patch + env: + GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }} + PAT_GITHUB: ${{ secrets.PAT_GITHUB }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.release-it.json b/.release-it.json index 218eb98..0f7e5fe 100644 --- a/.release-it.json +++ b/.release-it.json @@ -1,5 +1,7 @@ { "git": { + "addUntrackedFiles": true, + "requireCleanWorkingDir": false, "commitMessage": "chore: release ${version}", "tagName": "v${version}", "changelog": "npx auto-changelog --stdout --commit-limit false --unreleased --template https://raw.githubusercontent.com/release-it/release-it/master/templates/changelog-compact.hbs" @@ -12,6 +14,12 @@ "releaseName": "${version}" }, "hooks": { - "after:bump": ["npx auto-changelog -p", "git add ./CHANGELOG.md"] + "after:version:bump": [ + "npm run build", + "npm run setup-builds", + "npm run setup-packages", + "npx auto-changelog -p", + "npm run publish:all" + ] } } diff --git a/npm/react-canvas/package.json b/npm/react-canvas/package.json new file mode 100644 index 0000000..103b5dd --- /dev/null +++ b/npm/react-canvas/package.json @@ -0,0 +1,26 @@ +{ + "name": "@rive-app/react-canvas", + "version": "3.0.53", + "description": "React wrapper around the @rive-app/canvas library", + "main": "dist/index.js", + "typings": "dist/types/index.d.ts", + "files": [ + "dist/**" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/rive-app/rive-react.git" + }, + "author": "", + "license": "MIT", + "bugs": { + "url": "https://github.com/rive-app/rive-react/issues" + }, + "homepage": "https://github.com/rive-app/rive-react#readme", + "dependencies": { + "@rive-app/canvas": "1.2.0" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0" + } +} \ No newline at end of file diff --git a/npm/react-webgl/package.json b/npm/react-webgl/package.json new file mode 100644 index 0000000..f3863b1 --- /dev/null +++ b/npm/react-webgl/package.json @@ -0,0 +1,26 @@ +{ + "name": "@rive-app/react-webgl", + "version": "3.0.53", + "description": "React wrapper around the @rive-app/webgl library", + "main": "dist/index.js", + "typings": "dist/types/index.d.ts", + "files": [ + "dist/**" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/rive-app/rive-react.git" + }, + "author": "", + "license": "MIT", + "bugs": { + "url": "https://github.com/rive-app/rive-react/issues" + }, + "homepage": "https://github.com/rive-app/rive-react#readme", + "dependencies": { + "@rive-app/webgl": "1.2.0" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0" + } +} \ No newline at end of file diff --git a/package.json b/package.json index ec345f8..580a9d4 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,14 @@ "types:check": "tsc --noEmit", "release": "release-it", "storybook": "start-storybook -p 6006", - "build-storybook": "build-storybook -o docs-build" + "build-storybook": "build-storybook -o docs-build", + "release:patch": "npm run release -- --ci --dry-run", + "release:minor": "npm run release -- minor --ci --dry-run", + "release:major": "npm run release -- major --ci --dry-run", + "setup-builds": "./scripts/build.sh", + "setup-packages": "./scripts/setup_all_packages.sh", + "bump-versions": "./scripts/bump_all_versions.sh $npm_package_version", + "publish:all": "./scripts/publish_all.sh --access public" }, "repository": { "type": "git", diff --git a/scripts/bump_all_versions.sh b/scripts/bump_all_versions.sh deleted file mode 100755 index 3bf825d..0000000 --- a/scripts/bump_all_versions.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -e - -# Bump the version number of every npm module in the npm folder. -for dir in ./npm/*; do - pushd $dir > /dev/null - repo_name=`echo $dir | sed 's:.*/::' | sed 's/_/-/g'` - echo Bumping version of $repo_name - ../../scripts/bump_version.sh $repo_name $RELEASE_VERSION - popd > /dev/null -done diff --git a/scripts/bump_version.sh b/scripts/bump_version.sh deleted file mode 100755 index 2bbc83e..0000000 --- a/scripts/bump_version.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -# Bumps the version of a single npm module found in the current working -# directory. Call bump_version.sh from the path with package.json in it. - -set -e -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -# RELEASE_VERSION will come from an env variable passed in from the GH action workflow -node $SCRIPT_DIR/nextVersion.js "$RELEASE_VERSION" `pwd` - -# Replace the dist package json with the newly trimmed one -cp -f ./package.json ./dist/package.json diff --git a/scripts/nextVersion.js b/scripts/nextVersion.js deleted file mode 100644 index 3bbdd8b..0000000 --- a/scripts/nextVersion.js +++ /dev/null @@ -1,33 +0,0 @@ -const fs = require('fs'); -const path = process.argv[3]; -const package = require(path + '/package.json'); -const currentVersion = package.version; -const nextVersion = process.argv[2].trim().replace(/\'/g, '"'); - -if (!nextVersion || nextVersion === currentVersion) { - throw new Error('Next version is not defined or is a version that already exists'); -} - -// Returns -1 if first is less than second, 1 if first is greater than second, otherwise 0 if equal. -function compareVersion(first, second) { - // Assumption: only numbers in our versions. - const firstParts = first.split('.').map((value) => parseInt(value)); - const secondParts = second.split('.').map((value) => parseInt(value)); - - for (let i = 0; i < Math.max(firstParts.length, secondParts.length); i++) { - const first = i < firstParts.length ? firstParts[i] : 0; - const second = i < secondParts.length ? secondParts[i] : 0; - if (first < second) { - return -1; - } - if (second < first) { - return 1; - } - } - return 0; -} - -if (compareVersion(currentVersion, nextVersion) <= 0) { - package.version = nextVersion; - fs.writeFileSync(path + '/package.json', JSON.stringify(package, null, 2)); -} diff --git a/scripts/publish_all.sh b/scripts/publish_all.sh index a70bc6e..295d808 100755 --- a/scripts/publish_all.sh +++ b/scripts/publish_all.sh @@ -5,6 +5,6 @@ set -e for dir in ./npm/*; do pushd $dir > /dev/null echo Publishing `echo $dir | sed 's:.*/::'` - npm publish --access public + npm publish $@ popd > /dev/null done diff --git a/scripts/setup_all_packages.sh b/scripts/setup_all_packages.sh index 601545a..ca0730b 100755 --- a/scripts/setup_all_packages.sh +++ b/scripts/setup_all_packages.sh @@ -3,14 +3,17 @@ set -e echo "Copying package.json to rive-react npm package folders" -cp package.json npm/react-canvas -cp package.json npm/react-webgl - # Bump the version number of every npm module in the npm folder. for dir in ./npm/*; do echo $dir pushd $dir > /dev/null echo $dir + if [ -f "./package.json" ]; then + echo "Removing existing package.json..." + rm "./package.json" + echo "package.json deleted from $dir" + fi + cp ../../package.json ./ repo_name=`echo $dir | sed 's:.*/::' | sed 's/_/-/g'` echo Setting package.json on npm packages echo $repo_name