Skip to content

Commit 065acde

Browse files
authored
ci: Add ready label to automate tests (#305)
* ci: Added auto merge and tests run action * ci: Removed old lgtm labeler * ci: Run integration test action on push to main * ci: Update action name * ci: Remove lgtm label on new commits * ci: for build * ci: Update labeler action * test: Added libary fixture Signed-off-by: Josephasafg <ajgard7@gmail.com> * fix: Added conditional import --------- Signed-off-by: Josephasafg <ajgard7@gmail.com>
1 parent 8db4fbf commit 065acde

File tree

5 files changed

+140
-61
lines changed

5 files changed

+140
-61
lines changed

.github/workflows/integration-tests.yaml

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ on:
44
push:
55
branches:
66
- main
7-
workflow_dispatch:
8-
inputs:
9-
commit-to-test:
10-
description: "Commit SHA to test"
11-
required: true
12-
type: string
137

148
env:
159
POETRY_VERSION: "1.8"
@@ -26,21 +20,6 @@ jobs:
2620
steps:
2721
- name: Checkout
2822
uses: actions/checkout@v3
29-
with:
30-
ref: ${{ inputs.commit-to-test }}
31-
- name: Set status to pending
32-
if: ${{ github.event_name == 'workflow_dispatch' }}
33-
uses: actions/github-script@v7
34-
with:
35-
script: |
36-
github.rest.repos.createCommitStatus({
37-
owner: context.repo.owner,
38-
repo: context.repo.repo,
39-
sha: '${{ inputs.commit-to-test }}',
40-
state: 'pending',
41-
context: 'Integration Tests',
42-
description: 'Integration tests are in progress'
43-
})
4423
- name: Install Poetry
4524
run: |
4625
pipx install poetry==1.8
@@ -81,29 +60,3 @@ jobs:
8160
path: junit/test-results-${{ matrix.python-version }}.xml
8261
# Use always() to always run this step to publish test results when there are test failures
8362
if: ${{ always() }}
84-
- name: Set status to success
85-
if: ${{ github.event_name == 'workflow_dispatch' && success() }}
86-
uses: actions/github-script@v7
87-
with:
88-
script: |
89-
github.rest.repos.createCommitStatus({
90-
owner: context.repo.owner,
91-
repo: context.repo.repo,
92-
sha: '${{ inputs.commit-to-test }}',
93-
state: 'success',
94-
context: 'Integration Tests',
95-
description: 'Integration tests passed'
96-
})
97-
- name: Set status to failure
98-
if: ${{ github.event_name == 'workflow_dispatch' && failure() }}
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: '${{ inputs.commit-to-test }}',
106-
state: 'failure',
107-
context: 'Integration Tests',
108-
description: 'Integration tests failed'
109-
})

.github/workflows/labeler.yml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
contents: read
1414
pull-requests: write
1515
runs-on: ubuntu-latest
16+
if: github.event.action == 'synchronize'
1617
steps:
1718
- name: Checkout repository
1819
uses: actions/checkout@v4
@@ -112,16 +113,20 @@ jobs:
112113
github_token: ${{ secrets.GITHUB_TOKEN }}
113114
labels: ${{ env.label }}
114115

115-
add_lgtm_label:
116-
runs-on: ubuntu-latest
117-
if: github.event.review.state == 'APPROVED'
118-
119-
steps:
120-
- name: Checkout repository
121-
uses: actions/checkout@v3
122-
123-
- name: Add LGTM label
124-
uses: actions-ecosystem/action-add-labels@v1
116+
- name: Remove lgtm label on new commits
117+
uses: actions/github-script@v7
125118
with:
126-
github_token: ${{ secrets.GITHUB_TOKEN }}
127-
labels: lgtm
119+
github-token: ${{ secrets.GITHUB_TOKEN }}
120+
script: |
121+
try {
122+
await github.rest.issues.removeLabel({
123+
owner: context.repo.owner,
124+
repo: context.repo.repo,
125+
issue_number: context.issue.number,
126+
name: 'lgtm'
127+
});
128+
} catch (error) {
129+
if (error.status !== 404) {
130+
throw error;
131+
}
132+
}

.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',
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',
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',
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+
})

ai21/models/ai21_base_model.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import warnings
22
from typing import Any, Dict
33

4-
from pydantic import BaseModel, ConfigDict
4+
from pydantic import BaseModel
55
from typing_extensions import Self
66

77
from ai21.models._pydantic_compatibility import _to_dict, _to_json, _from_dict, _from_json, IS_PYDANTIC_V2
88

9+
if IS_PYDANTIC_V2:
10+
from pydantic import ConfigDict
11+
912

1013
class AI21BaseModel(BaseModel):
1114
if IS_PYDANTIC_V2:

tests/integration_tests/clients/studio/test_maestro.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
@pytest.mark.asyncio
8-
async def test_maestro__when_upload__should_return_data_sources(): # file_in_library: str):
8+
async def test_maestro__when_upload__should_return_data_sources(file_in_library: str):
99
client = AsyncAI21Client()
1010
run = await client.beta.maestro.runs.create_and_poll(
1111
input="When did Einstein receive a Nobel Prize?",

0 commit comments

Comments
 (0)