From 52edf300fe1bcdca8a40a0f3bb5b4f1ab92dd41c Mon Sep 17 00:00:00 2001 From: huanhuanwa <44698191+huanhuanwa@users.noreply.github.com> Date: Mon, 15 Jul 2024 14:57:37 +0800 Subject: [PATCH] build: add release config (#6) --- .changeset/README.md | 8 --- .changeset/config.json | 11 ----- .changeset/dirty-dingos-visit.md | 5 -- .changeset/gentle-knives-dress.md | 5 -- .changeset/nervous-eels-hear.md | 5 -- .changeset/sour-bees-argue.md | 5 -- .github/workflows/ci.yml | 31 ++++++++++++ .github/workflows/release.yml | 82 +++++++++++++++++++++++++++++++ .wpmrc.js | 16 ++++++ CHANGELOG.md | 0 angular.json | 5 +- package.json | 19 ++++--- packages/grid/src/test.ts | 9 ++++ scripts/pre-release.js | 19 +++++++ 14 files changed, 171 insertions(+), 49 deletions(-) delete mode 100644 .changeset/README.md delete mode 100644 .changeset/config.json delete mode 100644 .changeset/dirty-dingos-visit.md delete mode 100644 .changeset/gentle-knives-dress.md delete mode 100644 .changeset/nervous-eels-hear.md delete mode 100644 .changeset/sour-bees-argue.md create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml create mode 100644 .wpmrc.js create mode 100644 CHANGELOG.md create mode 100644 packages/grid/src/test.ts create mode 100644 scripts/pre-release.js diff --git a/.changeset/README.md b/.changeset/README.md deleted file mode 100644 index e5b6d8d6..00000000 --- a/.changeset/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Changesets - -Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works -with multi-package repos, or single-package repos to help you version and publish your code. You can -find the full documentation for it [in our repository](https://github.com/changesets/changesets) - -We have a quick list of common questions to get you started engaging with this project in -[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) diff --git a/.changeset/config.json b/.changeset/config.json deleted file mode 100644 index 2d7d21ac..00000000 --- a/.changeset/config.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$schema": "https://unpkg.com/@changesets/config@3.0.1/schema.json", - "changelog": "@changesets/cli/changelog", - "commit": false, - "fixed": [], - "linked": [], - "access": "restricted", - "baseBranch": "main", - "updateInternalDependencies": "patch", - "ignore": [] -} \ No newline at end of file diff --git a/.changeset/dirty-dingos-visit.md b/.changeset/dirty-dingos-visit.md deleted file mode 100644 index 0f1c6d0e..00000000 --- a/.changeset/dirty-dingos-visit.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"ai-table": patch ---- - -init ai-table diff --git a/.changeset/gentle-knives-dress.md b/.changeset/gentle-knives-dress.md deleted file mode 100644 index 63dedb70..00000000 --- a/.changeset/gentle-knives-dress.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@ai-table/grid': patch ---- - -move event listener to AITableGridEventService diff --git a/.changeset/nervous-eels-hear.md b/.changeset/nervous-eels-hear.md deleted file mode 100644 index e53847f4..00000000 --- a/.changeset/nervous-eels-hear.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@ai-table/grid': patch ---- - -support display rating and link field diff --git a/.changeset/sour-bees-argue.md b/.changeset/sour-bees-argue.md deleted file mode 100644 index 06c3d83a..00000000 --- a/.changeset/sour-bees-argue.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@ai-table/grid': patch ---- - -support dateTime field editor diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..06040db6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,31 @@ +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs + +name: Node.js CI + +on: + push: + branches: [ "develop" ] + pull_request: + branches: [ "develop" ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: npm install --force + - run: npm run build + - run: npm run ci:test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..2a0e0cec --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,82 @@ +name: Publish + +on: + pull_request: + types: + - opened + - reopened + pull_request_review: + types: + - submitted + check_suite: + types: + - completed + status: {} + +jobs: + autoApprove: + if: startsWith(github.head_ref, 'release-auto-') + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - uses: hmarr/auto-approve-action@v4 + with: + review-message: 'Auto approve sync PRs to auto merge them' + publish: + if: startsWith(github.head_ref, 'release-auto-') + needs: [autoApprove] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + - name: Setup Node.js + uses: actions/setup-node@v1 + with: + node-version: 18 + registry-url: 'https://registry.npmjs.org' + - name: Install dependencies + run: npm ci --force + - name: Publish + if: startsWith(github.head_ref, 'release-auto-v') + run: | + git config user.name github-actions + git config user.email github-actions@github.com + npm run pub + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Publish-next + if: startsWith(github.head_ref, 'release-auto-next-v') + run: | + git config user.name github-actions + git config user.email github-actions@github.com + npm run pub-next + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Read package.json + id: read-version + uses: notiz-dev/github-action-json-property@release + with: + path: 'package.json' + prop_path: 'version' + - name: send message to webhook + uses: joelwmale/webhook-action@master + with: + url: 'https://hook-rc.pingcode.com/api/flow/w/http/357bdd4f00f34bfab2f878ad3b9e8b48' + body: '{ "version": "${{ steps.read-version.outputs.prop }}", "name": "ai-table" }' + autoMerge: + if: startsWith(github.head_ref, 'release-auto-') + needs: [publish] + runs-on: ubuntu-latest + steps: + - id: autoMerge + name: autoMerge + uses: 'pascalgn/automerge-action@v0.15.5' + env: + GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + MERGE_LABELS: '' + MERGE_FORKS: 'false' + MERGE_RETRIES: '20' + MERGE_RETRY_SLEEP: '60000' diff --git a/.wpmrc.js b/.wpmrc.js new file mode 100644 index 00000000..70619764 --- /dev/null +++ b/.wpmrc.js @@ -0,0 +1,16 @@ +module.exports = { + allowBranch: ['main', 'release-auto-*'], + bumpFiles: ['package.json', 'package-lock.json', 'packages/grid/package.json'], + skip: { + confirm: true + }, + // backward compatibility changelog + // because we didn't use tag prefix(v) when create tag before + // should set tagPrefix as empty (default is 'v') + // otherwise, the changelog will rebuild, and will be lost past versions + tagPrefix: '', + hooks: { + prepublish: 'npm run build', + prereleaseBranch: 'node ./scripts/pre-release.js {{version}}' + } +}; diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..e69de29b diff --git a/angular.json b/angular.json index 7f59a3f1..08474fef 100644 --- a/angular.json +++ b/angular.json @@ -98,13 +98,12 @@ "test": { "builder": "@angular-devkit/build-angular:karma", "options": { - "main": "packages/grid/test.ts", + "main": "packages/grid/src/test.ts", "tsConfig": "packages/grid/tsconfig.spec.json", "karmaConfig": "packages/grid/karma.conf.js", "codeCoverage": true, "codeCoverageExclude": [ - "packages/grid/testing/**/*", - "packages/core/test/**/*" + "packages/grid/testing/**/*" ] } }, diff --git a/package.json b/package.json index de5b666f..6a006cb9 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,13 @@ "start": "ng serve", "build": "npm run build:grid", "build:grid": "ng build grid && cpx \"./packages/grid/src/**/*.scss\" ./dist/grid/", + "release": "wpm release --release-branch-format release-auto-v{{version}}", + "release-next": "wpm release --release-branch-format release-auto-next-v{{version}}", + "release-manual": "wpm release", + "release-next-manual": "wpm release --release-branch-format release-next-v{{version}}", "watch": "ng build --watch --configuration development", - "test": "ng test" + "pub": "cd dist/grid && npm publish", + "test": "ng test grid" }, "private": true, "dependencies": { @@ -23,18 +28,14 @@ "@angular/platform-browser": "^18.0.0", "@angular/platform-browser-dynamic": "^18.0.0", "@angular/router": "^18.0.0", - "@changesets/cli": "^2.27.5", "@tethys/cdk": "^17.0.8", "@tethys/icons": "^1.4.62", - "cpx": "^1.5.0", + "immer": "^10.0.3", "date-fns": "^3.6.0", - "ng-packagr": "^18.0.0", "ngx-tethys": "^17.0.8", "npm": "^10.8.1", "rxjs": "~7.8.0", "tslib": "^2.6.3", - "y-websocket": "^2.0.3", - "yjs": "^13.6.16", "zone.js": "~0.14.3" }, "devDependencies": { @@ -49,6 +50,10 @@ "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.1.0", "prettier": "^3.3.2", - "typescript": "~5.4.2" + "typescript": "~5.4.2", + "ng-packagr": "^18.0.0", + "cpx": "^1.5.0", + "@worktile/pkg-manager": "^0.1.0", + "chalk": "^2.4.2" } } diff --git a/packages/grid/src/test.ts b/packages/grid/src/test.ts new file mode 100644 index 00000000..61720dc8 --- /dev/null +++ b/packages/grid/src/test.ts @@ -0,0 +1,9 @@ +// This file is required by karma.conf.js and loads recursively all the .spec and framework files + +import 'zone.js'; +import 'zone.js/testing'; +import { getTestBed } from '@angular/core/testing'; +import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; + +// First, initialize the Angular testing environment. +getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), { teardown: { destroyAfterEach: true } }); diff --git a/scripts/pre-release.js b/scripts/pre-release.js new file mode 100644 index 00000000..ea0d6b8e --- /dev/null +++ b/scripts/pre-release.js @@ -0,0 +1,19 @@ +const chalk = require('chalk'); + +const command = process.env.npm_lifecycle_event; +const args = process.argv; +const version = args[2]; + +if (version.includes('next') && !command.includes('next')) { + console.log( + chalk.bgRed.black('[ERROR]'), + chalk.red(`✘ Publish the next version, please use ${chalk.blue('npm run release-next')}`), + ); + process.exit(1); +} else if (!version.includes('next') && command.includes('next')) { + console.log( + chalk.bgRed.black('[ERROR]'), + chalk.red(`✘ Publish the latest version, please use ${chalk.blue('npm run release')}`), + ); + process.exit(1); +}