|
29 | 29 | # yamllint enable rule:line-length |
30 | 30 | runs-on: ubuntu-latest |
31 | 31 | steps: |
| 32 | + - name: Get PR details |
| 33 | + id: pr |
| 34 | + # yamllint disable-line rule:line-length |
| 35 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 36 | + with: |
| 37 | + github-token: ${{ secrets.CEPH_CSI_BOT_TOKEN }} |
| 38 | + script: | |
| 39 | + const pr = await github.rest.pulls.get({ |
| 40 | + owner: context.repo.owner, |
| 41 | + repo: context.repo.repo, |
| 42 | + pull_number: context.issue.number |
| 43 | + }) |
| 44 | + core.setOutput('head_sha', pr.data.head.sha) |
| 45 | + core.setOutput('base_ref', pr.data.base.ref) |
| 46 | + core.setOutput('head_ref', pr.data.head.ref) |
| 47 | +
|
| 48 | + - name: Checkout PR branch |
| 49 | + # yamllint disable-line rule:line-length |
| 50 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 51 | + with: |
| 52 | + ref: ${{ steps.pr.outputs.head_sha }} |
| 53 | + fetch-depth: 0 |
| 54 | + |
| 55 | + - name: Check if rebase is needed |
| 56 | + id: check_rebase |
| 57 | + run: | |
| 58 | + set -euo pipefail |
| 59 | + BASE_REF="${{ steps.pr.outputs.base_ref }}" |
| 60 | + git fetch origin -- "$BASE_REF" |
| 61 | +
|
| 62 | + # Get the merge base between PR and target branch |
| 63 | + MERGE_BASE=$(git merge-base HEAD "origin/$BASE_REF") |
| 64 | +
|
| 65 | + # Get the latest commit on the target branch |
| 66 | + BASE_SHA=$(git rev-parse "origin/$BASE_REF") |
| 67 | +
|
| 68 | + # If merge base equals latest commit on base, no rebase needed |
| 69 | + if [ "$MERGE_BASE" = "$BASE_SHA" ]; then |
| 70 | + echo "needs_rebase=false" >> "$GITHUB_OUTPUT" |
| 71 | + echo "PR is up to date with base branch, no rebase needed" |
| 72 | + else |
| 73 | + echo "needs_rebase=true" >> "$GITHUB_OUTPUT" |
| 74 | + echo "PR needs rebase" |
| 75 | + fi |
| 76 | +
|
32 | 77 | - name: Add queued/rebase label |
| 78 | + if: steps.check_rebase.outputs.needs_rebase == 'true' |
33 | 79 | # yamllint disable-line rule:line-length |
34 | 80 | uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
35 | 81 | with: |
|
43 | 89 | }) |
44 | 90 |
|
45 | 91 | - name: Request rebase through Mergify |
| 92 | + if: steps.check_rebase.outputs.needs_rebase == 'true' |
46 | 93 | # yamllint disable-line rule:line-length |
47 | 94 | uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 |
48 | 95 | with: |
|
51 | 98 | body: | |
52 | 99 | @mergifyio rebase |
53 | 100 |
|
| 101 | + - name: Add ok-to-test label directly |
| 102 | + if: steps.check_rebase.outputs.needs_rebase == 'false' |
| 103 | + # yamllint disable-line rule:line-length |
| 104 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 105 | + with: |
| 106 | + github-token: ${{ secrets.CEPH_CSI_BOT_TOKEN }} |
| 107 | + script: | |
| 108 | + await github.rest.issues.addLabels({ |
| 109 | + issue_number: context.issue.number, |
| 110 | + owner: context.repo.owner, |
| 111 | + repo: context.repo.repo, |
| 112 | + labels: ['ok-to-test'] |
| 113 | + }) |
| 114 | +
|
54 | 115 | add-ok-to-test-label: |
55 | 116 | if: > |
56 | 117 | github.repository == 'ceph/ceph-csi' && |
|
0 commit comments