From 0373dda7a92485287a12c3795d7f00a2ecdcc332 Mon Sep 17 00:00:00 2001 From: danstarns Date: Mon, 10 Feb 2025 19:25:39 -0800 Subject: [PATCH 1/4] ci: add runners --- .github/actions/setup-project/action.yml | 9 ++++ .github/workflows/pr.yml | 9 ---- .../release-grapesjs-react-latest.yml | 22 +++++++++ package.json | 4 +- scripts/common.ts | 10 +++++ scripts/releaseCore.ts | 45 +++++++++++++++++++ 6 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/release-grapesjs-react-latest.yml create mode 100644 scripts/common.ts create mode 100644 scripts/releaseCore.ts diff --git a/.github/actions/setup-project/action.yml b/.github/actions/setup-project/action.yml index e4976ed..62fcb24 100644 --- a/.github/actions/setup-project/action.yml +++ b/.github/actions/setup-project/action.yml @@ -18,3 +18,12 @@ runs: - name: Install dependencies run: yarn shell: bash + + - name: Install React Dependencies in Root + shell: bash + run: | + cd ./packages/grapesjs-react && yarn add \ + react@^19.0.0 \ + react-dom@^19.0.0 \ + @types/react@^19.0.0 \ + @types/react-dom@^19.0.0 diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 51fa619..82d192a 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -30,15 +30,6 @@ jobs: - name: Setup Project Base uses: ./.github/actions/setup-project - ## We specify the version of react and react-dom we want to run vite build with - - name: Install React Dependencies in Root - run: | - cd ./packages/grapesjs-react && yarn add \ - react@^19.0.0 \ - react-dom@^19.0.0 \ - @types/react@^19.0.0 \ - @types/react-dom@^19.0.0 - - name: Build Core run: yarn workspace @grapesjs/react run build diff --git a/.github/workflows/release-grapesjs-react-latest.yml b/.github/workflows/release-grapesjs-react-latest.yml new file mode 100644 index 0000000..3299adc --- /dev/null +++ b/.github/workflows/release-grapesjs-react-latest.yml @@ -0,0 +1,22 @@ +name: Publish GrapesJS React latest +on: + push: + branches: [dev] + +jobs: + publish: + if: "contains(github.event.head_commit.message, 'Release GrapesJS React latest:')" + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup project + uses: ./.github/actions/setup-project + - name: Build + run: yarn build:core + - name: Publish to npm + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> ./packages/grapesjs-react/.npmrc + yarn publish:core:latest diff --git a/package.json b/package.json index a7e8b25..288a05b 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,9 @@ "clean": "find . -type d \\( -name \"node_modules\" -o -name \"build\" -o -name \"dist\" \\) -exec rm -rf {} + && rm ./yarn.lock", "build:core": "yarn workspace @grapesjs/react run build", "build:app-18": "yarn workspace @grapesjs/react-app-18 run build", - "build:app-19": "yarn workspace @grapesjs/react-app-19 run build" + "build:app-19": "yarn workspace @grapesjs/react-app-19 run build", + "release:core:latest": "ts-node scripts/releaseCore latest", + "publish:core:latest": "cd packages/grapesjs-react && npm publish --access public" }, "workspaces": { "packages": [ diff --git a/scripts/common.ts b/scripts/common.ts new file mode 100644 index 0000000..d4fb423 --- /dev/null +++ b/scripts/common.ts @@ -0,0 +1,10 @@ +import { execSync } from "child_process"; + +export function runCommand(command: string, error?: string) { + try { + return (execSync(command, { stdio: "inherit" }) || "").toString().trim(); + } catch (err) { + console.error(error || `Error while running command: ${command}`); + throw err; + } +} diff --git a/scripts/releaseCore.ts b/scripts/releaseCore.ts new file mode 100644 index 0000000..955f85f --- /dev/null +++ b/scripts/releaseCore.ts @@ -0,0 +1,45 @@ +import fs from "fs"; +import { resolve } from "path"; +import { runCommand } from "./common"; + +const grapesJSReactPath = resolve(__dirname, "../packages/grapesjs-react"); + +async function prepareReleaseGrapesJSReact() { + try { + const releaseTag = process.argv[2] || "rc"; + console.log("Prepare release GrapesJS tag:", releaseTag); + + runCommand( + "git diff-index --quiet HEAD --", + "You have uncommitted changes. Please commit or stash them before running the release script." + ); + + const versionCmd = + releaseTag === "latest" + ? "--patch" + : `--prerelease --preid ${releaseTag}`; + runCommand( + `yarn workspace @grapesjs/react version ${versionCmd} --no-git-tag-version --no-commit-hooks` + ); + + // Create a new release branch + const newVersion = JSON.parse( + fs.readFileSync(`${grapesJSReactPath}/package.json`, "utf8") + ).version; + const newBranch = `release-v${newVersion}`; + runCommand(`git checkout -b ${newBranch}`); + runCommand("git add ."); + runCommand( + `git commit -m "Release GrapesJS React ${releaseTag}: v${newVersion}"` + ); + + console.log( + `Release prepared! Push the current "${newBranch}" branch and open a new PR targeting 'dev'` + ); + } catch (error) { + console.error(error); + process.exit(1); + } +} + +prepareReleaseGrapesJSReact(); From 2f78be8a7a29902aaa13ab659f77c3a158697c2c Mon Sep 17 00:00:00 2001 From: danstarns Date: Mon, 10 Feb 2025 19:26:54 -0800 Subject: [PATCH 2/4] ci: fix* --- .github/workflows/release-grapesjs-react-latest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-grapesjs-react-latest.yml b/.github/workflows/release-grapesjs-react-latest.yml index 3299adc..70dcb54 100644 --- a/.github/workflows/release-grapesjs-react-latest.yml +++ b/.github/workflows/release-grapesjs-react-latest.yml @@ -1,7 +1,7 @@ name: Publish GrapesJS React latest on: push: - branches: [dev] + branches: [main] jobs: publish: From 64fa497729ccca176d7148b905a093e78aa68d8d Mon Sep 17 00:00:00 2001 From: danstarns Date: Mon, 10 Feb 2025 19:28:57 -0800 Subject: [PATCH 3/4] ci: * --- scripts/releaseCore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/releaseCore.ts b/scripts/releaseCore.ts index 955f85f..110ef1e 100644 --- a/scripts/releaseCore.ts +++ b/scripts/releaseCore.ts @@ -34,7 +34,7 @@ async function prepareReleaseGrapesJSReact() { ); console.log( - `Release prepared! Push the current "${newBranch}" branch and open a new PR targeting 'dev'` + `Release prepared! Push the current "${newBranch}" branch and open a new PR targeting 'main'` ); } catch (error) { console.error(error); From bde67bba5f80a687360ff272dff4cca096e04364 Mon Sep 17 00:00:00 2001 From: danstarns Date: Tue, 11 Feb 2025 16:52:42 -0800 Subject: [PATCH 4/4] refactor: ORG_NPM_TOKEN --- .github/workflows/release-grapesjs-react-latest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-grapesjs-react-latest.yml b/.github/workflows/release-grapesjs-react-latest.yml index 70dcb54..421b348 100644 --- a/.github/workflows/release-grapesjs-react-latest.yml +++ b/.github/workflows/release-grapesjs-react-latest.yml @@ -16,7 +16,7 @@ jobs: run: yarn build:core - name: Publish to npm env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.ORG_NPM_TOKEN }} run: | echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> ./packages/grapesjs-react/.npmrc yarn publish:core:latest