Scheduled PR: dev to prod #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Scheduled PR: dev to prod" | |
| on: | |
| schedule: | |
| # Runs at 9am EST (unless there is daylight savings) | |
| - cron: '0 14 * * 1' | |
| workflow_dispatch: | |
| env: | |
| # The date of the first run of the action. It has to be set to a date that is on the same weekday as the cron. | |
| FIRST_RUN_DATE: 2026-02-02 | |
| jobs: | |
| weekindex: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| weekindex: ${{ steps.calculate.outputs.weekindex }} | |
| steps: | |
| - name: Calculate weekdiff | |
| id: calculate | |
| run: | | |
| current_date=$(date +%Y-%m-%d) | |
| start=$(date -d ${{ env.FIRST_RUN_DATE }} +%s) | |
| end=$(date -d $current_date +%s) | |
| weekdiff=$(((end-start) / 60 / 60 / 24 / 7)) | |
| weekindex=$((weekdiff % 2)) | |
| echo "weekindex=$weekindex" >> "$GITHUB_OUTPUT" | |
| echo "FIRST_RUN_DATE: ${{ env.FIRST_RUN_DATE }}" >> $GITHUB_STEP_SUMMARY | |
| echo "current_date: $current_date" >> $GITHUB_STEP_SUMMARY | |
| echo "weekdiff: $weekdiff" >> $GITHUB_STEP_SUMMARY | |
| echo "weekindex: $weekindex" >> $GITHUB_STEP_SUMMARY | |
| if [ $weekindex -eq 0 ]; then | |
| echo "🟢 It's the first week of the bi-weekly cycle. The action is going to run." >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "🔴 It's the second week of the bi-weekly cycle. The action is going to be skipped." >> $GITHUB_STEP_SUMMARY | |
| fi | |
| action: | |
| if: ${{ needs.weekindex.outputs.weekindex == 0 }} | |
| runs-on: ubuntu-latest | |
| needs: | |
| - weekindex | |
| permissions: | |
| pull-requests: write | |
| contents: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Create Pull Request | |
| run: | | |
| gh pr create \ | |
| --base prod \ | |
| --head dev \ | |
| --title "Scheduled Merge: dev to prod" \ | |
| --body "Automated PR created by GitHub Actions on a semi-weekly schedule." \ | |
| || echo "PR already exists or no changes to merge" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |