Skip to content

Commit 897d2d0

Browse files
committed
add python
1 parent c1f691f commit 897d2d0

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

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

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,69 @@ 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-
87
on: [push, pull_request]
98

109
jobs:
1110
update-sdk:
1211
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.11"]
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 auto-update-sdk
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
62+
sudo apt-get update
63+
sudo apt-get install -y gh
4664
- name: Create a pull request
4765
if: env.changes == 'true'
4866
env:
4967
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5068
run: |
5169
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
70+
PR_BODY="This pull request was automatically created by GitHub Actions to update the SDK with the latest remote OpenAPI specification."
71+
gh auth login --with-token <<< "${GITHUB_TOKEN}"
72+
gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head auto-update-sdk --base main

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)

0 commit comments

Comments
 (0)