Merge pull request #48 from PSNAppz/1.0 #2
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Bridge API Tag Workflow | |
on: | |
push: | |
tags: | |
- "*" | |
branches-ignore: | |
- '*' | |
workflow_dispatch: | |
jobs: | |
publish-to-pypi: | |
name: Publish to PyPI For API Tag | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- uses: actions/checkout@v3 | |
- name: Install build dependencies | |
run: pip install build | |
- name: Build distribution | |
run: python -m build ./openg2p-g2p-bridge-api | |
- name: Publish | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
password: ${{ secrets.PYPI_API_TOKEN }} | |
packages-dir: ./openg2p-g2p-bridge-api/dist/ | |
openapi-publish: | |
name: OpenAPI Generate and Publish For API Tag | |
needs: publish-to-pypi | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Get branch name (merge) | |
run: | | |
echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
- name: Setup python for openapi generate | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- name: Install app | |
run: | | |
python -m pip install git+https://github.com/openg2p/[email protected]\#subdirectory=openg2p-fastapi-common | |
python -m pip install git+https://github.com/openg2p/[email protected]\#subdirectory=openg2p-fastapi-auth | |
python -m pip install git+https://github.com/openg2p/[email protected]\#subdirectory=openg2p-g2pconnect-common-lib | |
python -m pip install git+https://github.com/openg2p/[email protected]\#subdirectory=openg2p-g2p-bridge-models | |
python -m pip install openg2p-g2p-bridge-api==1.0.0 | |
- name: Generate openapi json | |
run: | | |
mkdir -p openg2p-g2p-bridge-api/api-docs/generated | |
python3 openg2p-g2p-bridge-api/main.py getOpenAPI openg2p-g2p-bridge-api/api-docs/generated/openapi.json | |
- name: Setup nodejs | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18' | |
- name: Publish to stoplight | |
run: | | |
npx @stoplight/cli@5 push --ci-token ${{ secrets.STOPLIGHT_PROJECT_TOKEN }} --url https://openg2p.stoplight.io --branch ${{ env.TAG_NAME }} --directory openg2p-g2p-bridge-api/api-docs/generated | |
docker-build-for-tag: | |
name: Docker Build and Push For API Tag | |
needs: publish-to-pypi | |
runs-on: ubuntu-latest | |
env: | |
NAMESPACE: ${{ secrets.docker_hub_organisation || 'openg2p' }} | |
SERVICE_NAME: openg2p-g2p-bridge-api | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Docker build | |
run: | | |
echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
IMAGE_ID=$NAMESPACE/$SERVICE_NAME | |
# Change all uppercase to lowercase | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
VERSION=TAG_NAME | |
echo IMAGE_ID=$IMAGE_ID | |
echo VERSION=$VERSION | |
echo IMAGE_ID=$IMAGE_ID >> $GITHUB_ENV | |
echo VERSION=$VERSION >> $GITHUB_ENV | |
docker build ./openg2p-g2p-bridge-api -f ./openg2p-g2p-bridge-api/Dockerfile-pypi \ | |
--tag $IMAGE_ID:$VERSION | |
if [[ '${{ secrets.docker_hub_token }}' != '' && '${{ secrets.docker_hub_actor }}' != '' ]]; then | |
export DOCKER_PUSH="true" | |
echo DOCKER_PUSH=$DOCKER_PUSH >> $GITHUB_ENV | |
fi | |
- name: Docker push | |
if: env.DOCKER_PUSH == 'true' | |
run: | | |
echo "${{ secrets.docker_hub_token }}" | docker login -u ${{ secrets.docker_hub_actor }} --password-stdin | |
docker push ${{ env.IMAGE_ID }}:${{ env.VERSION }} |