Skip to content

Commit 24d58a1

Browse files
authored
Merge pull request #1365 from SciCatProject/openapi-sdk
ci: added workflow for sdk generation and publishing
2 parents 09d2c75 + ee19050 commit 24d58a1

File tree

6 files changed

+340
-77
lines changed

6 files changed

+340
-77
lines changed

.github/openapi/python-config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"generatorName": "python",
3+
"packageName": "scicat-sdk-py",
4+
"projectName": "scicat-sdk-py"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"generatorName": "python-pydantic-v1",
3+
"packageName": "scicat-sdk-pydantic",
4+
"projectName": "scicat-sdk-pydantic"
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"generatorName": "typescript-angular",
3+
"npmName": "@scicatproject/scicat-sdk-ts",
4+
"ngVersion": "16.2.12",
5+
"withInterfaces": true
6+
}

.github/workflows/github-tag-and-release.yml

Lines changed: 0 additions & 77 deletions
This file was deleted.
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
name: Bump release version, build-push image and publish SDK
2+
3+
on:
4+
push:
5+
branches:
6+
- release
7+
8+
env:
9+
NODE_VERSION: 20.x
10+
PYTHON_VERSION: 3.x
11+
RELEASE_BRANCH: release
12+
13+
jobs:
14+
build-release:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: write
18+
packages: write
19+
20+
outputs:
21+
new_tag: ${{ steps.without_v.outputs.tag }}
22+
changelog: ${{ steps.tag_version.outputs.changelog }}
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
## Commit message examples for Release type (patch|minor|major) can be found:
28+
## https://github.com/mathieudutour/github-tag-action
29+
- name: Bump version and push tag
30+
id: tag_version
31+
uses: mathieudutour/[email protected]
32+
with:
33+
github_token: ${{ secrets.GITHUB_TOKEN }}
34+
release_branches: ${{ env.RELEASE_BRANCH }}
35+
36+
- name: Strip 'v' from the tag
37+
id: without_v
38+
run: |
39+
TAG=${{ steps.tag_version.outputs.new_tag }}
40+
WITHOUT_V=${TAG#v}
41+
echo "tag=$WITHOUT_V" >> $GITHUB_OUTPUT
42+
43+
- name: Create a GitHub release
44+
uses: ncipollo/release-action@v1
45+
with:
46+
tag: ${{ steps.tag_version.outputs.new_tag }}
47+
name: Release ${{ steps.tag_version.outputs.new_tag }}
48+
body: ${{ steps.tag_version.outputs.changelog }}
49+
50+
## The setup-qemu-action simplifies the setup of QEMU for cross-platform builds
51+
## https://github.com/docker/setup-qemu-action
52+
- name: Set up QEMU
53+
uses: docker/setup-qemu-action@v3
54+
55+
- name: Set up Docker Buildx
56+
uses: docker/setup-buildx-action@v3
57+
58+
- name: Login to GitHub Container Registry
59+
uses: docker/login-action@v3
60+
with:
61+
registry: ghcr.io
62+
username: ${{ github.actor }}
63+
password: ${{ secrets.GITHUB_TOKEN }}
64+
65+
- name: Set up Node.js
66+
uses: actions/setup-node@v4
67+
with:
68+
node-version: ${{ env.NODE_VERSION }}
69+
70+
- name: Install Node.js dependencies
71+
run: npm ci
72+
73+
## The metadata-action dynamically generates and manages metadata for Docker images,
74+
## like tags and labels, based on the provided inputs and workflow context.
75+
## https://github.com/docker/metadata-action
76+
- name: Docker meta
77+
id: meta
78+
uses: docker/metadata-action@v5
79+
with:
80+
images: ghcr.io/scicatproject/backend-next
81+
tags: |
82+
type=raw,value=stable
83+
type=raw,value=${{ steps.tag_version.outputs.new_tag }}
84+
type=semver,pattern={{version}}
85+
type=raw,value={{date 'YYYY_MM'}},prefix=r_
86+
87+
- name: Build and push
88+
uses: docker/build-push-action@v6
89+
with:
90+
context: .
91+
platforms: linux/amd64,linux/arm64/v8
92+
push: true
93+
tags: ${{ steps.meta.outputs.tags }}
94+
95+
start-backend-export-swagger:
96+
runs-on: ubuntu-latest
97+
steps:
98+
- name: Checkout repository
99+
uses: actions/checkout@v4
100+
101+
- name: Set up Node.js
102+
uses: actions/setup-node@v4
103+
with:
104+
node-version: ${{env.NODE_VERSION}}
105+
106+
- name: Pull and Run MongoDB
107+
run: |
108+
docker pull mongo:latest
109+
docker run -d --name mongo-container -p 27017:27017 mongo:latest
110+
111+
- name: Install Backend and wait for it to be ready
112+
env:
113+
MONGODB_URI: "mongodb://localhost:27017/scicat"
114+
JWT_SECRET: thisIsTheJwtSecret
115+
run: |
116+
npm install -g wait-on && npm install
117+
npm run start & wait-on http://localhost:3000/api/v3/health --timeout 200000
118+
119+
- name: Download the Swagger schema
120+
run: curl -o ./swagger-schema.json http://localhost:3000/explorer-json
121+
122+
- uses: actions/upload-artifact@v4
123+
with:
124+
name: swagger-schema
125+
path: ./swagger-schema.json
126+
127+
generate-upload-sdk:
128+
runs-on: ubuntu-latest
129+
needs:
130+
- build-release
131+
- start-backend-export-swagger
132+
strategy:
133+
matrix:
134+
generator: [python, python-pydantic-v1, typescript]
135+
136+
steps:
137+
- name: Checkout repository
138+
uses: actions/checkout@v4
139+
140+
- uses: actions/download-artifact@v4
141+
with:
142+
name: swagger-schema
143+
path: .
144+
145+
- name: Generate Client
146+
uses: openapi-generators/openapitools-generator-action@v1
147+
with:
148+
generator: ${{ matrix.generator }}
149+
openapi-file: ./swagger-schema.json
150+
config-file: .github/openapi/${{ matrix.generator }}-config.json
151+
command-args: |
152+
--git-repo-id scicat-backend-next \
153+
--git-user-id SciCatProject \
154+
-o ./sdk/${{ matrix.generator }} $(
155+
if [ "${{ matrix.generator }}" == "typescript" ]; then
156+
echo "--additional-properties=npmVersion=${{ needs.build-release.outputs.new_tag}}";
157+
elif [ "${{ matrix.generator }}" == "python" ]; then
158+
echo "--additional-properties=packageVersion=${{ needs.build-release.outputs.new_tag}}";
159+
elif [ "${{ matrix.generator }}" == "python-pydantic-v1" ]; then
160+
echo "--additional-properties=packageVersion=${{ needs.build-release.outputs.new_tag}}";
161+
fi
162+
)
163+
164+
- uses: actions/upload-artifact@v4
165+
with:
166+
name: sdk-${{ matrix.generator }}-${{ github.sha }}
167+
path: ./sdk
168+
169+
npm-publish:
170+
needs: generate-upload-sdk
171+
runs-on: ubuntu-latest
172+
environment:
173+
name: npm-sdk-package
174+
url: https://www.npmjs.com/package/@scicatproject/scicat-sdk-ts
175+
176+
steps:
177+
- name: Checkout repository
178+
uses: actions/checkout@v4
179+
180+
- name: Set up Node.js
181+
uses: actions/setup-node@v4
182+
with:
183+
node-version: ${{ env.NODE_VERSION }}
184+
registry-url: "https://registry.npmjs.org/"
185+
186+
- name: Download TypeScript SDK Artifact
187+
uses: actions/download-artifact@v4
188+
with:
189+
name: sdk-typescript-${{github.sha}}
190+
path: ./sdk
191+
192+
- name: Publish package
193+
run: |
194+
npm install
195+
npm run build
196+
npm publish --access public
197+
working-directory: ./sdk/typescript/
198+
env:
199+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
200+
201+
pypi-publish:
202+
needs: generate-upload-sdk
203+
runs-on: ubuntu-latest
204+
strategy:
205+
matrix:
206+
sdk_type: [python, python-pydantic-v1]
207+
environment:
208+
name: ${{ matrix.sdk_type }}-sdk-package
209+
url: ${{ matrix.sdk_type == 'python' && 'https://pypi.org/project/scicat-sdk-py' || 'https://pypi.org/project/scicat-sdk-pydantic' }}
210+
permissions:
211+
id-token: write
212+
213+
steps:
214+
- name: Checkout repository
215+
uses: actions/checkout@v4
216+
217+
- name: Set up Python
218+
uses: actions/setup-python@v4
219+
with:
220+
python-version: ${{ env.PYTHON_VERSION }}
221+
222+
- name: Download Python SDK Artifact
223+
uses: actions/download-artifact@v4
224+
with:
225+
name: sdk-${{ matrix.sdk_type }}-${{github.sha}}
226+
path: ./sdk
227+
228+
- name: Install dependencies
229+
run: |
230+
python -m pip install --upgrade pip
231+
pip install setuptools wheel
232+
working-directory: ./sdk/${{ matrix.sdk_type }}/
233+
234+
- name: Build package
235+
run: |
236+
python setup.py sdist bdist_wheel
237+
working-directory: ./sdk/${{ matrix.sdk_type }}/
238+
239+
- name: Publish package
240+
uses: pypa/gh-action-pypi-publish@release/v1
241+
with:
242+
packages-dir: ./sdk/${{ matrix.sdk_type }}/dist/

0 commit comments

Comments
 (0)