Browse Source

Release CI infra (#6224)

pull/6233/head
Daniel Starns 1 year ago
committed by GitHub
parent
commit
13deac7558
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 17
      .github/workflows/publish-cli.yml
  2. 26
      .github/workflows/publish-core-latest.yml
  3. 26
      .github/workflows/publish-core-rc.yml
  4. 10
      package.json
  5. 10
      scripts/common.ts
  6. 36
      scripts/releaseCli.ts
  7. 36
      scripts/releaseCore.ts

17
.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

26
.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

26
.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

10
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",

10
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;
}
}

36
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();

36
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();
Loading…
Cancel
Save