diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 6d04369e4..940feda69 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -1,16 +1,15 @@ -name: Publish Docs +name: Publish GrapesJS Docs on: push: - tags: - - 'docs-*' - branches: - - dev + branches: [dev] + paths: + - 'packages/docs/**' jobs: publish-docs: runs-on: ubuntu-latest - if: github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/docs-') + if: "contains(github.event.head_commit.message, 'Release GrapesJS docs:')" permissions: contents: write steps: diff --git a/package.json b/package.json index 10489dea0..c4adaecd9 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "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", + "release:docs": "ts-node scripts/releaseCore latest", "build:cli": "pnpm --filter grapesjs-cli build", "build:docs:api": "pnpm --filter @grapesjs/docs docs:api", "build:docs": "pnpm --filter @grapesjs/docs build" diff --git a/scripts/releaseDocs.ts b/scripts/releaseDocs.ts new file mode 100644 index 000000000..e1817d61d --- /dev/null +++ b/scripts/releaseDocs.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]; + console.log('Prepare release docs 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/docs 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 docs ${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();