|
| 1 | +name: PR Approval Handler |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_review: |
| 5 | + types: [submitted] |
| 6 | + |
| 7 | +env: |
| 8 | + POETRY_VERSION: "1.8" |
| 9 | + POETRY_URL: https://install.python-poetry.org |
| 10 | + |
| 11 | +jobs: |
| 12 | + handle-approval: |
| 13 | + if: github.event.review.state == 'APPROVED' |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + pull-requests: write |
| 18 | + statuses: write |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + ref: ${{ github.event.pull_request.head.sha }} |
| 25 | + |
| 26 | + - name: Add lgtm label |
| 27 | + uses: actions-ecosystem/action-add-labels@v1 |
| 28 | + with: |
| 29 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + labels: lgtm |
| 31 | + |
| 32 | + - name: Enable auto-merge |
| 33 | + uses: actions/github-script@v7 |
| 34 | + with: |
| 35 | + script: | |
| 36 | + await github.graphql(` |
| 37 | + mutation enableAutoMerge($pullRequestId: ID!, $mergeMethod: PullRequestMergeMethod!) { |
| 38 | + enablePullRequestAutoMerge(input: { |
| 39 | + pullRequestId: $pullRequestId, |
| 40 | + mergeMethod: $mergeMethod |
| 41 | + }) { |
| 42 | + pullRequest { |
| 43 | + autoMergeRequest { |
| 44 | + enabledAt |
| 45 | + mergeMethod |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | + `, { |
| 51 | + pullRequestId: context.payload.pull_request.node_id, |
| 52 | + mergeMethod: 'SQUASH' |
| 53 | + }); |
| 54 | + console.log('Auto-merge enabled with squash method'); |
| 55 | +
|
| 56 | + - name: Install Poetry |
| 57 | + run: | |
| 58 | + pipx install poetry==1.8 |
| 59 | +
|
| 60 | + - name: Set up Python |
| 61 | + uses: actions/setup-python@v5 |
| 62 | + with: |
| 63 | + python-version: "3.11" |
| 64 | + cache: poetry |
| 65 | + cache-dependency-path: poetry.lock |
| 66 | + |
| 67 | + - name: Set Poetry environment |
| 68 | + run: | |
| 69 | + poetry env use 3.11 |
| 70 | + poetry cache clear --all pypi |
| 71 | +
|
| 72 | + - name: Install dependencies |
| 73 | + run: | |
| 74 | + poetry install --all-extras |
| 75 | +
|
| 76 | + - name: Set status to pending |
| 77 | + uses: actions/github-script@v7 |
| 78 | + with: |
| 79 | + script: | |
| 80 | + github.rest.repos.createCommitStatus({ |
| 81 | + owner: context.repo.owner, |
| 82 | + repo: context.repo.repo, |
| 83 | + sha: '${{ github.event.pull_request.head.sha }}', |
| 84 | + state: 'pending', |
| 85 | + context: 'Integration Tests', |
| 86 | + description: 'Integration tests are running after approval' |
| 87 | + }) |
| 88 | +
|
| 89 | + - name: Run Integration Tests |
| 90 | + env: |
| 91 | + AI21_API_KEY: ${{ secrets.AI21_API_KEY }} |
| 92 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 93 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 94 | + run: | |
| 95 | + poetry run pytest tests/integration_tests/ |
| 96 | +
|
| 97 | + - name: Set status to success |
| 98 | + if: success() |
| 99 | + uses: actions/github-script@v7 |
| 100 | + with: |
| 101 | + script: | |
| 102 | + github.rest.repos.createCommitStatus({ |
| 103 | + owner: context.repo.owner, |
| 104 | + repo: context.repo.repo, |
| 105 | + sha: '${{ github.event.pull_request.head.sha }}', |
| 106 | + state: 'success', |
| 107 | + context: 'Integration Tests', |
| 108 | + description: 'Integration tests passed after approval' |
| 109 | + }) |
| 110 | +
|
| 111 | + - name: Set status to failure |
| 112 | + if: failure() |
| 113 | + uses: actions/github-script@v7 |
| 114 | + with: |
| 115 | + script: | |
| 116 | + github.rest.repos.createCommitStatus({ |
| 117 | + owner: context.repo.owner, |
| 118 | + repo: context.repo.repo, |
| 119 | + sha: '${{ github.event.pull_request.head.sha }}', |
| 120 | + state: 'failure', |
| 121 | + context: 'Integration Tests', |
| 122 | + description: 'Integration tests failed after approval' |
| 123 | + }) |
| 124 | +
|
| 125 | + - name: Upload pytest integration tests results |
| 126 | + uses: actions/upload-artifact@v4 |
| 127 | + with: |
| 128 | + name: pytest-results-pr-approval |
| 129 | + path: junit/test-results-*.xml |
| 130 | + if: always() |
0 commit comments