From 4429be44f2af2b91d9d5e26a65b70e59d9647979 Mon Sep 17 00:00:00 2001 From: Zach Plata Date: Mon, 18 Apr 2022 14:48:30 -0700 Subject: [PATCH] Change rive-react-* references to be the shortened namespace-named convention --- .github/workflows/publish.yml | 24 +++++++++++++++++++++++- scripts/build.sh | 3 +-- scripts/bump_all_versions.sh | 2 +- scripts/bump_version.sh | 4 ++-- scripts/nextVersion.js | 19 +++++++------------ scripts/publish_all.sh | 2 +- scripts/setup_all_packages.sh | 6 +++--- 7 files changed, 38 insertions(+), 22 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0ecf0de..deeb904 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -5,9 +5,31 @@ on: branches: - main jobs: + determine_version: + name: Determine the next build version + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + outputs: + version: ${{ steps.echo_version.outputs.version }} + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Install dependencies + run: npm ci + working-directory: ./ + - 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 @@ -33,4 +55,4 @@ jobs: - name: Release env: GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }} - run: npm run release + run: npm run release -- --ci diff --git a/scripts/build.sh b/scripts/build.sh index bb2019c..9ea494e 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -2,8 +2,7 @@ set -e -# Run the build and copy to each react-variant build for npm release -npm run build +# Copy the build to each react-variant build for npm release cp -r ./dist ./npm/react-webgl cp -r ./dist ./npm/react-canvas diff --git a/scripts/bump_all_versions.sh b/scripts/bump_all_versions.sh index 33fee0a..3bf825d 100755 --- a/scripts/bump_all_versions.sh +++ b/scripts/bump_all_versions.sh @@ -6,6 +6,6 @@ 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 + ../../scripts/bump_version.sh $repo_name $RELEASE_VERSION popd > /dev/null done diff --git a/scripts/bump_version.sh b/scripts/bump_version.sh index 4052d79..defb51c 100755 --- a/scripts/bump_version.sh +++ b/scripts/bump_version.sh @@ -5,5 +5,5 @@ set -e SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -NPM_VERSIONS=`npm show rive-react versions` -node $SCRIPT_DIR/nextVersion.js "$NPM_VERSIONS" `pwd` +# RELEASE_VERSION will come from an env variable passed in from the GH action workflow +node $SCRIPT_DIR/nextVersion.js "$RELEASE_VERSION" `pwd` diff --git a/scripts/nextVersion.js b/scripts/nextVersion.js index b41ab8c..d59b042 100644 --- a/scripts/nextVersion.js +++ b/scripts/nextVersion.js @@ -1,14 +1,12 @@ const fs = require('fs'); const path = process.argv[3]; const package = require(path + '/package.json'); -let versions = JSON.parse(process.argv[2].trim().replace(/\'/g, '"')); -const current = package.version; -// Don't work with alpha/beta/rc tags, maybe a better regex here? -versions = versions.filter((ver) => { - return !/[a-zA-Z]/.test(ver); -}); +const currentVersion = package.version; +const nextVersion = process.argv[2].trim().replace(/\'/g, '"'); -const latest = versions[versions.length - 1]; +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) { @@ -35,10 +33,7 @@ function compareVersion(first, second) { return 0; } -if (compareVersion(current, latest) <= 0) { - const parts = latest.split('.').map((value) => parseInt(value)); - // TODO: Need to make this smarter, because the semver can change on rive-react - parts[parts.length - 1] = parts[parts.length - 1] + 1; - package.version = parts.join('.'); +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 295d808..a70bc6e 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 $@ + npm publish --access public popd > /dev/null done diff --git a/scripts/setup_all_packages.sh b/scripts/setup_all_packages.sh index 11601ae..601545a 100755 --- a/scripts/setup_all_packages.sh +++ b/scripts/setup_all_packages.sh @@ -1,10 +1,10 @@ #!/bin/bash set -e -echo Copying package.json to rive-react npm package folders +echo "Copying package.json to rive-react npm package folders" -cp package.json npm/rive-react-canvas -cp package.json npm/rive-react-webgl +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