|
12 | 12 | - cron: '0 0 * * *' # Runs every day at midnight UTC |
13 | 13 |
|
14 | 14 | 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 |
15 | 56 | build: |
16 | 57 | name: Nightly Build on ${{ matrix.os }} |
| 58 | + needs: check |
| 59 | + if: needs.check.outputs.proceed == 'true' |
17 | 60 | runs-on: ${{ matrix.os }} |
18 | 61 | strategy: |
19 | 62 | matrix: |
|
74 | 117 | overwrite: "true" |
75 | 118 | release: |
76 | 119 | name: Create Nightly Release |
77 | | - needs: build |
| 120 | + needs: [check, build] |
78 | 121 | runs-on: ubuntu-latest |
79 | 122 | if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' |
80 | 123 | permissions: |
|
0 commit comments