From d4d79b220fcbe19e08411d6af80a749d76d38b12 Mon Sep 17 00:00:00 2001 From: mathuo <6710312+mathuo@users.noreply.github.com> Date: Sun, 22 Oct 2023 11:14:30 +0100 Subject: [PATCH] chore: Github Action npm experimental publish --- .github/workflows/experimental.yml | 29 +++++++++++++ package.json | 3 +- scripts/set-experimental-versions.js | 61 ++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/experimental.yml create mode 100644 scripts/set-experimental-versions.js diff --git a/.github/workflows/experimental.yml b/.github/workflows/experimental.yml new file mode 100644 index 000000000..8edc2c417 --- /dev/null +++ b/.github/workflows/experimental.yml @@ -0,0 +1,29 @@ +name: Publish Experimental Package to npmjs +on: + workflow_dispatch: + # release: + # types: [published] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version: '16.x' + registry-url: 'https://registry.npmjs.org' + + - uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-node- + + - run: yarn + - run: npm run set-experimental-verisons + - run: npm run build + - run: npm run test + - run: npm publish --tag experimental --dry-run + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/package.json b/package.json index 037fe7857..879053829 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "clean": "lerna run clean", "bootstrap": "lerna bootstrap", "test:cov": "jest --coverage", + "set-experimental-versions": "node scripts/set-experimental-versions", "version-beta-build": "lerna version prerelease --preid beta", "publish-app": "lerna publish", "docs": "typedoc", @@ -72,4 +73,4 @@ "dependencies": { "@microsoft/tsdoc": "^0.14.2" } -} \ No newline at end of file +} diff --git a/scripts/set-experimental-versions.js b/scripts/set-experimental-versions.js new file mode 100644 index 000000000..4ae911dc2 --- /dev/null +++ b/scripts/set-experimental-versions.js @@ -0,0 +1,61 @@ +const cp = require('child_process'); +const fs = require('fs'); +const path = require('path'); +const rootDir = path.join(__dirname, '..'); + +function formatDate() { + const date = new Date(); + + function pad(value) { + if (value.toString().length === 1) { + return `0${value}`; + } + return value; + } + + return `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad( + date.getDate() + )}`; +} + +function shortGitHash() { + return cp + .execSync('git rev-parse --short HEAD', { + cwd: rootDir, + }) + .toString() + .replace(/\n/g, ''); +} + +const version = `0.0.0-experimental-${shortGitHash()}-${formatDate()}`; + +// dockview-core + +const dockviewCorePath = path.join( + rootDir, + 'packages', + 'dockview-core', + 'package.json' +); +const dockviewCorePackageJson = JSON.parse( + fs.readFileSync(dockviewCorePath).toString() +); + +dockviewCorePackageJson.version = version; + +fs.writeFileSync( + dockviewCorePath, + JSON.stringify(dockviewCorePackageJson, null, 4) +); + +// dockview + +const dockviewPath = path.join(rootDir, 'packages', 'dockview', 'package.json'); +const dockviewPackageJson = JSON.parse( + fs.readFileSync(dockviewPath).toString() +); + +dockviewPackageJson.version = version; +dockviewPackageJson.dependencies['dockview-core'] = dockviewPackageJson.version; + +fs.writeFileSync(dockviewPath, JSON.stringify(dockviewPackageJson, null, 4));