Skip to content

ci(npm): cli release #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ name: gen-org-contributors

on:
schedule:
- cron: "0 0 * * *"
- cron: '0 0 * * *'
workflow_dispatch:

jobs:
generate:
runs-on: ubuntu-latest
if: github.repository == 'EternalHeartTeam/leetcode-practice'
steps:
- uses: thinkasany/organize-contributors@master
with:
Expand All @@ -16,5 +17,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]"
commit_message: 'chore: update contributors'
excludes_list: 'ImgBotApp,github-actions[bot],actions-user,imgbot[bot],dependabot[bot]'
4 changes: 2 additions & 2 deletions .github/workflows/pr-add-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions .github/workflows/release-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Create Cli Release

on:
push:
tags:
- 'cli-v*'

jobs:
build:
runs-on: ubuntu-latest
if: github.repository == 'EternalHeartTeam/leetcode-practice'
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: npm ci && npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.tgz
httpData/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry=https://registry.npmjs.org
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
[![Star History Chart](https://api.star-history.com/svg?repos=EternalHeartTeam/leetcode-practice&type=Date)](https://star-history.com/#EternalHeartTeam/leetcode-practice&Date)
52 changes: 52 additions & 0 deletions bin/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import fs from 'node:fs'
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 () {
// 自动更新版本
// 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') => {
// [<newversion> | 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构建')
})()
1 change: 1 addition & 0 deletions common/utils/file/getRootPath.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down