🔨 自动更新CI

This commit is contained in:
目棃
2025-01-08 11:04:13 +08:00
parent 09f4a92256
commit be5ed0618e
3 changed files with 65 additions and 0 deletions

35
.github/workflows/auto-release.yml vendored Normal file
View File

@@ -0,0 +1,35 @@
name: AutoPublish
on:
schedule:
- cron: '0 0 15 * *' # 每个月的 15 号
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '23'
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: '9.15.0'
- name: Install Dependencies
run: pnpm install
- name: Update Tag
run: pnpm auto-update
- name: Get Tag
id: version
run: echo "VERSION=$(node -p 'require(`./packages/hula-emojis/package.json`).version')" >> $GITHUB_ENV
- name: Commit Changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "🍱 Update version to ${{ env.VERSION }}"
git tag v${{ env.VERSION }}
git push origin HEAD:main --follow-tags

View File

@@ -10,6 +10,7 @@
"scripts": {
"dev": "lerna run dev --scope demo --stream",
"clean": "lerna clean -y",
"auto-update": "tsx scripts/auto-update.ts",
"prepare": "husky"
},
"lint-staged": {

29
scripts/auto-update.ts Normal file
View File

@@ -0,0 +1,29 @@
/**
* @file scripts/auto-update.ts
* @description 自动更新版本号
* @since 2025-01-08
*/
import ora from "ora";
import { writeFileSync, readFileSync } from "fs";
import { resolve } from "path";
const hulaEmojisDir = resolve(__dirname, "../packages/hula-emojis");
const versionSp = ora("检测版本号中...").start();
const pkgPath = resolve(hulaEmojisDir, "package.json");
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
const version = pkg.version.split(".");
const patch = parseInt(version[2]) + 1;
const newVersion = `${version[0]}.${version[1]}.${patch}`;
pkg.version = newVersion;
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
versionSp.succeed(`版本号更新为:${newVersion}`);
const changeSp = ora("生成变更日志中...").start();
const changelogPath = resolve(hulaEmojisDir, "CHANGELOG.md");
const changelog = readFileSync(changelogPath, "utf-8").split("\n");
changelog.splice(0, 2);
const date = new Date().toISOString().split("T")[0];
const newLines = ["# 更新日志", "", `## ${newVersion} (${date})`, "", "- 🍱 CI自动更新版本号", ""];
changelog.unshift(...newLines);
writeFileSync(changelogPath, changelog.join("\n"));
changeSp.succeed("变更日志生成成功");