Skip to content

Commit 2d29155

Browse files
authored
Create main.yml
1 parent 3bdeb3f commit 2d29155

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

.github/workflows/main.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Generate Client
2+
3+
# Runs this action whenever there are any changes to the master branch.
4+
on:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
client:
11+
runs-on: ubuntu-latest
12+
13+
# Checks out the entire repo.
14+
steps:
15+
- name: Checks out repo
16+
uses: actions/checkout@v1
17+
18+
# Generates a openapi.yaml file based on the FastAPI project.
19+
- name: Generate OpenAPI file
20+
uses: column-st/fastapi-openapi-specs-action@v1.0.2
21+
with:
22+
moduleDir: collector
23+
fileName: main.py
24+
appName: app
25+
fastapiVersioning: v1
26+
27+
# Uses an external tool, openapitools-generator-action, to generate the client code.
28+
# The 'openapirc.json' file is the following: { "packageName": "collector", "projectName": "collector" }
29+
# and it lives inside the master branch of the repository. Command outputs a new folder called
30+
# 'python-client' with the relevant client code.
31+
- name: Generate Python Client
32+
uses: triaxtec/openapitools-generator-action@v1.0.0
33+
with:
34+
generator: python
35+
openapi-file: openapi.yaml
36+
config-file: openapirc.json
37+
38+
# Deletes every file in the folder, except '.git' and the new generated 'python-client' folder.
39+
# Moves all content of the 'python-client' folder to the root directory.
40+
- name: Cleans the branch up.
41+
run: |
42+
# Removes all files except the .git and python-client folder.
43+
shopt -s extglob
44+
sudo rm -rf !(.|..|.git|python-client)
45+
# Moves all of the content of the python-client folder out,
46+
# and deletes the folder.
47+
mv python-client/* .
48+
rm -rf python-client
49+
50+
# Commits the new changes into a new branch called 'client'.
51+
- name: Commit changes.
52+
run: |
53+
git checkout -b client
54+
git config --local user.email "action@github.com"
55+
git config --local user.name "GitHub Action"
56+
git add .
57+
git commit -m "Generated client." -a || true
58+
59+
# Pushes all of these changes into the GitHub repository.
60+
- name: Push changes to client branch
61+
uses: ad-m/github-push-action@master
62+
with:
63+
github_token: ${{ secrets.GITHUB_TOKEN }}
64+
branch: client
65+
force: True

0 commit comments

Comments
 (0)