Skip to content

Commit a035dc7

Browse files
committed
add python
1 parent c1f691f commit a035dc7

File tree

2 files changed

+43
-33
lines changed

2 files changed

+43
-33
lines changed
Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,69 @@
11
name: Auto-Update SDK
22

3-
# on:
4-
# schedule:
5-
# - cron: "0 0 * * 1" # Runs every Monday at midnight
6-
# workflow_dispatch: # Allows manual triggering of the workflow
7-
8-
on: [push, pull_request]
3+
on:
4+
schedule:
5+
- cron: "0 0 * * 1" # Runs every Monday at midnight
6+
workflow_dispatch: # Allows manual triggering of the workflow
97

108
jobs:
119
update-sdk:
1210
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-version: ["3.11"]
1314
steps:
14-
- name: Checkout repository
15+
- uses: actions/checkout@v3
16+
- name: Set up Python ${{ matrix.python-version }}
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: ${{ matrix.python-version }}
20+
- name: Set up Node.js
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: '18'
24+
- name: Install OpenAPI Generator CLI
25+
run: npm install @openapitools/openapi-generator-cli -g
26+
- name: Install dependencies
1527
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"
28+
python -m pip install --upgrade pip
29+
pip install -r requirements.txt
2030
- name: Pull and generate SDK
21-
run: |
22-
cd repo
23-
make gen-openapi-remote
31+
run: make gen-openapi-remote-for-ci
2432
- name: Check for changes
33+
id: check_changes
2534
run: |
26-
cd repo
2735
if git diff --quiet; then
2836
echo "changes=false" >> $GITHUB_ENV
2937
else
3038
echo "changes=true" >> $GITHUB_ENV
3139
fi
40+
- name: Set up Git
41+
if: env.changes == 'true'
42+
run: |
43+
git config user.name "github-actions[bot]"
44+
git config user.email "github-actions[bot]@users.noreply.github.com"
3245
- name: Commit changes
3346
if: env.changes == 'true'
3447
run: |
35-
cd repo
3648
git checkout -b auto-update-sdk || git checkout auto-update-sdk
3749
git add .
3850
git commit -m "Auto-update SDK on $(date +'%Y-%m-%d')"
3951
- name: Push changes
4052
if: env.changes == 'true'
4153
env:
4254
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
run: git push --force --set-upstream origin auto-update-sdk
56+
- name: Install GitHub CLI
57+
if: env.changes == 'true'
4358
run: |
44-
cd repo
45-
git push --force --set-upstream origin auto-update-sdk
59+
sudo apt-get update
60+
sudo apt-get install -y gh
4661
- name: Create a pull request
4762
if: env.changes == 'true'
4863
env:
4964
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5065
run: |
5166
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
67+
PR_BODY="This pull request was automatically created by GitHub Actions to update the SDK with the latest remote OpenAPI specification."
68+
gh auth login --with-token <<< "${GITHUB_TOKEN}"
69+
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)