Skip to content

Commit 087ba9a

Browse files
update: code
1 parent 640f9dc commit 087ba9a

49 files changed

Lines changed: 2856 additions & 2399 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 152 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,158 @@
1-
name: 构建和发布
1+
name: 发布新版本
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
version:
7-
description: '版本号(自增)'
8-
required: false
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: '版本号(自增)'
8+
required: false
99

1010
permissions:
11-
contents: write
11+
contents: write
1212

1313
jobs:
14-
build:
15-
name: 构建和上传发布资产
16-
runs-on: ubuntu-latest
17-
18-
steps:
19-
- name: 结账代码
20-
uses: actions/checkout@v3
21-
with:
22-
fetch-depth: 0 # 获取完整 tag 历史
23-
24-
- name: 检查分支
25-
if: github.ref != 'refs/heads/main'
26-
run: |
27-
echo "错误: 该工作流只能在 main 分支上运行。"
28-
exit 1
29-
30-
- name: 设置Node.js
31-
uses: actions/setup-node@v3
32-
with:
33-
node-version: '22'
34-
35-
- name: 安装依赖项
36-
run: |
37-
yarn install --ignore-engines
38-
39-
- name: 自动获取/自增版本号
40-
id: versioning
41-
run: |
42-
# 如果用户输入 version,则直接用
43-
if [[ -n "${{ github.event.inputs.version }}" ]]; then
44-
VERSION="v${{ github.event.inputs.version }}"
45-
else
46-
# 自动获取最新 tag
47-
LATEST_TAG=$(git tag --sort=-v:refname | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$" | head -n 1)
48-
if [ -z "$LATEST_TAG" ]; then
49-
VERSION="v0.0.1"
50-
else
51-
VERSION_NUM=${LATEST_TAG#v}
52-
MAJOR=$(echo $VERSION_NUM | cut -d. -f1)
53-
MINOR=$(echo $VERSION_NUM | cut -d. -f2)
54-
PATCH=$(echo $VERSION_NUM | cut -d. -f3)
55-
PATCH=$((PATCH + 1))
56-
VERSION="v$MAJOR.$MINOR.$PATCH"
57-
fi
58-
fi
59-
echo "version=$VERSION" >> $GITHUB_OUTPUT
60-
echo "本次发布版本号: $VERSION"
61-
62-
- name: 打包
63-
run: |
64-
yarn build
65-
mkdir -p dist-release
66-
cp -rf ./lib dist-release/lib
67-
cp -rf ./.puppeteerrc.cjs dist-release/.puppeteerrc.cjs
68-
cp -rf ./package.json dist-release/package.json
69-
cp -rf ./README.md dist-release/README.md
70-
# 检查 dist 目录是否存在且不为空
71-
if [[ ! -d dist-release || -z $(ls -A dist-release) ]]; then
72-
echo "错误: 'dist' 目录不存在或为空,构建步骤可能失败。"
73-
exit 1
74-
fi
75-
# 转移产物
76-
mv dist-release ../dist-release
77-
78-
- name: 推送 release
79-
run: |
80-
DEPLOY_BRANCH="release"
81-
git fetch origin $DEPLOY_BRANCH || echo "远程分支 $DEPLOY_BRANCH 不存在,准备创建..."
82-
if ! git show-ref --verify --quiet refs/remotes/origin/$DEPLOY_BRANCH; then
83-
git checkout -b $DEPLOY_BRANCH
84-
git push origin $DEPLOY_BRANCH
85-
else
86-
git checkout $DEPLOY_BRANCH
87-
fi
88-
89-
# 删除依赖
90-
rm -rf node_modules
91-
rm -rf .gitignore
92-
93-
# 清理非 git 文件夹的其他内容
94-
find . -mindepth 1 ! -path './.git*' -exec rm -rf {} + || {
95-
echo "错误: 文件查找并删除出现意外"
96-
}
97-
98-
# 移动 dist 文件夹内容到根目录
99-
mv ../dist-release/* ./ || {
100-
echo "错误: 无法将 'dist-release' 目录中的文件移动到根目录,目录可能为空。"
101-
exit 1
102-
}
103-
104-
# 去除 package.json 中一些字段
105-
jq 'del(.devDependencies)' package.json > package.json.tmp && mv package.json.tmp package.json
106-
jq 'del(.workspaces)' package.json > package.json.tmp && mv package.json.tmp package.json
107-
jq 'del(.private)' package.json > package.json.tmp && mv package.json.tmp package.json
108-
jq 'del(.scripts)' package.json > package.json.tmp && mv package.json.tmp package.json
109-
jq --arg version "${{ steps.versioning.outputs.version }}" '.version = ($version | sub("^v";""))' package.json > package.json.tmp && mv package.json.tmp package.json
110-
111-
# 开始产出
112-
git config --local user.email "ningmengchongshui@gmail.com"
113-
git config --local user.name "ningmengchongshui"
114-
git config --local push.autoSetupRemote true
115-
git add -A
116-
git commit -m "${{ steps.versioning.outputs.version }}"
117-
git push origin $DEPLOY_BRANCH || {
118-
echo "错误:推送失败,请检查..."
119-
exit 1
120-
}
121-
env:
122-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123-
124-
- name: 打 tag 并推送
125-
run: |
126-
TAG="${{ steps.versioning.outputs.version }}"
127-
git tag -f $TAG
128-
git push origin $TAG --force
129-
env:
130-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14+
build:
15+
name: 构建和上传发布资产
16+
runs-on: macos-latest
17+
18+
steps:
19+
- name: 结账代码
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0 # 获取完整 tag 历史
23+
24+
- name: 检查分支
25+
if: github.ref != 'refs/heads/main'
26+
run: |
27+
echo "错误: 该工作流只能在 main 分支上运行。"
28+
exit 1
29+
30+
- name: 设置nodejs版本
31+
uses: actions/setup-node@v4
32+
with:
33+
node-version: '22'
34+
35+
# - name: 缓存前端依赖
36+
# uses: actions/cache@v3
37+
# with:
38+
# path: frontend/node_modules
39+
# key: ${{ runner.os }}-frontend-${{ hashFiles('frontend/yarn.lock') }}
40+
41+
- name: 缓存游戏依赖
42+
uses: actions/cache@v3
43+
with:
44+
path: node_modules
45+
key: ${{ runner.os }}-root-${{ hashFiles('yarn.lock') }}
46+
47+
- name: 检查yarn工具
48+
run: |
49+
if ! command -v yarn &> /dev/null; then
50+
npm install -g yarn
51+
fi
52+
53+
# - name: 安装前端依赖
54+
# run: |
55+
# cd frontend && yarn install --ignore-engines
56+
57+
- name: 安装游戏依赖
58+
run: |
59+
yarn install --ignore-engines
60+
61+
- name: 自动获取/自增版本号
62+
id: versioning
63+
run: |
64+
# 如果用户输入 version,则直接用
65+
if [[ -n "${{ github.event.inputs.version }}" ]]; then
66+
VERSION="v${{ github.event.inputs.version }}"
67+
else
68+
# 自动获取最新 tag
69+
LATEST_TAG=$(git tag --sort=-v:refname | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$" | head -n 1)
70+
if [ -z "$LATEST_TAG" ]; then
71+
VERSION="v0.0.1"
72+
else
73+
VERSION_NUM=${LATEST_TAG#v}
74+
MAJOR=$(echo $VERSION_NUM | cut -d. -f1)
75+
MINOR=$(echo $VERSION_NUM | cut -d. -f2)
76+
PATCH=$(echo $VERSION_NUM | cut -d. -f3)
77+
PATCH=$((PATCH + 1))
78+
VERSION="v$MAJOR.$MINOR.$PATCH"
79+
fi
80+
fi
81+
echo "version=$VERSION" >> $GITHUB_OUTPUT
82+
echo "本次发布版本号: $VERSION"
83+
84+
- name: 打包
85+
run: |
86+
yarn build
87+
# yarn bundle # bundle
88+
mkdir -p dist-release
89+
# cp -rf ./dist dist-release/dist # bundle
90+
cp -rf ./lib dist-release/lib
91+
cp -rf ./.puppeteerrc.cjs dist-release/.puppeteerrc.cjs
92+
cp -rf ./package.json dist-release/package.json
93+
cp -rf ./README.md dist-release/README.md
94+
# 检查 dist 目录是否存在且不为空
95+
if [[ ! -d dist-release || -z $(ls -A dist-release) ]]; then
96+
echo "错误: 'dist' 目录不存在或为空,构建步骤可能失败。"
97+
exit 1
98+
fi
99+
# 转移产物
100+
mv dist-release ../dist-release
101+
102+
- name: 推送 release
103+
run: |
104+
DEPLOY_BRANCH="release"
105+
git fetch origin $DEPLOY_BRANCH || echo "远程分支 $DEPLOY_BRANCH 不存在,准备创建..."
106+
if ! git show-ref --verify --quiet refs/remotes/origin/$DEPLOY_BRANCH; then
107+
git checkout -b $DEPLOY_BRANCH
108+
git push origin $DEPLOY_BRANCH
109+
else
110+
git checkout $DEPLOY_BRANCH
111+
fi
112+
113+
# 删除依赖
114+
rm -rf node_modules
115+
rm -rf .gitignore
116+
117+
# 清理非 git 文件夹的其他内容(保护 .git 目录)
118+
find . -mindepth 1 ! -path './.git*' -exec rm -rf {} + || true
119+
120+
# 移动 dist-release 文件夹内容到根目录
121+
mv ../dist-release/* ./ || {
122+
echo "错误: 无法将 'dist-release' 目录中的文件移动到根目录,目录可能为空。"
123+
exit 1
124+
}
125+
126+
# 检查 .git 是否还在
127+
if [ ! -d .git ]; then
128+
echo "错误:.git 目录已丢失,无法进行后续 git 操作"
129+
exit 1
130+
fi
131+
132+
# 去除 package.json 中一些字段
133+
jq 'del(.devDependencies)' package.json > package.json.tmp && mv package.json.tmp package.json
134+
jq 'del(.workspaces)' package.json > package.json.tmp && mv package.json.tmp package.json
135+
jq 'del(.private)' package.json > package.json.tmp && mv package.json.tmp package.json
136+
jq 'del(.scripts)' package.json > package.json.tmp && mv package.json.tmp package.json
137+
jq --arg version "${{ steps.versioning.outputs.version }}" '.version = ($version | sub("^v";""))' package.json > package.json.tmp && mv package.json.tmp package.json
138+
139+
# 开始产出
140+
git config --local user.email "ningmengchongshui@gmail.com"
141+
git config --local user.name "ningmengchongshui"
142+
git config --local push.autoSetupRemote true
143+
git add -A
144+
git commit -m "${{ steps.versioning.outputs.version }}"
145+
git push origin $DEPLOY_BRANCH || {
146+
echo "错误:推送失败,请检查..."
147+
exit 1
148+
}
149+
env:
150+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
151+
152+
- name: 打 tag 并推送
153+
run: |
154+
TAG="${{ steps.versioning.outputs.version }}"
155+
git tag -f $TAG
156+
git push origin $TAG --force
157+
env:
158+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/check-dev.yml

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,53 @@
1-
name: 推送检验
1+
name: 基础推送检验
22

33
on:
4-
push:
5-
branches:
6-
- dev-*
7-
- for/dev-*
4+
push:
5+
branches:
6+
- main
7+
- dev-*
8+
- test-*
9+
- for/dev-*
810

911
jobs:
10-
build-to-deploy:
11-
runs-on: macos-latest
12-
13-
steps:
14-
- name: 检出代码库
15-
uses: actions/checkout@v2
16-
17-
- name: 缓存Node.js模块
18-
uses: actions/cache@v3
19-
with:
20-
path: |
21-
frontend/node_modules
22-
key: ${{ runner.os }}-node-${{ hashFiles('frontend/package-lock.json', 'frontend/yarn.lock') }}
23-
restore-keys: |
24-
${{ runner.os }}-node-
25-
26-
- name: 设置nodejs版本
27-
uses: actions/setup-node@v2
28-
with:
29-
node-version: '22'
30-
31-
- name: 加载依赖
32-
run: |
33-
yarn install --ignore-engines
34-
35-
- name: 格式化检查
36-
run: |
37-
yarn format
38-
yarn eslint
39-
40-
- name: 打包测试
41-
run: |
42-
yarn build
12+
build-to-deploy:
13+
runs-on: macos-latest
14+
15+
steps:
16+
- name: 检出代码库
17+
uses: actions/checkout@v4
18+
19+
- name: 设置nodejs版本
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '22'
23+
24+
# - name: 缓存前端依赖
25+
# uses: actions/cache@v3
26+
# with:
27+
# path: frontend/node_modules
28+
# key: ${{ runner.os }}-frontend-${{ hashFiles('frontend/yarn.lock') }}
29+
30+
- name: 缓存游戏依赖
31+
uses: actions/cache@v3
32+
with:
33+
path: node_modules
34+
key: ${{ runner.os }}-root-${{ hashFiles('yarn.lock') }}
35+
36+
- name: 检查yarn工具
37+
run: |
38+
if ! command -v yarn &> /dev/null; then
39+
npm install -g yarn
40+
fi
41+
42+
# - name: 安装前端依赖
43+
# run: |
44+
# cd frontend && yarn install --ignore-engines --frozen-lockfile
45+
46+
- name: 安装游戏依赖
47+
run: |
48+
yarn install --ignore-engines --frozen-lockfile
49+
50+
- name: 打包测试
51+
run: |
52+
yarn build || echo "build 脚本执行失败或不存在"
53+
# yarn bundle || echo "bundle 脚本执行失败或不存在"

0 commit comments

Comments
 (0)