mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-19 19:04:23 +08:00
添加 Android 打包工作流并实现响应式设计
- 在 GitHub Actions 中添加 Android 打包工作流,支持 ARM64、ARMv7 和 x86_64 架构 - 创建 CI 脚本用于解析提交信息和应用版本号 - 移除标题栏的旋转屏幕按钮,简化窗口控制 - 创建响应式设计 hooks (useResponsive) 用于检测屏幕尺寸 - 更新 StudentManager 组件以支持移动端响应式布局 - 在移动设备上自动调整表格列宽、按钮大小和字体大小 - 移动端隐藏标签列以节省空间 - 按钮在移动端使用垂直布局和更小的尺寸
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import fs from "fs"
|
||||
import path from "path"
|
||||
|
||||
const rawVersion = String(process.argv[2] || "")
|
||||
.trim()
|
||||
.replace(/^v/i, "")
|
||||
if (!rawVersion) {
|
||||
process.stderr.write("缺少版本号参数,例如:node scripts/ci/apply-version.mjs 1.2.3\n")
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const semverRe = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+([0-9A-Za-z.-]+))?$/
|
||||
|
||||
function toSemver(version) {
|
||||
if (semverRe.test(version)) {
|
||||
return version
|
||||
}
|
||||
|
||||
const parts = version.split(/[._-]/)
|
||||
const nums = parts.filter((p) => /^\d+$/.test(p))
|
||||
const nonNums = parts.filter((p) => !/^\d+$/.test(p) && p.length > 0)
|
||||
|
||||
let major = "0",
|
||||
minor = "0",
|
||||
patch = "0"
|
||||
let prerelease = ""
|
||||
let buildMeta = ""
|
||||
|
||||
if (nums.length >= 3) {
|
||||
major = nums[0]
|
||||
minor = nums[1]
|
||||
patch = nums[2]
|
||||
if (nums.length > 3) {
|
||||
buildMeta = nums.slice(3).join(".")
|
||||
}
|
||||
} else if (nums.length === 2) {
|
||||
major = nums[0]
|
||||
minor = nums[1]
|
||||
patch = "0"
|
||||
} else if (nums.length === 1) {
|
||||
major = nums[0]
|
||||
minor = "0"
|
||||
patch = "0"
|
||||
}
|
||||
|
||||
if (nonNums.length > 0) {
|
||||
if (prerelease) {
|
||||
prerelease += "." + nonNums.join(".")
|
||||
} else {
|
||||
prerelease = nonNums.join(".")
|
||||
}
|
||||
}
|
||||
|
||||
let result = `${major}.${minor}.${patch}`
|
||||
if (prerelease) {
|
||||
result += `-${prerelease}`
|
||||
}
|
||||
if (buildMeta) {
|
||||
result += `+${buildMeta}`
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
const version = toSemver(rawVersion)
|
||||
|
||||
process.stdout.write(`版本号转换: "${rawVersion}" -> "${version}"\n`)
|
||||
|
||||
const pkgPath = path.join(process.cwd(), "package.json")
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"))
|
||||
pkg.version = version
|
||||
fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`, "utf-8")
|
||||
@@ -0,0 +1,104 @@
|
||||
import fs from "fs"
|
||||
import path from "path"
|
||||
|
||||
const cwd = process.cwd()
|
||||
const pkgPath = path.join(cwd, "package.json")
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"))
|
||||
const scripts = pkg?.scripts ?? {}
|
||||
|
||||
const rawMessage =
|
||||
process.env.RELEASE_MESSAGE ??
|
||||
process.env.GITHUB_COMMIT_MESSAGE ??
|
||||
process.argv.slice(2).join(" ") ??
|
||||
""
|
||||
const message = String(rawMessage || "").trim()
|
||||
|
||||
const isReleasePrefix = /^release:/i.test(message)
|
||||
|
||||
const semverRe = /\bv?(\S+)/
|
||||
const versionMatch = message.match(semverRe)
|
||||
const version = versionMatch ? versionMatch[1] : ""
|
||||
|
||||
const buildToken =
|
||||
message.match(/\b(build:(?:win|mac|linux|android|unpack|all))\b/i)?.[1]?.toLowerCase() ?? ""
|
||||
let buildScript =
|
||||
buildToken === "build:all"
|
||||
? "build:all"
|
||||
: buildToken && buildToken.startsWith("build:")
|
||||
? buildToken
|
||||
: ""
|
||||
|
||||
if (isReleasePrefix && !buildScript) {
|
||||
buildScript = "build:all"
|
||||
}
|
||||
|
||||
const supportedBuildScripts = new Set([
|
||||
"build:win",
|
||||
"build:mac",
|
||||
"build:linux",
|
||||
"build:android",
|
||||
"build:unpack",
|
||||
])
|
||||
const hasBuildScript = buildScript
|
||||
? buildScript === "build:all"
|
||||
? true
|
||||
: typeof scripts[buildScript] === "string" && scripts[buildScript]
|
||||
: false
|
||||
|
||||
const fail = (text) => {
|
||||
process.stderr.write(`${text}\n`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const hasAnySignal = Boolean(isReleasePrefix || version || buildScript)
|
||||
const shouldSkip = !hasAnySignal
|
||||
|
||||
if (!shouldSkip) {
|
||||
if (!version) {
|
||||
fail(
|
||||
[
|
||||
"未在提交信息中检测到版本号。",
|
||||
"示例:release: v1.2.3 build:win 或 release: 1.2.3",
|
||||
"支持格式:v1.2.3 或 1.2.3(可带 -beta.1 等后缀)",
|
||||
].join("\n")
|
||||
)
|
||||
}
|
||||
|
||||
if (!buildScript) {
|
||||
fail(
|
||||
[
|
||||
"未在提交信息中检测到构建命令标记。",
|
||||
"示例:release: v1.2.3 build:win",
|
||||
"支持:build:win | build:mac | build:linux | build:android | build:unpack | build:all",
|
||||
].join("\n")
|
||||
)
|
||||
}
|
||||
|
||||
if (!hasBuildScript) {
|
||||
fail(`构建脚本不存在或为空:${buildScript}`)
|
||||
}
|
||||
}
|
||||
|
||||
const runWin = !shouldSkip && (buildScript === "build:all" || buildScript === "build:win")
|
||||
const runMac = !shouldSkip && (buildScript === "build:all" || buildScript === "build:mac")
|
||||
const runLinux = !shouldSkip && (buildScript === "build:all" || buildScript === "build:linux")
|
||||
const runAndroid = !shouldSkip && (buildScript === "build:all" || buildScript === "build:android")
|
||||
const runUnpack = !shouldSkip && buildScript === "build:unpack"
|
||||
|
||||
const outputs = {
|
||||
version: shouldSkip ? "" : version,
|
||||
tag: shouldSkip ? "" : `v${version}`,
|
||||
build_script: shouldSkip ? "" : buildScript,
|
||||
run_win: String(runWin),
|
||||
run_mac: String(runMac),
|
||||
run_linux: String(runLinux),
|
||||
run_android: String(runAndroid),
|
||||
run_unpack: String(runUnpack),
|
||||
}
|
||||
|
||||
if (process.env.GITHUB_OUTPUT) {
|
||||
const lines = Object.entries(outputs).map(([k, v]) => `${k}=${v}`)
|
||||
fs.appendFileSync(process.env.GITHUB_OUTPUT, `${lines.join("\n")}\n`)
|
||||
} else {
|
||||
process.stdout.write(`${JSON.stringify(outputs, null, 2)}\n`)
|
||||
}
|
||||
Reference in New Issue
Block a user