Skip to content

Commit 15557ed

Browse files
committed
ci: Added auto merge and tests run action
1 parent 8db4fbf commit 15557ed

1 file changed

Lines changed: 118 additions & 0 deletions

File tree

.github/workflows/pr-approval.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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: read
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: Install Poetry
33+
run: |
34+
pipx install poetry==1.8
35+
36+
- name: Set up Python
37+
uses: actions/setup-python@v5
38+
with:
39+
python-version: "3.11"
40+
cache: poetry
41+
cache-dependency-path: poetry.lock
42+
43+
- name: Set Poetry environment
44+
run: |
45+
poetry env use 3.11
46+
poetry cache clear --all pypi
47+
48+
- name: Install dependencies
49+
run: |
50+
poetry install --all-extras
51+
52+
- name: Set status to pending
53+
uses: actions/github-script@v7
54+
with:
55+
script: |
56+
github.rest.repos.createCommitStatus({
57+
owner: context.repo.owner,
58+
repo: context.repo.repo,
59+
sha: '${{ github.event.pull_request.head.sha }}',
60+
state: 'pending',
61+
context: 'Integration Tests (PR Approved)',
62+
description: 'Integration tests are running after approval'
63+
})
64+
65+
- name: Run Integration Tests
66+
env:
67+
AI21_API_KEY: ${{ secrets.AI21_API_KEY }}
68+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
69+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
70+
run: |
71+
poetry run pytest tests/integration_tests/
72+
73+
- name: Set status to success
74+
if: success()
75+
uses: actions/github-script@v7
76+
with:
77+
script: |
78+
github.rest.repos.createCommitStatus({
79+
owner: context.repo.owner,
80+
repo: context.repo.repo,
81+
sha: '${{ github.event.pull_request.head.sha }}',
82+
state: 'success',
83+
context: 'Integration Tests (PR Approved)',
84+
description: 'Integration tests passed after approval'
85+
})
86+
87+
- name: Set status to failure
88+
if: failure()
89+
uses: actions/github-script@v7
90+
with:
91+
script: |
92+
github.rest.repos.createCommitStatus({
93+
owner: context.repo.owner,
94+
repo: context.repo.repo,
95+
sha: '${{ github.event.pull_request.head.sha }}',
96+
state: 'failure',
97+
context: 'Integration Tests (PR Approved)',
98+
description: 'Integration tests failed after approval'
99+
})
100+
101+
- name: Upload pytest integration tests results
102+
uses: actions/upload-artifact@v4
103+
with:
104+
name: pytest-results-pr-approval
105+
path: junit/test-results-*.xml
106+
if: always()
107+
108+
- name: Auto-merge PR
109+
if: success()
110+
uses: actions/github-script@v7
111+
with:
112+
script: |
113+
await github.rest.pulls.merge({
114+
owner: context.repo.owner,
115+
repo: context.repo.repo,
116+
pull_number: context.issue.number,
117+
merge_method: 'squash'
118+
})

0 commit comments

Comments
 (0)