PR Approval Handler #56
Workflow file for this run
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: PR Approval Handler | |
| on: | |
| pull_request_review: | |
| types: [submitted] | |
| env: | |
| POETRY_VERSION: "1.8" | |
| POETRY_URL: https://install.python-poetry.org | |
| jobs: | |
| handle-approval: | |
| if: github.event.review.state == 'APPROVED' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| statuses: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Add lgtm label | |
| uses: actions-ecosystem/action-add-labels@v1 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| labels: lgtm | |
| - name: Enable auto-merge | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| await github.graphql(` | |
| mutation enableAutoMerge($pullRequestId: ID!, $mergeMethod: PullRequestMergeMethod!) { | |
| enablePullRequestAutoMerge(input: { | |
| pullRequestId: $pullRequestId, | |
| mergeMethod: $mergeMethod | |
| }) { | |
| pullRequest { | |
| autoMergeRequest { | |
| enabledAt | |
| mergeMethod | |
| } | |
| } | |
| } | |
| } | |
| `, { | |
| pullRequestId: context.payload.pull_request.node_id, | |
| mergeMethod: 'SQUASH' | |
| }); | |
| console.log('Auto-merge enabled with squash method'); | |
| - name: Install Poetry | |
| run: | | |
| pipx install poetry==1.8 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| cache: poetry | |
| cache-dependency-path: poetry.lock | |
| - name: Set Poetry environment | |
| run: | | |
| poetry env use 3.11 | |
| poetry cache clear --all pypi | |
| - name: Install dependencies | |
| run: | | |
| poetry install --all-extras | |
| - name: Set status to pending | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| github.rest.repos.createCommitStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| sha: '${{ github.event.pull_request.head.sha }}', | |
| state: 'pending', | |
| context: 'Integration Tests', | |
| description: 'Integration tests are running after approval' | |
| }) | |
| - name: Run Integration Tests | |
| env: | |
| AI21_API_KEY: ${{ secrets.AI21_API_KEY }} | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| run: | | |
| poetry run pytest tests/integration_tests/ | |
| - name: Set status to success | |
| if: success() | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| github.rest.repos.createCommitStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| sha: '${{ github.event.pull_request.head.sha }}', | |
| state: 'success', | |
| context: 'Integration Tests', | |
| description: 'Integration tests passed after approval' | |
| }) | |
| - name: Set status to failure | |
| if: failure() | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| github.rest.repos.createCommitStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| sha: '${{ github.event.pull_request.head.sha }}', | |
| state: 'failure', | |
| context: 'Integration Tests', | |
| description: 'Integration tests failed after approval' | |
| }) | |
| - name: Upload pytest integration tests results | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pytest-results-pr-approval | |
| path: junit/test-results-*.xml | |
| if: always() |