Skip to content

Commit

Permalink
build: added sdk generate & publish github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Junjiequan committed Aug 22, 2024
1 parent 3e4dc8b commit 27d0618
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 0 deletions.
105 changes: 105 additions & 0 deletions .github/workflows/publish-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Generate and Publish SDK for multiple languages

on:
push:
branches:
- release

env:
NODE_VERSION: 18.x

jobs:
generate-sdk:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{env.NODE_VERSION}}

- name: Run docker-compose
run: |
cp CI/ESS/e2e/docker-compose.e2e.yaml docker-compose.yaml
docker compose pull
docker compose build --no-cache
docker compose up -d
- name: Wait for Backend
run: |
npm install -g wait-on
wait-on http://localhost:3000/api/v3/health --timeout 200000
- name: Run SDK generation script
run: ./scripts/generate-sdk-local.sh

- name: Fix permissions for SDK directory
run: sudo chown -R $USER:$USER ./sdk

- name: Upload generated SDK JSON
uses: actions/upload-artifact@v3
with:
name: sdk
path: ./sdk

npm-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: "https://registry.npmjs.org/"

- name: Publish SDK to npm
run: |
npm install
npm run build
cd dist && npm publish --access public
working-directory: ./sdk/typescript
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

pypi-publish:
needs: generate-sdk
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/Scicat-Python-SDK
permissions:
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download generated SDK
uses: actions/download-artifact@v3
with:
name: sdk
path: ./sdk/

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
working-directory: ./sdk/python

- name: Build package
run: |
python setup.py sdist bdist_wheel
working-directory: ./sdk/python

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: ./sdk/python/dist/
24 changes: 24 additions & 0 deletions scripts/generate-sdk-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -e

# Download the Swagger schema
curl -o ./swagger-schema.json http://localhost:3000/explorer-json

# Remove the existing SDK directory if it exists
rm -rf ./sdk

docker run \
--rm \
-v "${PWD}":/local \
openapitools/openapi-generator-cli generate \
-c /local/scripts/typescript-sdk.json \

docker run \
--rm \
-v "${PWD}":/local \
openapitools/openapi-generator-cli generate \
-c /local/scripts/python-sdk.json \

# Remove the Swagger schema file
rm ./swagger-schema.json
8 changes: 8 additions & 0 deletions scripts/python-sdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"packageName": "Scicat-Python-SDK",
"projectName": "Scicat-Python-SDK",
"packageVerion": "0.0.1",
"inputSpec": "/local/swagger-schema.json",
"generatorName": "python",
"outputDir": "/local/sdk/python"
}
9 changes: 9 additions & 0 deletions scripts/typescript-sdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"npmName": "@scicat-sdk/typescript-angular",
"npmVersion": "0.0.7",
"ngVersion": "16.2.12",
"withInterfaces": true,
"inputSpec": "/local/swagger-schema.json",
"generatorName": "typescript-angular",
"outputDir": "/local/sdk/typescript"
}

0 comments on commit 27d0618

Please sign in to comment.