Yicong-Huang commented on code in PR #4598:
URL: https://github.com/apache/texera/pull/4598#discussion_r3174499176


##########
.github/workflows/github-action-build.yml:
##########
@@ -19,22 +19,107 @@ name: Build
 
 env:
   NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
-  
+
 on:
   push:
     branches:
       - 'ci-enable/**'
       - 'main'
       - 'release/**'
   pull_request:
+    types:
+      - opened
+      - reopened
+      - synchronize
+      - labeled
+      - unlabeled
   workflow_dispatch:
 
+permissions:
+  checks: write
+  contents: read
+  pull-requests: read
+
 concurrency:
   group: ${{ github.workflow }}-${{ github.ref }}
   cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
 
 jobs:
+  precheck:
+    name: Precheck
+    runs-on: ubuntu-latest
+    outputs:
+      run_frontend: ${{ steps.decide.outputs.run_frontend }}
+      run_scala: ${{ steps.decide.outputs.run_scala }}
+      run_python: ${{ steps.decide.outputs.run_python }}
+      run_agent_service: ${{ steps.decide.outputs.run_agent_service }}
+      backport_targets: ${{ steps.decide.outputs.backport_targets }}
+    steps:
+      - name: Decide which jobs to run
+        id: decide
+        uses: actions/github-script@v8
+        with:
+          script: |
+            const eventName = context.eventName;
+
+            // Main build stacks: always run.
+            const stacks = ["run_frontend", "run_scala", "run_python", 
"run_agent_service"];
+            for (const key of stacks) {
+              core.setOutput(key, "true");
+            }
+
+            // Backport targets: all current release/* labels on the PR.
+            let targets = [];
+            if (eventName === "pull_request") {
+              const labels = context.payload.pull_request.labels.map((l) => 
l.name);
+              targets = [...new Set(labels.filter((n) => 
/^release\/.+$/.test(n)))].sort();
+            }
+
+            if (targets.length === 0) {
+              core.info(`No backport targets on PR.`);
+            } else {
+              core.info(`Backport targets: ${targets.join(", ")}`);
+            }
+            core.setOutput("backport_targets", JSON.stringify(targets));
+
+  cleanup-stale-backport:
+    if: ${{ github.event_name == 'pull_request' && github.event.action == 
'unlabeled' && startsWith(github.event.label.name, 'release/') }}
+    runs-on: ubuntu-latest
+    steps:
+      - name: Cancel obsolete backport check_runs for the removed target
+        uses: actions/github-script@v8
+        with:
+          script: |
+            const { owner, repo } = context.repo;
+            const target = context.payload.label.name;
+            const headSha = context.payload.pull_request.head.sha;
+            const prefix = `backport (${target}) `;
+
+            const checks = await github.paginate(
+              github.rest.checks.listForRef,
+              { owner, repo, ref: headSha, per_page: 100 }
+            );
+
+            for (const check of checks) {
+              if (!check.name.startsWith(prefix)) continue;
+              if (check.status === "completed" && check.conclusion === 
"cancelled") continue;
+              try {
+                await github.rest.checks.update({
+                  owner,
+                  repo,
+                  check_run_id: check.id,
+                  status: "completed",
+                  conclusion: "cancelled",
+                });
+                core.info(`Cancelled check ${check.name}`);
+              } catch (e) {
+                core.warning(`Failed to update check ${check.id} 
(${check.name}): ${e.message}`);
+              }
+            }
+
   frontend:
+    needs: precheck
+    if: ${{ needs.precheck.outputs.run_frontend == 'true' }}
     name: frontend (${{ matrix.os }}, 18)

Review Comment:
   I do plan to do it, but right now asf.yaml requires exact name matching of 
jobs. if I reuse it it will add a wrapper name. Let's do it later.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to