Skip to content

Commit eb60b73

Browse files
committed
ci: check proceed condition for nightly
1 parent 937cabb commit eb60b73

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

.github/workflows/nightly.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,51 @@ on:
1212
- cron: '0 0 * * *' # Runs every day at midnight UTC
1313

1414
jobs:
15+
check:
16+
name: Determine Build Necessity
17+
runs-on: ubuntu-latest
18+
outputs:
19+
proceed: ${{ steps.check.outputs.proceed }}
20+
steps:
21+
- uses: actions/checkout@v5
22+
with:
23+
fetch-depth: 0
24+
- name: Get the last nightly commit
25+
id: last_nightly
26+
uses: actions/github-script@v7
27+
with:
28+
script: |
29+
const release = await github.rest.repos.getReleaseByTag({
30+
owner: context.repo.owner,
31+
repo: context.repo.repo,
32+
tag: 'nightly'
33+
}).catch(() => null);
34+
if (release && release.data && release.data.target_commitish) {
35+
return release.data.target_commitish;
36+
} else {
37+
return null;
38+
}
39+
- name: Check the proceed condition
40+
id: check
41+
run: |
42+
LAST_NIGHTLY_COMMIT="${{ steps.last_nightly.outputs.result }}"
43+
CURRENT_COMMIT="${GITHUB_SHA}"
44+
echo "Last nightly commit: $LAST_NIGHTLY_COMMIT"
45+
echo "Current commit: $CURRENT_COMMIT"
46+
if [ -z "$LAST_NIGHTLY_COMMIT" ]; then
47+
echo "No previous nightly release found. Proceeding with build."
48+
echo "proceed=true" >> $GITHUB_OUTPUT
49+
elif [ "$LAST_NIGHTLY_COMMIT" != "$CURRENT_COMMIT" ]; then
50+
echo "New commits found since last nightly release. Proceeding with build."
51+
echo "proceed=true" >> $GITHUB_OUTPUT
52+
else
53+
echo "No new commits since last nightly release. Skipping build."
54+
echo "proceed=false" >> $GITHUB_OUTPUT
55+
fi
1556
build:
1657
name: Nightly Build on ${{ matrix.os }}
58+
needs: check
59+
if: needs.check.outputs.proceed == 'true'
1760
runs-on: ${{ matrix.os }}
1861
strategy:
1962
matrix:
@@ -74,7 +117,7 @@ jobs:
74117
overwrite: "true"
75118
release:
76119
name: Create Nightly Release
77-
needs: build
120+
needs: [check, build]
78121
runs-on: ubuntu-latest
79122
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
80123
permissions:

0 commit comments

Comments
 (0)