|
| 1 | +name: Nightly Release |
| 2 | + |
| 3 | +# Create a PR from dev → master every night if there are new commits. |
| 4 | +# The existing auto-release workflow tags and releases after merge. |
| 5 | + |
| 6 | +on: |
| 7 | + schedule: |
| 8 | + # Every day at midnight UTC |
| 9 | + - cron: '0 0 * * *' |
| 10 | + workflow_dispatch: # Manual trigger for testing |
| 11 | + |
| 12 | +jobs: |
| 13 | + nightly-pr: |
| 14 | + name: Nightly PR |
| 15 | + runs-on: ubuntu-latest |
| 16 | + timeout-minutes: 5 |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + token: ${{ secrets.ORILANG_RELEASE_TOKEN }} |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Check for new commits |
| 26 | + id: check |
| 27 | + run: | |
| 28 | + git fetch origin master dev |
| 29 | + AHEAD=$(git rev-list --count origin/master..origin/dev) |
| 30 | + echo "ahead=$AHEAD" >> $GITHUB_OUTPUT |
| 31 | + if [ "$AHEAD" -eq 0 ]; then |
| 32 | + echo "No new commits on dev since last merge. Skipping." |
| 33 | + else |
| 34 | + echo "$AHEAD new commit(s) on dev ahead of master." |
| 35 | + fi |
| 36 | +
|
| 37 | + - name: Check for existing PR |
| 38 | + if: steps.check.outputs.ahead != '0' |
| 39 | + id: existing |
| 40 | + env: |
| 41 | + GH_TOKEN: ${{ secrets.ORILANG_RELEASE_TOKEN }} |
| 42 | + run: | |
| 43 | + PR=$(gh pr list --base master --head dev --state open --json number --jq '.[0].number // empty') |
| 44 | + if [ -n "$PR" ]; then |
| 45 | + echo "PR #$PR already open. Skipping." |
| 46 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 47 | + else |
| 48 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 49 | + fi |
| 50 | +
|
| 51 | + - name: Create nightly PR |
| 52 | + if: steps.check.outputs.ahead != '0' && steps.existing.outputs.exists == 'false' |
| 53 | + env: |
| 54 | + GH_TOKEN: ${{ secrets.ORILANG_RELEASE_TOKEN }} |
| 55 | + run: | |
| 56 | + DATE=$(date -u +"%Y-%m-%d") |
| 57 | + AHEAD=${{ steps.check.outputs.ahead }} |
| 58 | +
|
| 59 | + gh pr create \ |
| 60 | + --base master \ |
| 61 | + --head dev \ |
| 62 | + --title "nightly: $DATE" \ |
| 63 | + --body "$(cat <<EOF |
| 64 | + ## Nightly Release — $DATE |
| 65 | +
|
| 66 | + Automated PR with $AHEAD new commit(s) from dev. |
| 67 | +
|
| 68 | + This PR will auto-merge once CI passes, triggering a nightly release. |
| 69 | + EOF |
| 70 | + )" |
| 71 | +
|
| 72 | + - name: Enable auto-merge |
| 73 | + if: steps.check.outputs.ahead != '0' && steps.existing.outputs.exists == 'false' |
| 74 | + env: |
| 75 | + GH_TOKEN: ${{ secrets.ORILANG_RELEASE_TOKEN }} |
| 76 | + run: | |
| 77 | + gh pr merge --auto --merge --delete-branch=false |
0 commit comments