Skip to content

Commit d164fc3

Browse files
committed
add python
1 parent c1f691f commit d164fc3

File tree

9 files changed

+85
-46
lines changed

9 files changed

+85
-46
lines changed

.github/workflows/autogen-remote-changes.yml

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,92 @@ name: Auto-Update SDK
44
# schedule:
55
# - cron: "0 0 * * 1" # Runs every Monday at midnight
66
# workflow_dispatch: # Allows manual triggering of the workflow
7-
8-
on: [push, pull_request]
7+
on: [push]
98

109
jobs:
1110
update-sdk:
1211
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.12"]
1315
steps:
14-
- name: Checkout repository
16+
- uses: actions/checkout@v3
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Set up Node.js
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: '18'
25+
- name: Install OpenAPI Generator CLI
26+
run: npm install @openapitools/openapi-generator-cli -g
27+
- name: Install dependencies
1528
run: |
16-
git clone https://github.com/${{ github.repository }} repo
17-
cd repo
18-
git config --global user.name "github-actions[bot]"
19-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
29+
python -m pip install --upgrade pip
30+
pip install -r requirements.txt
2031
- name: Pull and generate SDK
21-
run: |
22-
cd repo
23-
make gen-openapi-remote
32+
run: make gen-openapi-remote-for-ci
2433
- name: Check for changes
34+
id: check_changes
2535
run: |
26-
cd repo
2736
if git diff --quiet; then
2837
echo "changes=false" >> $GITHUB_ENV
2938
else
3039
echo "changes=true" >> $GITHUB_ENV
3140
fi
41+
- name: Set up Git
42+
if: env.changes == 'true'
43+
run: |
44+
git config user.name "github-actions[bot]"
45+
git config user.email "github-actions[bot]@users.noreply.github.com"
3246
- name: Commit changes
3347
if: env.changes == 'true'
3448
run: |
35-
cd repo
36-
git checkout -b auto-update-sdk || git checkout auto-update-sdk
49+
BRANCH_NAME="auto-update-sdk-$(date +'%Y-%m-%d-%H-%M-%S')"
50+
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
51+
git checkout -b $BRANCH_NAME || git checkout $BRANCH_NAME
3752
git add .
3853
git commit -m "Auto-update SDK on $(date +'%Y-%m-%d')"
3954
- name: Push changes
4055
if: env.changes == 'true'
4156
env:
4257
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
run: git push --force --set-upstream origin $BRANCH_NAME
59+
- name: Install GitHub CLI
60+
if: env.changes == 'true'
4361
run: |
44-
cd repo
45-
git push --force --set-upstream origin auto-update-sdk
46-
- name: Create a pull request
62+
sudo apt-get update
63+
sudo apt-get install -y gh
64+
- name: Check for existing pull request
4765
if: env.changes == 'true'
66+
env:
67+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
id: check_pr
69+
run: |
70+
PR_EXISTS=$(gh pr list --search "Auto-update SDK" --base main --state open --json number -q '.[0].number')
71+
if [[ -n "$PR_EXISTS" ]]; then
72+
echo "pr_exists=true" >> $GITHUB_ENV
73+
echo "PR_NUMBER=$PR_EXISTS" >> $GITHUB_ENV
74+
else
75+
echo "pr_exists=false" >> $GITHUB_ENV
76+
fi
77+
- name: Create a pull request
78+
if: env.changes == 'true' && env.pr_exists == 'false'
4879
env:
4980
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5081
run: |
5182
PR_TITLE="Auto-update SDK on $(date +'%Y-%m-%d')"
52-
PR_BODY="This pull request was automatically created by GitHub Actions to update the SDK."
53-
curl -H "Authorization: token $GITHUB_TOKEN" \
54-
-X POST \
55-
-H "Content-Type: application/json" \
56-
-d @- \
57-
https://api.github.com/repos/${{ github.repository }}/pulls <<EOF
58-
{
59-
"title": "$PR_TITLE",
60-
"body": "$PR_BODY",
61-
"head": "auto-update-sdk",
62-
"base": "main"
63-
}
64-
EOF
83+
PR_BODY="This pull request was automatically created by GitHub Actions to update the SDK with the latest remote OpenAPI specification."
84+
gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head $BRANCH_NAME --base main
85+
- name: Update existing pull request
86+
if: env.changes == 'true' && env.pr_exists == 'true'
87+
run: |
88+
echo "An existing pull request titled 'Auto-update SDK' is already open. Updating it with the latest changes."
89+
90+
# Push the changes to the existing branch to update the pull request
91+
git push --set-upstream origin $BRANCH_NAME --force
92+
93+
# Add a comment to the existing pull request to notify about the update
94+
gh pr comment $PR_NUMBER --body "This pull request has been updated with the latest changes from the automated SDK update process on $(date +'%Y-%m-%d %H:%M:%S')."
95+

.github/workflows/python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
16+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
1717

1818
steps:
1919
- uses: actions/checkout@v3

.gitlab-ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ stages:
1414
- pip install -r test-requirements.txt
1515
- pytest --cov=opal
1616

17-
pytest-3.7:
18-
extends: .pytest
19-
image: python:3.7-alpine
2017
pytest-3.8:
2118
extends: .pytest
2219
image: python:3.8-alpine

.openapi-generator/templates/github-workflow.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
17+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
1818

1919
steps:
2020
- uses: actions/checkout@v3

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# ref: https://docs.travis-ci.com/user/languages/python
22
language: python
33
python:
4-
- "3.7"
54
- "3.8"
65
- "3.9"
76
- "3.10"

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ SHELL:=/bin/bash
22
PYTHON_POST_PROCESS_FILE=python -m black
33

44
OPENAPI_GEN=openapi-generator generate --enable-post-process-file -i api/openapi.yaml -g python -o . -c config.json -t .openapi-generator/templates
5+
OPENAPI_GEN_CI=openapi-generator-cli generate --enable-post-process-file -i api/openapi.yaml -g python -o . -c config.json -t .openapi-generator/templates
6+
PULL_REMOTE_OPENAPI=curl https://app.opal.dev/openapi.yaml > api/openapi.yaml
57

68
gen-openapi:
79
$(OPENAPI_GEN)
810
gen-openapi-remote:
9-
curl https://app.opal.dev/openapi.yaml > api/openapi.yaml
10-
$(OPENAPI_GEN)
11+
$(PULL_REMOTE_OPENAPI)
12+
$(OPENAPI_GEN)
13+
gen-openapi-remote-for-ci:
14+
$(PULL_REMOTE_OPENAPI)
15+
$(OPENAPI_GEN_CI)

config.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
{"enumClassPrefix": true, "packageName": "opal", "gitHost": "github.com", "gitUserId": "opalsecurity", "gitRepoId": "opal-python", "disallowAdditionalPropertiesIfNotPresent":false}
1+
{
2+
"enumClassPrefix": true,
3+
"packageName": "opal",
4+
"gitHost": "github.com",
5+
"gitUserId": "opalsecurity",
6+
"gitRepoId": "opal-python",
7+
"disallowAdditionalPropertiesIfNotPresent": false
8+
}

requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
urllib3 >= 1.25.3, < 2.1.0
2-
setuptools >= 21.0.0
3-
python_dateutil >= 2.5.3
1+
urllib3 >= 1.25.3, < 3.0.0
2+
python_dateutil >= 2.8.2
43
pydantic >= 2
54
typing-extensions >= 4.7.1

test-requirements.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
pytest~=7.1.3
2-
pytest-cov>=2.8.1
3-
pytest-randomly>=3.12.0
4-
mypy>=1.4.1
5-
types-python-dateutil>=2.8.19
1+
pytest >= 7.2.1
2+
pytest-cov >= 2.8.1
3+
tox >= 3.9.0
4+
flake8 >= 4.0.0
5+
types-python-dateutil >= 2.8.19.14
6+
mypy >= 1.5

0 commit comments

Comments
 (0)