Skip to content

Merge pull request #1437 from SciCatProject/master #1

Merge pull request #1437 from SciCatProject/master

Merge pull request #1437 from SciCatProject/master #1

name: Bump release version, build-push image and publish SDK
on:
push:
branches:
- release
env:
NODE_VERSION: 20.x
PYTHON_VERSION: 3.x
RELEASE_BRANCH: release
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_
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64/v8
push: true
tags: ${{ steps.meta.outputs.tags }}
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 scicat-backend-next \
--git-user-id SciCatProject \
-o ./sdk/${{ matrix.generator }} $(
if [ "${{ matrix.generator }}" == "typescript-angular" ]; 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/scicat-sdk-ts
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 Angular SDK Artifact
uses: actions/download-artifact@v4
with:
name: sdk-typescript-angular-${{github.sha}}
path: ./sdk
- name: Publish package
run: |
npm install
npm run build
npm publish --access public
working-directory: ./sdk/typescript-angular/
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-sdk-py' || 'https://pypi.org/project/scicat-sdk-pydantic' }}
permissions:
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
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/