浏览代码

CI: parallel more tasks [skip ci]

SukkaW 1 周之前
父节点
当前提交
ad6bd46b59
共有 1 个文件被更改,包括 44 次插入31 次删除
  1. 44 31
      .github/workflows/main.yml

+ 44 - 31
.github/workflows/main.yml

@@ -21,43 +21,13 @@ jobs:
     steps:
       - uses: smorimoto/tune-github-hosted-runner-network@v1
         # https://github.com/actions/runner-images/issues/1187
-      - uses: actions/checkout@v6
+      - uses: actions/checkout@v7
         with:
           persist-credentials: false
-      - uses: pnpm/action-setup@v5
-        with:
-          run_install: false
-      - uses: actions/setup-node@v6
-        with:
-          node-version-file: ".node-version"
-          cache: "pnpm"
       - name: Grab Building Folder
         id: ramdisk
         run: |
           echo "build_dir=previous-build-${{ github.run_id }}-${{ github.run_number }}" >> $GITHUB_OUTPUT
-      - name: Download Previous Build
-        uses: actions/checkout@v6
-        with:
-          repository: SukkaLab/ruleset.skk.moe
-          # during a race condition the dist repo may be private, use token to clone
-          token: ${{ secrets.GIT_TOKEN }}
-          persist-credentials: false
-          filter: "tree:0" # we don't care about git history here
-          fetch-tags: false
-          path: ${{ steps.ramdisk.outputs.build_dir }}
-      - name: Setup build folder
-        run: |
-          if [ ! -d ${{ steps.ramdisk.outputs.build_dir }}/.git ]; then
-            echo ".git not found"
-            exit 1
-          fi
-          rm -rf "${{ steps.ramdisk.outputs.build_dir }}/.git"
-
-          if [ ! -d ${{ steps.ramdisk.outputs.build_dir }}/List ]; then
-            echo "List not found"
-            exit 1
-          fi
-          echo "public directory is ready: ${{ steps.ramdisk.outputs.build_dir }}"
       - name: Get current date
         id: date
         run: |
@@ -68,9 +38,24 @@ jobs:
           echo "hour=$(date +'%H')" >> $GITHUB_OUTPUT
           echo "minute=$(date +'%M')" >> $GITHUB_OUTPUT
           echo "second=$(date +'%S')" >> $GITHUB_OUTPUT
+      # Download previous build and restore cache.db in the background,
+      # while the Node.js toolchain is set up in the foreground
+      - name: Download Previous Build
+        id: download_previous_build
+        uses: actions/checkout@v6
+        background: true
+        with:
+          repository: SukkaLab/ruleset.skk.moe
+          # during a race condition the dist repo may be private, use token to clone
+          token: ${{ secrets.GIT_TOKEN }}
+          persist-credentials: false
+          filter: "tree:0" # we don't care about git history here
+          fetch-tags: false
+          path: ${{ steps.ramdisk.outputs.build_dir }}
       - name: Restore cache.db
         uses: actions/cache/restore@v6
         id: cache-db-restore
+        background: true
         with:
           path: |
             .cache
@@ -83,8 +68,32 @@ jobs:
             ${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-
             ${{ runner.os }}-v3-${{ steps.date.outputs.year }}-
             ${{ runner.os }}-v3-
+      # Setup Node.js and pnpm in foreground
+      - uses: pnpm/action-setup@v6
+        with:
+          run_install: false
+      - uses: actions/setup-node@v6
+        with:
+          node-version-file: ".node-version"
+          cache: "pnpm"
       - run: pnpm config set --location=global minimumReleaseAge 0
       - run: pnpm install
+      # Foreground pnpm + Node.js setup complete, ensure previous build and cache.db are ready
+      - wait: [download_previous_build, cache-db-restore]
+      # Double check build folder before starting build
+      - name: Setup build folder
+        run: |
+          if [ ! -d ${{ steps.ramdisk.outputs.build_dir }}/.git ]; then
+            echo ".git not found"
+            exit 1
+          fi
+          rm -rf "${{ steps.ramdisk.outputs.build_dir }}/.git"
+
+          if [ ! -d ${{ steps.ramdisk.outputs.build_dir }}/List ]; then
+            echo "List not found"
+            exit 1
+          fi
+          echo "public directory is ready: ${{ steps.ramdisk.outputs.build_dir }}"
       - run: pnpm run build
         env:
           PUBLIC_DIR: ${{ steps.ramdisk.outputs.build_dir }}
@@ -105,7 +114,10 @@ jobs:
             exit 1
           fi
           echo "public directory is ready: ${{ steps.ramdisk.outputs.build_dir }}"
+      # Upload artifact and save cache.db in parallel
       - uses: actions/upload-artifact@v7
+        id: upload_build_artifact
+        background: true
         with:
           name: build-artifact-${{ github.sha }}-${{ github.run_number }}
           path: ${{ steps.ramdisk.outputs.build_dir }}
@@ -120,6 +132,7 @@ jobs:
           path: |
             .cache
           key: ${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-${{ steps.date.outputs.day }} ${{ steps.date.outputs.hour }}:${{ steps.date.outputs.minute }}:${{ steps.date.outputs.second }}
+      - wait: upload_build_artifact
 
   diff_deployment_on_pr:
     if: github.ref != 'refs/heads/master'