diff --git a/.github/workflows/publish-cli.yml b/.github/workflows/publish-cli.yml new file mode 100644 index 000000000..71ffbe83d --- /dev/null +++ b/.github/workflows/publish-cli.yml @@ -0,0 +1,17 @@ +name: Publish GrapesJS CLI +on: + push: + branches: [dev] + paths: + - 'packages/cli/**' + +jobs: + publish: + if: "contains(github.event.head_commit.message, 'Release GrapesJS cli:')" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup-project + - name: Publish Core + run: pnpm publish --access public + working-directory: ./packages/cli diff --git a/.github/workflows/publish-core-latest.yml b/.github/workflows/publish-core-latest.yml new file mode 100644 index 000000000..f85565630 --- /dev/null +++ b/.github/workflows/publish-core-latest.yml @@ -0,0 +1,26 @@ +name: Publish GrapesJS Core +on: + push: + branches: [dev] + paths: + - 'packages/core/**' + +jobs: + publish: + if: "contains(github.event.head_commit.message, 'Release GrapesJS core latest:')" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup-project + - name: Build cli + run: pnpm run build:cli + - name: Build core + run: pnpm run build:core + - name: Check core TS + run: pnpm run ts:check + - name: Publish to npm + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> ./packages/core/.npmrc + yarn publish:core:latest diff --git a/.github/workflows/publish-core-rc.yml b/.github/workflows/publish-core-rc.yml new file mode 100644 index 000000000..7ac9ad7fc --- /dev/null +++ b/.github/workflows/publish-core-rc.yml @@ -0,0 +1,26 @@ +name: Publish GrapesJS Core +on: + push: + branches: [dev] + paths: + - 'packages/core/**' + +jobs: + publish: + if: "contains(github.event.head_commit.message, 'Release GrapesJS core rc:')" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup-project + - name: Build cli + run: pnpm run build:cli + - name: Build core + run: pnpm run build:core + - name: Check core TS + run: pnpm run ts:check + - name: Publish to npm + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> ./packages/core/.npmrc + yarn publish:core:rc diff --git a/package.json b/package.json index 094ae02ba..10420183e 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,15 @@ "ts:check": "pnpm --filter grapesjs ts:check", "clean": "find . -type d \\( -name \"node_modules\" -o -name \"build\" -o -name \"dist\" \\) -exec rm -rf {} + && rm ./pnpm-lock.yaml", "format": "prettier . --write --ignore-path .prettierignore", - "format:check": "prettier . --check --ignore-path .prettierignore" + "format:check": "prettier . --check --ignore-path .prettierignore", + "release:core:rc": "ts-node scripts/releaseCore rc", + "release:core:latest": "ts-node scripts/releaseCore latest", + "release:cli:rc": "ts-node scripts/releaseCli rc", + "release:cli:latest": "ts-node scripts/releaseCli latest", + "publish:core:rc": "cd packages/core && npm publish --tag rc --access public", + "publish:core:latest": "cd packages/core && npm publish --access public", + "build:core": "pnpm --filter grapesjs build", + "build:cli": "pnpm --filter grapesjs-cli build" }, "devDependencies": { "@babel/cli": "7.24.8", diff --git a/scripts/common.ts b/scripts/common.ts new file mode 100644 index 000000000..989ff0433 --- /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/releaseCli.ts b/scripts/releaseCli.ts new file mode 100644 index 000000000..8f235d6c3 --- /dev/null +++ b/scripts/releaseCli.ts @@ -0,0 +1,36 @@ +import fs from 'fs'; +import { resolve } from 'path'; +import { runCommand } from './common'; + +const pathLib = resolve(__dirname, '../packages/cli'); + +async function prepareCoreRelease() { + try { + const releaseTag = process.argv[2] || 'rc'; + console.log('Prepare release cli tag:', releaseTag); + + // Check if the current branch is clean (no staged changes) + runCommand( + 'git diff-index --quiet HEAD --', + 'You have uncommitted changes. Please commit or stash them before running the release script.', + ); + + // Increment the CLI version + const versionCmd = releaseTag === 'latest' ? 'patch' : `prerelease --preid ${releaseTag}`; + runCommand(`pnpm --filter grapesjs-cli exec npm version ${versionCmd} --no-git-tag-version --no-commit-hooks`); + + // Create a new release branch + const newVersion = JSON.parse(fs.readFileSync(`${pathLib}/package.json`, 'utf8')).version; + const newBranch = `release-v${newVersion}`; + runCommand(`git checkout -b ${newBranch}`); + runCommand('git add .'); + runCommand(`git commit -m "Release GrapesJS cli ${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); + } +} + +prepareCoreRelease(); diff --git a/scripts/releaseCore.ts b/scripts/releaseCore.ts new file mode 100644 index 000000000..085098bfa --- /dev/null +++ b/scripts/releaseCore.ts @@ -0,0 +1,36 @@ +import fs from 'fs'; +import { resolve } from 'path'; +import { runCommand } from './common'; + +const pathLib = resolve(__dirname, '../packages/core'); + +async function prepareCoreRelease() { + try { + const releaseTag = process.argv[2] || 'rc'; + console.log('Prepare release core tag:', releaseTag); + + // Check if the current branch is clean (no staged changes) + runCommand( + 'git diff-index --quiet HEAD --', + 'You have uncommitted changes. Please commit or stash them before running the release script.', + ); + + // Increment the Core version + const versionCmd = releaseTag === 'latest' ? 'patch' : `prerelease --preid ${releaseTag}`; + runCommand(`pnpm --filter grapesjs exec npm version ${versionCmd} --no-git-tag-version --no-commit-hooks`); + + // Create a new release branch + const newVersion = JSON.parse(fs.readFileSync(`${pathLib}/package.json`, 'utf8')).version; + const newBranch = `release-v${newVersion}`; + runCommand(`git checkout -b ${newBranch}`); + runCommand('git add .'); + runCommand(`git commit -m "Release GrapesJS core ${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); + } +} + +prepareCoreRelease();