From 1b5b615070e4bd948efd82310e45b9143b309e61 Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Mon, 11 Mar 2024 10:26:04 +0800 Subject: [PATCH 1/3] ci(npm): cli release --- .github/workflows/release-cli.yml | 24 ++++++++++++++++ .npmignore | 2 ++ .npmrc | 1 + bin/release.js | 47 +++++++++++++++++++++++++++++++ package.json | 1 + 5 files changed, 75 insertions(+) create mode 100644 .github/workflows/release-cli.yml create mode 100644 .npmignore create mode 100644 .npmrc create mode 100644 bin/release.js diff --git a/.github/workflows/release-cli.yml b/.github/workflows/release-cli.yml new file mode 100644 index 0000000..07407b4 --- /dev/null +++ b/.github/workflows/release-cli.yml @@ -0,0 +1,24 @@ +name: Create Cli Release + +on: + push: + tags: + - 'cli-v*' + +jobs: + build: + runs-on: ubuntu-latest + if: github.repository == 'doocs/md' + steps: + - uses: actions/checkout@v3 + # Setup .npmrc file to publish to npm + - uses: actions/setup-node@v3 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org' + - run: npm install + - run: npm run build-cli + - run: cd md-cli && npm ci && npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..f185b90 --- /dev/null +++ b/.npmignore @@ -0,0 +1,2 @@ +.tgz +httpData/ diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..38f11c6 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +registry=https://registry.npmjs.org diff --git a/bin/release.js b/bin/release.js new file mode 100644 index 0000000..d7f106b --- /dev/null +++ b/bin/release.js @@ -0,0 +1,47 @@ +import fs from 'node:fs' +import { fileURLToPath } from 'url'; +import path, { dirname } from 'node:path'; +import * as child_process from 'node:child_process' +import packageJson from '../package.json' assert { type: "json" }; +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); +(async function () { + // 自动更新版本 + // version可以传递如 6.1.1 | patch | minor | major + const execCommand = arr => (Array.isArray(arr) ? arr : [arr]).forEach(c => { + try { + console.log(`start: ${c}...`) + console.log(child_process.execSync(c).toString('utf8')) + } catch (error) { + console.log('\x1B[31m%s\x1B[0m', error.stdout.toString()) + process.exit(1) + } + }) + const getNewVersion = (oldVersion, version = 'patch') => { + // [ | major | minor | patch] + if (/^([0-9]+\.*)+$/.test(version)) return version + const types = ['major', 'minor', 'patch'] + const index = types.indexOf(version) + if (index >= 0) { + const versionArr = oldVersion.split('.') + versionArr[index] = Number(versionArr[index]) + 1 + return versionArr.map((e, i) => i > index ? 0 : e).join('.') + } + return getNewVersion(oldVersion) + } + const newVersionObj = { + version: getNewVersion(packageJson.version, process.argv[2]), + }; + fs.writeFileSync( + path.resolve(__dirname, '../package.json'), + JSON.stringify(Object.assign({}, packageJson, newVersionObj), null, 2) + + '\n' + ); + console.log(newVersionObj); + execCommand([ + `git commit -a -m 'chore: update version cli-v${newVersionObj.version}'`, + `git tag cli-v${newVersionObj.version}`, + 'git push && git push --tags', + ]) + console.log('\x1B[32m%s\x1B[0m', '发布完成,请关注github CI构建') +}()) diff --git a/package.json b/package.json index 0d60a9d..17eee0f 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "lc": "node bin/lc.js -d src", "lk": "node bin/lk.js -d src", "lf": "node bin/lf.js -d src", + "release:cli": "node ./bin/release.js", "update": "node scripts/update.js", "build-cli": "node esbuild.config.js", "publish-cli": "cd pl-cli && npm publish --registry https://registry.npmjs.org/", From 1289fda262d0821c185f4a69ae76a8dc5921ed66 Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Mon, 11 Mar 2024 10:31:09 +0800 Subject: [PATCH 2/3] fix: update --- .github/workflows/contributors.yml | 6 +-- .github/workflows/pr-add-label.yml | 4 +- .github/workflows/release-cli.yml | 5 +-- README.md | 2 +- bin/release.js | 71 ++++++++++++++++-------------- common/utils/file/getRootPath.js | 1 + 6 files changed, 47 insertions(+), 42 deletions(-) diff --git a/.github/workflows/contributors.yml b/.github/workflows/contributors.yml index 209c6f7..077900d 100644 --- a/.github/workflows/contributors.yml +++ b/.github/workflows/contributors.yml @@ -2,7 +2,7 @@ name: gen-org-contributors on: schedule: - - cron: "0 0 * * *" + - cron: '0 0 * * *' workflow_dispatch: jobs: @@ -16,5 +16,5 @@ jobs: png_path: images/contributors.png json_path: contributors.json branch: svg - commit_message: "chore: update contributors" - excludes_list: "ImgBotApp,github-actions[bot],actions-user,imgbot[bot],dependabot[bot]" \ No newline at end of file + commit_message: 'chore: update contributors' + excludes_list: 'ImgBotApp,github-actions[bot],actions-user,imgbot[bot],dependabot[bot]' diff --git a/.github/workflows/pr-add-label.yml b/.github/workflows/pr-add-label.yml index 5eb10eb..e3e8cae 100644 --- a/.github/workflows/pr-add-label.yml +++ b/.github/workflows/pr-add-label.yml @@ -20,5 +20,5 @@ jobs: with: github_token: ${{ secrets.ACTION_TOKEN }} pr_number: ${{ env.PR_NUMBER }} - organize_name: "EternalHeartTeam" - team_name: "eternalheartteam" + organize_name: EternalHeartTeam + team_name: eternalheartteam diff --git a/.github/workflows/release-cli.yml b/.github/workflows/release-cli.yml index 07407b4..87c2c7a 100644 --- a/.github/workflows/release-cli.yml +++ b/.github/workflows/release-cli.yml @@ -8,7 +8,7 @@ on: jobs: build: runs-on: ubuntu-latest - if: github.repository == 'doocs/md' + if: github.repository == 'EternalHeartTeam/leetcode-practice' steps: - uses: actions/checkout@v3 # Setup .npmrc file to publish to npm @@ -18,7 +18,6 @@ jobs: registry-url: 'https://registry.npmjs.org' - run: npm install - run: npm run build-cli - - run: cd md-cli && npm ci && npm publish + - run: npm ci && npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} - diff --git a/README.md b/README.md index 1a1a1df..d1ed329 100644 --- a/README.md +++ b/README.md @@ -499,4 +499,4 @@ If you encounter any `issues` or have some `great suggestions`, feel free to joi ## Star History -[![Star History Chart](https://api.star-history.com/svg?repos=EternalHeartTeam/leetcode-practice&type=Date)](https://star-history.com/#EternalHeartTeam/leetcode-practice&Date) \ No newline at end of file +[![Star History Chart](https://api.star-history.com/svg?repos=EternalHeartTeam/leetcode-practice&type=Date)](https://star-history.com/#EternalHeartTeam/leetcode-practice&Date) diff --git a/bin/release.js b/bin/release.js index d7f106b..0f81b06 100644 --- a/bin/release.js +++ b/bin/release.js @@ -1,22 +1,24 @@ import fs from 'node:fs' -import { fileURLToPath } from 'url'; -import path, { dirname } from 'node:path'; +import { fileURLToPath } from 'node:url' +import path, { dirname } from 'node:path' import * as child_process from 'node:child_process' -import packageJson from '../package.json' assert { type: "json" }; -const __filename = fileURLToPath(import.meta.url); -const __dirname = dirname(__filename); -(async function () { +import packageJson from '../package.json' assert { type: 'json' } + +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) +;(async function () { // 自动更新版本 // version可以传递如 6.1.1 | patch | minor | major - const execCommand = arr => (Array.isArray(arr) ? arr : [arr]).forEach(c => { - try { - console.log(`start: ${c}...`) - console.log(child_process.execSync(c).toString('utf8')) - } catch (error) { - console.log('\x1B[31m%s\x1B[0m', error.stdout.toString()) - process.exit(1) - } - }) + const execCommand = (arr) => + (Array.isArray(arr) ? arr : [arr]).forEach((c) => { + try { + console.log(`start: ${c}...`) + console.log(child_process.execSync(c).toString('utf8')) + } catch (error) { + console.log('\x1B[31m%s\x1B[0m', error.stdout.toString()) + process.exit(1) + } + }) const getNewVersion = (oldVersion, version = 'patch') => { // [ | major | minor | patch] if (/^([0-9]+\.*)+$/.test(version)) return version @@ -25,23 +27,26 @@ const __dirname = dirname(__filename); if (index >= 0) { const versionArr = oldVersion.split('.') versionArr[index] = Number(versionArr[index]) + 1 - return versionArr.map((e, i) => i > index ? 0 : e).join('.') + return versionArr.map((e, i) => (i > index ? 0 : e)).join('.') } return getNewVersion(oldVersion) - } - const newVersionObj = { - version: getNewVersion(packageJson.version, process.argv[2]), - }; - fs.writeFileSync( - path.resolve(__dirname, '../package.json'), - JSON.stringify(Object.assign({}, packageJson, newVersionObj), null, 2) + - '\n' - ); - console.log(newVersionObj); - execCommand([ - `git commit -a -m 'chore: update version cli-v${newVersionObj.version}'`, - `git tag cli-v${newVersionObj.version}`, - 'git push && git push --tags', - ]) - console.log('\x1B[32m%s\x1B[0m', '发布完成,请关注github CI构建') -}()) + } + const newVersionObj = { + version: getNewVersion(packageJson.version, process.argv[2]) + } + fs.writeFileSync( + path.resolve(__dirname, '../package.json'), + `${JSON.stringify( + Object.assign({}, packageJson, newVersionObj), + null, + 2 + )}\n` + ) + console.log(newVersionObj) + execCommand([ + `git commit -a -m 'chore: update version cli-v${newVersionObj.version}'`, + `git tag cli-v${newVersionObj.version}`, + 'git push && git push --tags' + ]) + console.log('\x1B[32m%s\x1B[0m', '发布完成,请关注github CI构建') +})() diff --git a/common/utils/file/getRootPath.js b/common/utils/file/getRootPath.js index 5f7b831..0971a80 100644 --- a/common/utils/file/getRootPath.js +++ b/common/utils/file/getRootPath.js @@ -1,6 +1,7 @@ import path from 'node:path' import { __dirname } from '#common/utils/file/getDirname.js' import { currentEnv } from '#common/utils/etc/checkEnv.js' + // 在cli环境下 执行目录为 bin 目录 根目录就是上一层目录 export const rootPath = currentEnv() === 'project' From 20f17934b94d3e40bed4445fe209bcc73fe0bbd8 Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Mon, 11 Mar 2024 10:33:55 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E8=BF=99=E4=B8=AA=E4=B8=8D=E9=9C=80=E8=A6=81=E5=9C=A8?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AB=AF=E5=AE=9A=E6=97=B6=E8=B7=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/contributors.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/contributors.yml b/.github/workflows/contributors.yml index 077900d..0d7b46e 100644 --- a/.github/workflows/contributors.yml +++ b/.github/workflows/contributors.yml @@ -8,6 +8,7 @@ on: jobs: generate: runs-on: ubuntu-latest + if: github.repository == 'EternalHeartTeam/leetcode-practice' steps: - uses: thinkasany/organize-contributors@master with: