diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9881e22bd..a21f7c0f3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -94,11 +94,32 @@ jobs: echo "jdk_installed=false" >> $GITHUB_ENV fi + # 缓存 JDK + - name: 缓存 JDK + if: env.jdk_installed == 'false' + uses: actions/cache@v3 + with: + path: ~/.sdkman/candidates + key: ${{ runner.os }}-jdk-11-${{ hashFiles('**/build.gradle*') }} + restore-keys: | + ${{ runner.os }}-jdk-11- + + - name: 安装 JDK 11 + if: env.jdk_installed == 'false' && env.should_build == 'true' + run: | + sudo apt update + sudo apt install -y openjdk-11-jdk + + - name: 验证 JDK 安装 + if: env.should_build == 'true' + run: | + java -version + # 检查 Gradle 是否已安装 - name: 检查 Gradle 是否已安装 id: check_gradle run: | - if ./gradlew -v &>/dev/null; then + if gradle -v &>/dev/null; then echo "Gradle 已安装" echo "gradle_installed=true" >> $GITHUB_ENV else @@ -106,34 +127,25 @@ jobs: echo "gradle_installed=false" >> $GITHUB_ENV fi - # 缓存 JDK - - name: 缓存 JDK - if: env.jdk_installed == 'false' - uses: actions/cache@v3 - with: - path: ~/.sdkman/candidates - key: ${{ runner.os }}-jdk-11-${{ hashFiles('**/build.gradle*') }} - restore-keys: | - ${{ runner.os }}-jdk-11- - # 缓存 Gradle - - name: 手动缓存 Gradle 构建 + - name: 缓存 Gradle if: env.gradle_installed == 'false' uses: actions/cache@v3 with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-build-${{ hashFiles('**/gradle-wrapper.properties') }} + path: ~/.gradle + key: ${{ runner.os }}-gradle-${{ hashFiles('**/build.gradle*') }} restore-keys: | - ${{ runner.os }}-gradle-build- - + ${{ runner.os }}-gradle- - - name: 安装 JDK 11 - if: env.jdk_installed == 'false' && env.should_build == 'true' + # 安装 Gradle + - name: 安装 Gradle + if: env.gradle_installed == 'false' && env.should_build == 'true' run: | sudo apt update - sudo apt install -y openjdk-11-jdk + sudo apt install -y gradle - - name: 验证 JDK 安装 + # 验证 Gradle 安装 + - name: 验证 Gradle 安装 if: env.should_build == 'true' run: | - java -version \ No newline at end of file + gradle -v