diff --git a/.github/workflows/autofix.yml b/.github/workflows/autofix.yml index 51cef3aad..c19283ea7 100644 --- a/.github/workflows/autofix.yml +++ b/.github/workflows/autofix.yml @@ -3,6 +3,8 @@ on: pull_request: push: branches: [ "main" ] + paths: + - "!scripts/**" permissions: contents: read diff --git a/.github/workflows/changelogensets.yml b/.github/workflows/changelogensets.yml new file mode 100644 index 000000000..bf0876c38 --- /dev/null +++ b/.github/workflows/changelogensets.yml @@ -0,0 +1,36 @@ +name: Release + +on: + push: + branches: + - main + +permissions: + pull-requests: write + contents: write + +concurrency: + group: ${{ github.workflow }}-${{ github.event.number || github.sha }} + cancel-in-progress: ${{ github.event_name != 'push' }} + +jobs: + update-changelog: + if: github.repository_owner == 'oku-ui' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - run: corepack enable + - uses: actions/setup-node@v3 + with: + node-version: 20 + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + + - run: pnpm jiti ./scripts/update-changelog.ts + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/chromatic.yml b/.github/workflows/chromatic.yml index cdc3a59e5..4d1bf2eb4 100644 --- a/.github/workflows/chromatic.yml +++ b/.github/workflows/chromatic.yml @@ -4,6 +4,9 @@ on: push: branches: - main + paths: + - "!scripts/**" + # "You must append a colon (:) to all events, including events without configuration." # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-using-multiple-events-with-activity-types-or-configuration pull_request: @@ -11,6 +14,7 @@ on: - 'packages/components/**' - '.storybook/**' - 'package.json' + - "!scripts/**" permissions: contents: write diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 951f3d8b5..5db5821b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,10 +11,14 @@ on: push: branches: - main + paths: + - "!scripts/**" pull_request: branches: - main + paths: + - "!scripts/**" jobs: build-test: diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..c44e8e902 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,100 @@ +# Changelog + + +## ...main + + +### 🚀 Enhancements + + - Structure (#35) + - Primitive (#39) + - Use-callback-ref package (#41) + - Label package (#42) + - Aspect-ratio (#43) + - Provide core package (#44) + - Avatar (#46) + - Playground vue3 (#47) + - Playground nuxt3 (#48) + - Packages core and components folder create (#51) + - Storybook (#54) + - **compose-refs:** New package (84620fe) + - **use-previous:** New package (3636d75) + - **use-size:** New package (5ff1387) + - **OkuSeparator:** Create new component (#83) + - Element type (#85) + - Utils package (#86) + - **checkbox:** New component (#87) + - New struct storybook folder (#93) + - Add OkuProgress component (#89) + - Vue 3.3 support structural change (#96) + - RefElement and primitive add new types (#99) + - **toggle:** New component (#111) + +### 🩹 Fixes + + - Github folder name (95b04d4) + - Optimize expose (#84) + - **progress:** Stroybook and fix some progress bugs (#98) + - Checkbox (#113) + - **deps:** Update dependency @antfu/eslint-config to ^0.38.6 (#116) + +### 💅 Refactors + + - Vite build change to unbuild (#92) + - **label:** Add merge props with @oku-ui/utils (#94) + - Cleanup configs and package.json files (#100) + - **core:** One package use-composable (#109) + +### 🏡 Chora + + - Update readme (1aafefe) + - Update readme (49e98ef) + - Fix github (a804142) + - Add issuas link (8cdacbf) + - Fix readme (fd1025e) + - Fix readme (3d8963f) + - Fix readme (819e7d0) + - Drop the numbers (a0f8cea) + - Fix drop published (ad63d38) + - Fix toggle typo and add contributor (316e1d1) + - Add thank you new message (3ddf1c6) + - Add sponsors readme (#31) + - Fix readme (1930d6e) + - Update readme (024afed) + - Update renovate (aff3ded) + - Update renovate (d823836) + - Update renovate (0a0bc81) + - Update readme (026ba28) + - Add chromatic (#56) + - Storybook theme (#63) + - Add more scripts and update contributing (#68) + - Fix primitive ref (#71) + - Fix aspect-ratio change ratio type to number and change the div element (#73) + - Fix tsconfig (#74) + - Fix ref expose (#76) + - Feat use-controllable-ref package (#77) + - Fix pnpmlock (4d18463) + - Fix turbo build dependsOn (29db953) + - Update package.json (d5ea788) + - Update renovate (7829a2c) + - Change struct label storybook demo vue (#90) + - Auto import component nuxt playground (#91) + - Add label test (#95) + - Fix build (4ab9372) + - Refactor unbuild settings (#97) + - Update readme (3312737) + - **separator:** Add test (#102) + - Fix dev mode (78eecfa) + - Update README (#112) + - Pnpm overrides (590c6c0) + +### ❤️ Contributors + +- Productdevbook +- Faithful Ojebiyi ([@faithfulojebiyi](http://github.com/faithfulojebiyi)) +- Mehmet +- Suxiong +- Victor Akintunde +- Sadegh Barati ([@sadeghbarati](http://github.com/sadeghbarati)) +- Fatih Yıldız + diff --git a/changelog.config.ts b/changelog.config.ts new file mode 100644 index 000000000..6e0843f43 --- /dev/null +++ b/changelog.config.ts @@ -0,0 +1,29 @@ +import type { ChangelogConfig } from 'changelogen' + +function getDefaultConfig() { + return >{ + types: { + version: { title: '🔖 Version', semver: 'patch' }, + feat: { title: '🚀 Enhancements', semver: 'minor' }, + perf: { title: '🔥 Performance', semver: 'patch' }, + fix: { title: '🩹 Fixes', semver: 'patch' }, + refactor: { title: '💅 Refactors', semver: 'patch' }, + docs: { title: '📖 Documentation', semver: 'patch' }, + build: { title: '📦 Build', semver: 'patch' }, + types: { title: '🌊 Types', semver: 'patch' }, + chore: { title: '🏡 Chore' }, + examples: { title: '🏀 Examples' }, + test: { title: '✅ Tests' }, + style: { title: '🎨 Styles' }, + ci: { title: '🤖 CI' }, + }, + repo: { + repo: 'oku-ui/primitives', + provider: 'github', + domain: 'github.com', + token: process.env.GITHUB_TOKEN, + }, + } +} + +export default getDefaultConfig diff --git a/package.json b/package.json index 505aa2c48..820bf8955 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { - "name": "oku-ui", + "name": "primitives", "type": "module", - "private": true, + "version": "0.1.0", "packageManager": "pnpm@8.3.0", + "repository": "oku-ui/primitives", "scripts": { "p:build": "tsup", "build": "turbo run build --filter='./packages/**'", @@ -45,11 +46,14 @@ "@vitejs/plugin-vue": "^4.2.2", "@vitest/coverage-c8": "^0.31.0", "@vue/test-utils": "^2.3.2", + "changelogen": "^0.5.3", "chromatic": "^6.17.4", "eslint": "8.39.0", "eslint-config-custom": "workspace:*", "eslint-plugin-storybook": "^0.6.12", + "jiti": "^1.18.2", "jsdom": "^22.0.0", + "ofetch": "^1.0.1", "react": "^18.2.0", "react-dom": "^18.2.0", "rimraf": "^5.0.0", diff --git a/packages/components/aspect-ratio/package.json b/packages/components/aspect-ratio/package.json index 25ec75a1b..00749160e 100644 --- a/packages/components/aspect-ratio/package.json +++ b/packages/components/aspect-ratio/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/aspect-ratio", "type": "module", - "version": "1.0.0", + "version": "0.0.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/components/checkbox/package.json b/packages/components/checkbox/package.json index 4c9b06f71..43772a454 100644 --- a/packages/components/checkbox/package.json +++ b/packages/components/checkbox/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/checkbox", "type": "module", - "version": "1.0.0", + "version": "0.0.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/components/progress/package.json b/packages/components/progress/package.json index 20d4bdcd1..8ec9f42d4 100644 --- a/packages/components/progress/package.json +++ b/packages/components/progress/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/progress", "type": "module", - "version": "1.0.0", + "version": "0.0.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/provide/package.json b/packages/core/provide/package.json index df2d930b3..2c69c8130 100644 --- a/packages/core/provide/package.json +++ b/packages/core/provide/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/provide", "type": "module", - "version": "1.0.0", + "version": "0.0.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/core/use-composable/package.json b/packages/core/use-composable/package.json index d1e60abd1..4d8e78117 100644 --- a/packages/core/use-composable/package.json +++ b/packages/core/use-composable/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/use-composable", "type": "module", - "version": "1.0.0", + "version": "0.0.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/packages/example-package/package.json b/packages/example-package/package.json index 7134dac33..6064674af 100644 --- a/packages/example-package/package.json +++ b/packages/example-package/package.json @@ -1,7 +1,7 @@ { "name": "@oku-ui/example", "type": "module", - "version": "1.0.0", + "version": "0.0.0", "license": "MIT", "source": "src/index.ts", "funding": "https://github.com/sponsors/productdevbook", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 382b1e3e2..e6c3614cf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -65,6 +65,9 @@ importers: '@vue/test-utils': specifier: ^2.3.2 version: 2.3.2(vue@3.3.2) + changelogen: + specifier: ^0.5.3 + version: 0.5.3 chromatic: specifier: ^6.17.4 version: 6.17.4 @@ -77,9 +80,15 @@ importers: eslint-plugin-storybook: specifier: ^0.6.12 version: 0.6.12(eslint@8.39.0)(typescript@5.0.4) + jiti: + specifier: ^1.18.2 + version: 1.18.2 jsdom: specifier: ^22.0.0 version: 22.0.0 + ofetch: + specifier: ^1.0.1 + version: 1.0.1 react: specifier: ^18.2.0 version: 18.2.0 @@ -4532,7 +4541,7 @@ packages: debug: 4.3.4 globby: 11.1.0 is-glob: 4.0.3 - semver: 7.5.0 + semver: 7.5.1 tsutils: 3.21.0(typescript@5.0.4) typescript: 5.0.4 transitivePeerDependencies: @@ -6378,6 +6387,13 @@ packages: semver: 7.5.1 dev: false + /bundle-name@3.0.0: + resolution: {integrity: sha512-PKA4BeSvBpQKQ8iPOGCSiell+N8P+Tf1DlwqmYhpe2gAhKPHn8EYOxVT+ShuGmhg8lN8XiSlS80yiExKXrURlw==} + engines: {node: '>=12'} + dependencies: + run-applescript: 5.0.0 + dev: true + /bundle-require@4.0.1(esbuild@0.17.18): resolution: {integrity: sha512-9NQkRHlNdNpDBGmLpngF3EFDcwodhMUuLz9PaWYciVcQF9SE4LFjM2DB/xV1Li5JiuDMv7ZUWuC3rGbqR0MAXQ==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} @@ -6539,6 +6555,28 @@ packages: engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} dev: true + /changelogen@0.5.3: + resolution: {integrity: sha512-RjTrgJlTHhbGlMo/s73j7uSTspla3ykr0UA5zwRs/HIZvElY6qZHu3X70httgC2Du5poS2wFCS10WLfwZr7ZTQ==} + hasBin: true + dependencies: + c12: 1.4.1 + colorette: 2.0.20 + consola: 3.1.0 + convert-gitmoji: 0.1.3 + execa: 7.1.1 + mri: 1.2.0 + node-fetch-native: 1.1.1 + ofetch: 1.0.1 + open: 9.1.0 + pathe: 1.1.0 + pkg-types: 1.0.3 + scule: 1.0.0 + semver: 7.5.1 + yaml: 2.2.2 + transitivePeerDependencies: + - supports-color + dev: true + /character-entities-legacy@1.1.4: resolution: {integrity: sha512-3Xnr+7ZFS1uxeiUDvV02wQ+QDbc55o97tIV5zHScSPJpcLm/r0DFPcoY3tYRp+VZukxuMeKgXYmsXQHO05zQeA==} dev: false @@ -6893,6 +6931,10 @@ packages: engines: {node: '>= 0.6'} dev: true + /convert-gitmoji@0.1.3: + resolution: {integrity: sha512-t5yxPyI8h8KPvRwrS/sRrfIpT2gJbmBAY0TFokyUBy3PM44RuFRpZwHdACz+GTSPLRLo3s4qsscOMLjHiXBwzw==} + dev: true + /convert-source-map@1.9.0: resolution: {integrity: sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==} dev: true @@ -7193,6 +7235,16 @@ packages: untildify: 4.0.0 dev: true + /default-browser@4.0.0: + resolution: {integrity: sha512-wX5pXO1+BrhMkSbROFsyxUm0i/cJEScyNhA4PPxc41ICuv05ZZB/MX28s8aZx6xjmatvebIapF6hLEKEcpneUA==} + engines: {node: '>=14.16'} + dependencies: + bundle-name: 3.0.0 + default-browser-id: 3.0.0 + execa: 7.1.1 + titleize: 3.0.0 + dev: true + /defaults@1.0.4: resolution: {integrity: sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==} dependencies: @@ -7209,6 +7261,11 @@ packages: engines: {node: '>=8'} dev: true + /define-lazy-prop@3.0.0: + resolution: {integrity: sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg==} + engines: {node: '>=12'} + dev: true + /define-properties@1.2.0: resolution: {integrity: sha512-xvqAVKGfT1+UAvPwKTVw/njhdQ8ZhXK4lI0bCIuCMrp2up9nPnaDftrLtmpTazqd1o+UY4zgzU+avtMbDP+ldA==} engines: {node: '>= 0.4'} @@ -9242,6 +9299,14 @@ packages: resolution: {integrity: sha512-gyPJuv83bHMpocVYoqof5VDiZveEoGoFL8m3BXNb2VW8Xs+rz9kqO8LOQ5DH6EsuvilT1ApazU0pyl+ytbPtlw==} dev: false + /is-inside-container@1.0.0: + resolution: {integrity: sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA==} + engines: {node: '>=14.16'} + hasBin: true + dependencies: + is-docker: 3.0.0 + dev: true + /is-interactive@2.0.0: resolution: {integrity: sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==} engines: {node: '>=12'} @@ -10838,8 +10903,8 @@ packages: resolution: {integrity: sha512-icBz2JYfEpt+wZz1FRoGcrMigjNKjzvufE26m9+yUiacRQRHwnNlGRPiDnW4op7WX/MR6aniwS8xw8jyVelF2g==} dependencies: destr: 1.2.2 - node-fetch-native: 1.1.0 - ufo: 1.1.1 + node-fetch-native: 1.1.1 + ufo: 1.1.2 dev: true /ohash@1.1.2: @@ -10900,6 +10965,16 @@ packages: is-wsl: 2.2.0 dev: true + /open@9.1.0: + resolution: {integrity: sha512-OS+QTnw1/4vrf+9hh1jc1jnYjzSG4ttTBB8UxOwAnInG3Uo4ssetzC1ihqaIHjLJnA5GGlRl6QlZXOTQhRBUvg==} + engines: {node: '>=14.16'} + dependencies: + default-browser: 4.0.0 + define-lazy-prop: 3.0.0 + is-inside-container: 1.0.0 + is-wsl: 2.2.0 + dev: true + /openapi-typescript@6.2.4: resolution: {integrity: sha512-P/VK7oJ3TnIS67o1UzuS1pMnry4mzNzeQG0ZjLdPGT04mN9FeeTgHw1bN6MiANFN0tO6BcRavSL5tUFAh6iiwg==} hasBin: true @@ -12252,6 +12327,13 @@ packages: resolution: {integrity: sha512-APM0Gt1KoXBz0iIkkdB/kfvGOwC4UuJFeG/c+yV7wSc7q96cG/kJ0HiYCnzivD9SB53cLV1MlHFNfOuPaadYSw==} dev: true + /run-applescript@5.0.0: + resolution: {integrity: sha512-XcT5rBksx1QdIhlFOCtgZkB99ZEouFZ1E2Kc2LHqNW13U3/74YGdkQRmThTwxy4QIyookibDKYZOPqX//6BlAg==} + engines: {node: '>=12'} + dependencies: + execa: 5.1.1 + dev: true + /run-async@2.4.1: resolution: {integrity: sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ==} engines: {node: '>=0.12.0'} @@ -13047,6 +13129,11 @@ packages: engines: {node: '>=14.0.0'} dev: true + /titleize@3.0.0: + resolution: {integrity: sha512-KxVu8EYHDPBdUYdKZdKtU2aj2XfEx9AfjXxE/Aj0vT06w2icA09Vus1rh6eSu1y01akYg6BjIK/hxyLJINoMLQ==} + engines: {node: '>=12'} + dev: true + /tmp@0.0.33: resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==} engines: {node: '>=0.6.0'} @@ -13341,10 +13428,6 @@ packages: engines: {node: '>=12.20'} hasBin: true - /ufo@1.1.1: - resolution: {integrity: sha512-MvlCc4GHrmZdAllBc0iUDowff36Q9Ndw/UzqmEKyrfSzokTd9ZCy1i+IIk5hrYKkjoYVQyNbrw7/F8XJ2rEwTg==} - dev: true - /ufo@1.1.2: resolution: {integrity: sha512-TrY6DsjTQQgyS3E3dBaOXf0TpPD8u9FVrVYmKVegJuFw51n/YB9XPt+U6ydzFG5ZIN7+DIjPbNmXoBj9esYhgQ==} dev: true @@ -14320,7 +14403,7 @@ packages: espree: 9.5.2 esquery: 1.5.0 lodash: 4.17.21 - semver: 7.5.0 + semver: 7.5.1 transitivePeerDependencies: - supports-color dev: false diff --git a/scripts/_utils.ts b/scripts/_utils.ts new file mode 100644 index 000000000..464831a69 --- /dev/null +++ b/scripts/_utils.ts @@ -0,0 +1,83 @@ +import { promises as fsp } from 'node:fs' +import { resolve } from 'pathe' +import { execaSync } from 'execa' +import { determineSemverChange, getGitDiff, loadChangelogConfig, parseCommits } from 'changelogen' + +export interface Dep { + name: string + range: string + type: string +} + +type ThenArg = T extends PromiseLike ? U : T +export type Package = ThenArg> + +export async function loadPackage(dir: string) { + const pkgPath = resolve(dir, 'package.json') + const data = JSON.parse(await fsp.readFile(pkgPath, 'utf-8').catch(() => '{}')) + const save = () => fsp.writeFile(pkgPath, `${JSON.stringify(data, null, 2)}\n`) + + const updateDeps = (reviver: (dep: Dep) => Dep | void) => { + for (const type of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']) { + if (!data[type]) + continue + for (const e of Object.entries(data[type])) { + const dep: Dep = { name: e[0], range: e[1] as string, type } + delete data[type][dep.name] + const updated = reviver(dep) || dep + data[updated.type] = data[updated.type] || {} + data[updated.type][updated.name] = updated.range + } + } + } + + return { + dir, + data, + save, + updateDeps, + } +} + +export async function loadWorkspace(dir: string) { + const workspacePkg = await loadPackage(dir) + + const rename = (from: string, to: string) => { + workspacePkg.data._name = workspacePkg.data.name + workspacePkg.data.name = to + workspacePkg.updateDeps((dep) => { + if (dep.name === from && !dep.range.startsWith('npm:')) + dep.range = `npm:${to}@${dep.range}` + }) + } + + const setVersion = (newVersion: string, opts: { updateDeps?: boolean } = {}) => { + workspacePkg.data.version = newVersion + } + + const save = () => workspacePkg.save() + + return { + dir, + workspacePkg, + save, + rename, + setVersion, + } +} + +export async function determineBumpType() { + const config = await loadChangelogConfig(process.cwd()) + const commits = await getLatestCommits() + + const bumpType = determineSemverChange(commits, config) + + return bumpType === 'major' ? 'minor' : bumpType +} + +export async function getLatestCommits() { + const config = await loadChangelogConfig(process.cwd()) + const latestTag = execaSync('git', ['describe', '--tags', '--abbrev=0']).stdout + + return parseCommits(await getGitDiff(latestTag), config) +} diff --git a/scripts/add-tag.sh b/scripts/add-tag.sh new file mode 100644 index 000000000..d360dfab0 --- /dev/null +++ b/scripts/add-tag.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# get the version number from package.json +version=$(node -p -e "require('./package.json').version") +version="v$version" +# git tag it +git tag $version + +# push it +git push origin $version \ No newline at end of file diff --git a/scripts/update-changelog.ts b/scripts/update-changelog.ts new file mode 100644 index 000000000..1843b4655 --- /dev/null +++ b/scripts/update-changelog.ts @@ -0,0 +1,79 @@ +import { execSync } from 'node:child_process' +import { $fetch } from 'ofetch' +import { inc } from 'semver' +import { generateMarkDown, loadChangelogConfig } from 'changelogen' +import { determineBumpType, getLatestCommits, loadWorkspace } from './_utils' + +async function main() { + const workspace = await loadWorkspace(process.cwd()) + const config = await loadChangelogConfig(process.cwd()) + console.log(config) + const commits = await getLatestCommits().then(commits => commits.filter( + c => config.types[c.type] && !(c.type === 'chore' && c.scope === 'deps' && !c.isBreaking), + )) + const bumpType = await determineBumpType() + + const newVersion = inc(workspace.workspacePkg.data.version, bumpType || 'patch') + const changelog = await generateMarkDown(commits, config) + console.log(newVersion, 'newVersion') + console.log(changelog, 'changelog') + + // Create and push a branch with bumped versions if it has not already been created + const branchExists = execSync(`git ls-remote --heads origin v${newVersion}`).toString().trim().length > 0 + if (!branchExists) { + execSync('git config --global user.email "hi@productdevbook.com"') + execSync('git config --global user.name "productdevbook"') + execSync(`git checkout -b v${newVersion}`) + + workspace.setVersion(newVersion!) + + await workspace.save() + + execSync(`git commit -am v${newVersion}`) + execSync(`git push -u origin v${newVersion}`) + } + + // Get the current PR for this release, if it exists + const [currentPR] = await $fetch(`https://api.github.com/repos/oku-ui/primitives/pulls?head=oku-ui:v${newVersion}`) + + const releaseNotes = [ + currentPR?.body.replace(/## 👉 Changelog[\s\S]*$/, '') || `> ${newVersion} is the next ${bumpType} release.\n>\n> **Timetable**: to be announced.`, + '## 👉 Changelog', + changelog.replace(/^## v.*?\n/, '').replace('...main', `...v${newVersion}`), + ].join('\n') + + // Create a PR with release notes if none exists + if (!currentPR) { + return await $fetch('https://api.github.com/repos/oku-ui/primitives/pulls', { + method: 'POST', + headers: { + Authorization: `token ${process.env.GITHUB_TOKEN}`, + }, + body: { + title: `v${newVersion}`, + head: `v${newVersion}`, + base: 'main', + body: releaseNotes, + draft: true, + }, + }) + } + console.log(currentPR.number, 'currentPR.number') + console.log(releaseNotes, 'releaseNotes') + console.log('') + // Update release notes if the pull request does exist + await $fetch(`https://api.github.com/repos/oku-ui/primitives/pulls/${currentPR.number}`, { + method: 'PATCH', + headers: { + Authorization: `token ${process.env.GITHUB_TOKEN}`, + }, + body: { + body: releaseNotes, + }, + }) +} + +main().catch((err) => { + console.error(err) + process.exit(1) +})