run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 on: push: branches: - master # 监听master分支 jobs: build-common-modules: runs-on: ubuntu steps: - name: Checkout Repository uses: http://git.missmoc.top/mocheng/checkout@v4 - name: Set up environment (JDK + Maven) run: | echo "JAVA_HOME=/java17/java17" >> $GITHUB_ENV echo "$JAVA_HOME/bin" >> $GITHUB_PATH # 配置Maven echo "MAVEN_HOME=/maven/apache-maven-3.9.11" >> $GITHUB_ENV echo "$MAVEN_HOME/bin" >> $GITHUB_PATH echo "Java version:" java -version echo "Maven version:" /maven/apache-maven-3.9.11/bin/mvn -v echo "JAVA_HOME: $JAVA_HOME" echo "MAVEN_HOME: $MAVEN_HOME" - name: Configure Maven settings run: | # 创建Maven配置文件,添加必要仓库 mkdir -p ~/.m2 cat > ~/.m2/settings.xml << EOF central https://repo1.maven.org/maven2 central dromara-repo https://maven.dromara.org/repository/releases/ dromara EOF - name: Build and install common modules run: | # 构建并安装项目通用模块(根据实际项目结构调整) # 核心通用模块 if [ -f "./ruoyi-common/pom.xml" ]; then /maven/apache-maven-3.9.11/bin/mvn clean install -DskipTests -f ./ruoyi-common/pom.xml else echo "Warning: ruoyi-common module not found" fi # API模块 if [ -f "./ruoyi-api/pom.xml" ]; then /maven/apache-maven-3.9.11/bin/mvn clean install -DskipTests -f ./ruoyi-api/pom.xml else echo "Warning: ruoyi-api module not found" fi # BOM模块 if [ -f "./ruoyi-common-bom/pom.xml" ]; then /maven/apache-maven-3.9.11/bin/mvn clean install -DskipTests -f ./ruoyi-common-bom/pom.xml else echo "Warning: ruoyi-common-bom module not found" fi # 其他通用模块(根据实际情况添加) # if [ -f "./other-common-module/pom.xml" ]; then # $MAVEN_HOME/bin/mvn clean install -DskipTests -f ./other-common-module/pom.xml # fi # 主任务:构建并推送各服务镜像 build-and-push: needs: build-common-modules # 依赖通用模块构建完成 runs-on: ubuntu strategy: matrix: service: - ruoyi-auth - ruoyi-gateway - ruoyi-modules/Property - ruoyi-modules/ruoyi-gen - ruoyi-modules/ruoyi-job - ruoyi-modules/ruoyi-resource - ruoyi-modules/ruoyi-system - ruoyi-modules/ruoyi-workflow - ruoyi-modules/Sis - ruoyi-visual/ruoyi-monitor - ruoyi-visual/ruoyi-nacos - ruoyi-seata-server - ruoyi-sentinel-dashboard - ruoyi-snailjob-server steps: - name: Checkout Repository uses: http://git.missmoc.top/mocheng/checkout@v4 - name: Set up Node.js (if needed) uses: http://git.missmoc.top/mocheng/setup-node@v3 with: node-version: '16' if: ${{ contains(matrix.service, 'frontend') || contains(matrix.service, 'vue') }} - name: Set up environment (JDK + Maven) run: | # 配置环境变量 echo "JAVA_HOME=/java17/java17" >> $GITHUB_ENV echo "$JAVA_HOME/bin" >> $GITHUB_PATH echo "MAVEN_HOME=/maven/apache-maven-3.9.11" >> $GITHUB_ENV echo "$MAVEN_HOME/bin" >> $GITHUB_PATH # 验证环境 echo "Java version:" java -version echo "Maven version:" $MAVEN_HOME/bin/mvn -v - name: Build Project with Maven run: | # 检查服务目录是否存在 if [ ! -d "./${{ matrix.service }}" ]; then echo "Error: Service directory ${{ matrix.service }} not found" exit 1 fi # 检查pom.xml是否存在 if [ ! -f "./${{ matrix.service }}/pom.xml" ]; then echo "Error: pom.xml not found in ${{ matrix.service }}" exit 1 fi # 执行构建 $MAVEN_HOME/bin/mvn clean package -DskipTests -f ./${{ matrix.service }}/pom.xml # 检查构建结果 if [ ! -d "./${{ matrix.service }}/target" ]; then echo "Error: Build failed, target directory not found" exit 1 fi echo "Build successful for ${{ matrix.service }}" ls -la ./${{ matrix.service }}/target/ - name: Set Up Docker Buildx uses: http://git.missmoc.top/mocheng/setup-buildx-action@v3 - name: Login to Gitea Container Registry uses: http://git.missmoc.top/mocheng/login-action@v3 with: registry: ${{ secrets.REGISTRY_URL }} username: ${{ secrets.REGISTRY_USER }} password: ${{ secrets.REGISTRY_PASS }} - name: Determine Dockerfile Path id: dockerfile-path run: | service_path="${{ matrix.service }}" # 检查默认路径 default_dockerfile="$service_path/Dockerfile" # 检查通用路径 common_dockerfile="Dockerfile" if [ -f "$default_dockerfile" ]; then echo "dockerfile_path=$default_dockerfile" >> $GITHUB_OUTPUT echo "Using Dockerfile at $default_dockerfile" elif [ -f "$common_dockerfile" ]; then echo "dockerfile_path=$common_dockerfile" >> $GITHUB_OUTPUT echo "Using root Dockerfile for $service_path" else echo "Error: Dockerfile not found for $service_path" exit 1 fi - name: Build and Push Docker Image uses: http://git.missmoc.top/mocheng/build-push-action@v5 with: context: . file: ${{ steps.dockerfile-path.outputs.dockerfile_path }} tags: ${{ secrets.REGISTRY_URL }}/by2025/${{ matrix.service }}:${{ github.sha }} push: true # 启用缓存加速构建 cache-from: type=gha cache-to: type=gha,mode=max # 构建参数 build-args: | SERVICE_NAME=${{ matrix.service }} BUILD_TIMESTAMP=$(date +%Y%m%d%H%M%S) # 显示构建详情 progress: plain