|
| 1 | +name: Check CI stability for PRs with "ci/verify-stability" or "ci/verify-stability-merge-master" label |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Monday to Friday: Every 2 hours from 7 PM to 7 AM CEST |
| 6 | + - cron: "0 17 * * 1-5" |
| 7 | + - cron: "0 19 * * 1-5" |
| 8 | + - cron: "0 21 * * 1-5" |
| 9 | + - cron: "0 23 * * 1-5" |
| 10 | + - cron: "0 1 * * 2-6" |
| 11 | + - cron: "0 3 * * 2-6" |
| 12 | + - cron: "0 5 * * 2-6" |
| 13 | + # Saturday and Sunday: Every 2 hours all day |
| 14 | + - cron: "0 */2 * * 6,0" |
| 15 | + workflow_dispatch: # Allows manual trigger from GitHub Actions UI |
| 16 | +env: |
| 17 | + GH_USER: "github-actions[bot]" |
| 18 | + GH_EMAIL: "<41898282+github-actions[bot]@users.noreply.github.com>" |
| 19 | +jobs: |
| 20 | + trigger-ci: |
| 21 | + runs-on: ubuntu-24.04 |
| 22 | + steps: |
| 23 | + - name: Generate GitHub app token |
| 24 | + id: github-app-token |
| 25 | + uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0 |
| 26 | + with: |
| 27 | + app-id: ${{ secrets.APP_ID }} |
| 28 | + private-key: ${{ secrets.APP_PRIVATE_KEY }} |
| 29 | + - name: Checkout repository |
| 30 | + uses: actions/checkout@v3 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + token: ${{ steps.github-app-token.outputs.token }} |
| 34 | + - name: Get open pull requests and save to file |
| 35 | + run: | |
| 36 | + gh pr list --json number,labels > open_prs.json |
| 37 | + env: |
| 38 | + GITHUB_TOKEN: ${{ steps.github-app-token.outputs.token }} |
| 39 | + - name: Process PRs |
| 40 | + id: process_prs |
| 41 | + run: | |
| 42 | + cat open_prs.json |
| 43 | + pr_numbers_with_verify_stability=$(jq -r -c '.[] | select(.labels[]?.name == "ci/verify-stability") | .number' open_prs.json | tr '\n' ' ') |
| 44 | + pr_numbers_with_verify_stability_merge_master=$(jq -r '.[] | select(.labels[]?.name == "ci/verify-stability-merge-master") | .number' open_prs.json | tr '\n' ' ') |
| 45 | + echo "PRs with 'ci/verify-stability' label: $pr_numbers_with_verify_stability" |
| 46 | + echo "PRs with 'ci/verify-stability-merge-master' label: $pr_numbers_with_verify_stability_merge_master" |
| 47 | + echo "pr_numbers_with_verify_stability=$pr_numbers_with_verify_stability" >> $GITHUB_OUTPUT |
| 48 | + echo "pr_numbers_with_verify_stability_merge_master=$pr_numbers_with_verify_stability_merge_master" >> $GITHUB_OUTPUT |
| 49 | + env: |
| 50 | + GITHUB_TOKEN: ${{ steps.github-app-token.outputs.token }} |
| 51 | + - name: Merge master branch (if applicable) and push a single commit |
| 52 | + if: steps.process_prs.outputs.pr_numbers_with_verify_stability != '' |
| 53 | + run: | |
| 54 | + eval "pr_numbers=(${{ steps.process_prs.outputs.pr_numbers_with_verify_stability }})" |
| 55 | + for pr_number in $pr_numbers; do |
| 56 | + current_datetime=$(date +"%Y-%m-%d %H:%M:%S") |
| 57 | + echo "Processing PR #$pr_number" |
| 58 | +
|
| 59 | + # Fetch PR details to get the base branch (original branch name) |
| 60 | + pr_branch=$(gh pr view $pr_number --json headRefName --jq '.headRefName') |
| 61 | + echo "The original branch for PR #$pr_number is $pr_branch" |
| 62 | + git fetch origin pull/$pr_number/head:$pr_branch |
| 63 | + git checkout $pr_branch |
| 64 | +
|
| 65 | + git config user.name "${GH_USER}" |
| 66 | + git config user.email "${GH_EMAIL}" |
| 67 | + |
| 68 | + # Check if the PR needs to merge with master |
| 69 | + if echo "${{ steps.process_prs.outputs.pr_numbers_with_verify_stability_merge_master }}" | grep -wq "$pr_number"; then |
| 70 | + echo "Merging master into PR #$pr_number" |
| 71 | + git fetch origin master |
| 72 | + git merge origin/master --no-ff --no-commit |
| 73 | + git commit --allow-empty -m "Merge master into PR #$pr_number" |
| 74 | + fi |
| 75 | + |
| 76 | + # Commit an empty commit to trigger the CI |
| 77 | + echo "Pushing empty commit to trigger CI for PR #$pr_number on $current_datetime" |
| 78 | + git commit --allow-empty -m "Trigger CI for PR #$pr_number on $current_datetime" |
| 79 | + git push origin $pr_branch |
| 80 | + done |
| 81 | + env: |
| 82 | + GITHUB_TOKEN: ${{ steps.github-app-token.outputs.token }} |
0 commit comments