This is an automated email from the ASF dual-hosted git repository.

snuyanzin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/master by this push:
     new 392e0325e88 [hotfix][ci] Do not run GHA nightly if there is no newer 
commits since the last run
392e0325e88 is described below

commit 392e0325e880e50f8f564377f212c1cbfbbe1c76
Author: Sergey Nuyanzin <[email protected]>
AuthorDate: Mon Jun 8 11:02:06 2026 +0200

    [hotfix][ci] Do not run GHA nightly if there is no newer commits since the 
last run
---
 .github/workflows/nightly-trigger.yml | 41 ++++++++++++++++++++++++++++++++---
 1 file changed, 38 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/nightly-trigger.yml 
b/.github/workflows/nightly-trigger.yml
index ecb1618a12b..34686258b4d 100644
--- a/.github/workflows/nightly-trigger.yml
+++ b/.github/workflows/nightly-trigger.yml
@@ -21,6 +21,7 @@ name: "Nightly trigger (beta)"
 on:
   schedule:
     - cron: '0 2 * * *'
+  workflow_dispatch:
 
 jobs:
   Trigger:
@@ -39,9 +40,43 @@ jobs:
         uses: actions/github-script@v7
         with:
           script: |
-            github.rest.actions.createWorkflowDispatch({
+            const branch = '${{ matrix.branch }}';
+
+            // Resolve the current HEAD of the branch.
+            const { data: branchData } = await github.rest.repos.getBranch({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              branch: branch
+            });
+            const currentSha = branchData.commit.sha;
+
+            // Compare SHA from last nightly against current
+            // if it is same, then no need to run nightly for the same SHA 
again.
+            const { data: runsData } = await 
github.rest.actions.listWorkflowRuns({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              workflow_id: 'nightly.yml',
+              branch: branch,
+              per_page: 1
+            });
+            
+            const lastRun = runsData.workflow_runs[0];
+            const lastBuiltSha = lastRun?.head_sha;
+            const lastConclusion = lastRun?.conclusion;
+
+            // Skip the scheduled run only if there are no new commits AND the
+            // previous nightly was green. If the last run failed/was 
cancelled,
+            // re-run even without new commits so failures get retried.
+            // It is still possible to run manually even if the last one was 
green and no new commits.
+            if (context.eventName === 'schedule' && lastBuiltSha === 
currentSha && lastConclusion === 'success') {
+              core.info(`No new commits on ${branch} since ${currentSha} and 
last nightly was green, skipping scheduled nightly.`);
+              return;
+            }
+
+            core.info(`Triggering nightly on ${branch} at ${currentSha} (last 
built: ${lastBuiltSha ?? 'none'}, last conclusion: ${lastConclusion ?? 
'none'}).`);
+            await github.rest.actions.createWorkflowDispatch({
               owner: context.repo.owner,
               repo: context.repo.repo,
               workflow_id: 'nightly.yml',
-              ref: '${{ matrix.branch }}'
-            })
+              ref: branch
+            });

Reply via email to