فهرست منبع

【维护】重构 GitHub Actions 工作流以提高可维护性

- 新增输入参数以自定义 OS 名称
- 创建专门的环境设置脚本 (gh_acions_setup.bash)
- 移除冗余的构建步骤
- 优化 ISO 上传步骤
PJ568 1 سال پیش
والد
کامیت
55588c334c
3فایلهای تغییر یافته به همراه78 افزوده شده و 36 حذف شده
  1. 9 35
      .github/workflows/build_iso.yaml
  2. 1 1
      build.bash
  3. 68 0
      scripts/gh_acions_setup.bash

+ 9 - 35
.github/workflows/build_iso.yaml

@@ -2,6 +2,11 @@ name: Build PageOS ISO
 
 on:
   workflow_dispatch:
+    inputs:
+      name:
+        description: "OS name"
+        required: false
+        default: "pageos"
 
 concurrency:
   group: "测试"
@@ -15,52 +20,21 @@ jobs:
       options: --privileged
 
     steps:
-      - name: Setup system
-        run: |
-          # 安装sudo
-          pacman -Syu --noconfirm --needed sudo
-          # 初始化 pacman
-          pacman-key --init
-          pacman-key --populate archlinux
-          # 创建 builder 用户和组
-          useradd -m -s /bin/bash builder
-          echo 'builder ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
-          groupadd -f alpm
-          usermod -aG alpm builder
-          # 启用 multilib 仓库
-          printf '\n%s\n%s\n' '[multilib]' 'Include = /etc/pacman.d/mirrorlist' >> /etc/pacman.conf
-          grep -A1 "\[multilib\]" /etc/pacman.conf
-          pacman -Syy --noconfirm --needed zellij|| true
-
-      - name: Install dependencies
-        run: |
-          # 安装基础依赖
-          pacman -Sy --noconfirm archiso reflector git base-devel sudo
-
-          # 安装 aurutils
-          sudo -u builder git clone https://aur.archlinux.org/aurutils.git /home/builder/aurutils
-          cd /home/builder/aurutils
-          sudo -u builder makepkg -si --noconfirm
-
       - name: Checkout repository
         uses: actions/checkout@v4
         with:
           repository: swaybien/pageos
 
-      - name: Make build script executable
-        run: chmod +x build.bash
+      - name: Setup actions environment
+        run: ./scripts/gh_acions_setup.bash
 
       - name: Run build script
-        run: |
-          # 修复文件权限
-          chown -R builder:builder .
-          # 执行构建
-          sudo -u builder ./build.bash --noconfirm
+        run: sudo -u builder ./build.bash --noconfirm
 
       - name: Upload ISO artifact
         uses: actions/upload-artifact@v4
         with:
-          name: pageos-iso
+          name: ${{ github.event.inputs.name || 'pageos' }}
           path: target/*.iso
           compression-level: 9 # maximum compression
           retention-days: 5

+ 1 - 1
build.bash

@@ -61,7 +61,7 @@ handle_error() {
 trap 'handle_error ${LINENO} "$BASH_COMMAND"' ERR
 
 # 语言检测 | Language detection
-if [ $(echo ${LANG/_/-} | grep -Ei "\\b(zh|cn)\\b") ]; then CURRENT_LANG=1;  fi
+if [ $(echo ${LANG/_/-} | grep -Ei "\\b(zh|cn)\\b") ]; then CURRENT_LANG=1; fi
 
 # 创建 pacman.conf 文件 | Create pacman.conf file
 create_pacman_conf() {

+ 68 - 0
scripts/gh_acions_setup.bash

@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+
+# 设置定量 | Quantities
+## 当前脚本所在目录 | Script directory
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+## 仓库目录 | Repository directory
+REPO_DIR="$(dirname "$SCRIPT_DIR")"
+## 当前语言 | Current language
+CURRENT_LANG=0 # 0: en-US, 1: zh-Hans-CN
+
+# 本地化 | Localization
+recho() {
+  if [ $CURRENT_LANG == 1 ]; then
+    ## zh-Hans-CN
+    echo $1;
+  else
+    ## en-US
+    echo $2;
+  fi
+}
+
+# 语言检测 | Language detection
+if [ $(echo ${LANG/_/-} | grep -Ei "\\b(zh|cn)\\b") ]; then CURRENT_LANG=1;  fi
+
+# 显示脚本信息 | Display script info
+recho "开始执行 GitHub Actions 环境设置..." "Starting GitHub Actions environment setup..."
+recho "脚本目录: $SCRIPT_DIR" "Script directory: $SCRIPT_DIR"
+recho "仓库目录: $REPO_DIR" "Repository directory: $REPO_DIR"
+
+# 安装 sudo | Install sudo
+recho "正在安装 sudo..." "Installing sudo..."
+pacman -Syu --noconfirm --needed sudo
+
+# 初始化 pacman | Initialize pacman
+recho "正在初始化 pacman 密钥..." "Initializing pacman keys..."
+pacman-key --init
+pacman-key --populate archlinux
+
+# 创建 builder 用户和组 | Create builder user and group
+recho "正在创建 builder 用户和组..." "Creating builder user and group..."
+useradd -m -s /bin/bash builder
+echo 'builder ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
+groupadd -f alpm
+usermod -aG alpm builder
+
+# 启用 multilib 仓库 | Enable multilib
+recho "正在启用 multilib 仓库..." "Enabling multilib repository..."
+printf '\n%s\n%s\n' '[multilib]' 'Include = /etc/pacman.d/mirrorlist' >> /etc/pacman.conf
+grep -A1 "\[multilib\]" /etc/pacman.conf
+pacman -Syy --noconfirm --needed zellij|| true
+
+# 安装基础依赖 | Install base dependencies
+recho "正在安装基础依赖..." "Installing base dependencies..."
+pacman -Sy --noconfirm archiso reflector git base-devel sudo
+
+# 安装 aurutils | Install aurutils
+recho "正在安装 aurutils..." "Installing aurutils..."
+sudo -u builder git clone https://aur.archlinux.org/aurutils.git /home/builder/aurutils
+cd /home/builder/aurutils && cd $REPO_DIR
+sudo -u builder makepkg -si --noconfirm
+
+# 修复文件权限 | Fix file permissions
+recho "正在修复文件权限..." "Fixing file permissions..."
+chown -R builder:builder $REPO_DIR
+
+# 完成提示 | Completion message
+recho "环境设置完成!" "Environment setup completed!"
+recho "然后需手动执行 sudo -u builder $REPO_DIR/build.bash --noconfirm" "Next, manually execute: sudo -u builder $REPO_DIR/build.bash --noconfirm"