forked from AI21Labs/ai21-python
-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (115 loc) · 3.82 KB
/
pr-approval.yml
File metadata and controls
130 lines (115 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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()