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