Skip to content

Update release-candidate-workflow.yml #53

Update release-candidate-workflow.yml

Update release-candidate-workflow.yml #53

name: Version update
on:
push:
branches:
main-*
jobs:
# ---------------------------------------------------------------- #
# | Coverage and SonarCloud.io upload | #
# ---------------------------------------------------------------- #
tests-and-sonarcloud:
strategy:
matrix:
version: ["3.10", "3.11"] # TODO: Get Python versions from the project
name: Testing and updating SonarCloud
runs-on: ubuntu-latest
steps:
# Checkout
- name: Branch checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
# Install Python
- name: Setup Python installation
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.version }}
# Install Poetry
- name: Setup Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
poetry self update --preview
echo "$HOME/.local/bin" >> $GITHUB_PATH
# Install required dependencies
- name: Install dependencies
run: poetry install -v --with dev
# Run Coverage
- name: Run Coverage
run: |
poetry run coverage run -m pytest
poetry run coverage report
# Generate XML Coverage result file
- if: matrix.version == '3.10'
name: Generate Coverage XML file
run: poetry run coverage xml
# Upload coverage data to SonarCloud.io
- if: matrix.version == '3.10'
name: Update SonarCloud.io
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# ---------------------------------------------------------------- #
# | Build package and upload it to PyPI | #
# ---------------------------------------------------------------- #
package-creation-and-upload:
name: Create package and upload to PyPI
needs: tests-and-sonarcloud
runs-on: ubuntu-latest
steps:
# Checkout
- name: Repository checkout
uses: actions/checkout@v3
# Install Poetry
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "POETRY_VIRTUALENVS_CREATE=true" >> $GITHUB_ENV
echo "POETRY_VIRTUALENVS_IN_PROJECT=true" >> $GITHUB_ENV
echo "POETRY_INSTALLER_PARALLEL=true" >> $GITHUB_ENV
# Install Python
- name: Python setup
uses: actions/setup-python@v4
with:
python-version: '3.10'
# Install required dependencies
- name: Install dependencies
run: poetry install -vv --no-interaction --without dev
# Configure Nexus in Poetry
- name: Poetry Nexus configuration
run: |
poetry source add nexus https://nexus.appx.cloud/repository/pypi-hosted/simple
poetry config http-basic.nexus ${{ secrets.EKS_NEXUS_USER }} ${{ secrets.EKS_NEXUS_PASSWORD }}
# Determine the current version of the application (for main branch)
- name: Determine current version
if: ${{ github.ref_name == 'main-2.0' }}
run: |
version="$(poetry version --short)${{ github.run_number }}"
echo "Package version: $version"
echo "package_version=$version" >> $GITHUB_ENV
# Determine the current version of the application (for non-main branch)
- name: Determine a version non-main branch
if: ${{ github.ref_name != 'main-2.0' }}
run: |
version="$(poetry version --short)rc${{ github.run_number }}" # rc
echo "Package version: $version"
echo "package_version=$version" >> $GITHUB_ENV
# Build the package and publish it to PyPI
- name: Build and publish package
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
echo "Package version: ${{ env.package_version }}"
poetry version ${{ env.package_version }}
poetry publish --build
# Create a Release on GitHub for the new package
- name: Create a Release for the new package
if: ${{ github.ref_name == 'main-2.0' }}
uses: softprops/action-gh-release@v0.1.14
with:
tag_name: ${{ env.package_version }}
name: "Release ${{ env.package_version }}"
generate_release_notes: True
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ---------------------------------------------------------------- #
# | Build image and upload it to AWS and DockerHub | #
# ---------------------------------------------------------------- #
create-and-upload-image:
name: Create and upload the image
needs: tests-and-sonarcloud
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
environment:
name: ci
steps:
# Checkout
- name: Check out source code
uses: actions/checkout@v3
# Configure AWS
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@master
with:
role-to-assume: arn:aws:iam::325973380531:role/dnb-inno-repository-access-role
aws-region: eu-central-1
# Install Poetry (needed for version)
- name: Setup Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
poetry self update --preview
echo "$HOME/.local/bin" >> $GITHUB_PATH
# Determine the current version of the application
- name: Determine current version
run: |
version="$(poetry version --short)${{ github.run_number }}"
echo "Package version: $version"
echo "package_version=$version" >> $GITHUB_ENV
# Login to Amazon ECR
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
# Create the image and upload it to Amazon ECR (Uvicorn edition)
- name: Build, tag, and push image to Amazon ECR - Uvicorn
run: |
docker build --target uvicorn-image -t ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_UVICORN }}:${{ env.package_version }} .
docker push ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_UVICORN }}:${{ env.package_version }}
docker build --target uvicorn-image -t ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_UVICORN }} .
docker push ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_UVICORN }}
# Create the image and upload it to Amazon ECR (Uvicorn edition)
- name: Build, tag, and push image to Amazon ECR - Gunicorn
run: |
docker build --target gunicorn-image -t ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_GUNICORN }}:${{ env.package_version }} .
docker push ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_GUNICORN }}:${{ env.package_version }}
docker build --target gunicorn-image -t ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_GUNICORN }} .
docker push ${{ secrets.ECR_REGISTRY }}/${{ secrets.ECR_REPOSITORY_GUNICORN }}
# Login to DockerHub
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Create Gunicorn image and upload as latest
- name: Gunicorn - Build and Upload to Docker (latest)
uses: docker/build-push-action@v3
with:
push: true
tags: weatherproviderapi/weather-provider-api-gunicorn:latest
target: gunicorn-image
# Create Gunicorn image and upload as version
- name: Gunicorn - Build and Upload to Docker (versioned)
uses: docker/build-push-action@v3
with:
push: true
tags: weatherproviderapi/weather-provider-api-gunicorn:${{ env.package_version }}
target: gunicorn-image
# Create Uvicorn image and upload as latest
- name: Uvicorn - Build and Upload to Docker (latest)
uses: docker/build-push-action@v3
with:
push: true
tags: weatherproviderapi/weather-provider-api-uvicorn:latest
target: uvicorn-image
# Create Uvicorn image and upload as version
- name: Uvicorn - Build and Upload to Docker (versioned)
uses: docker/build-push-action@v3
with:
push: true
tags: weatherproviderapi/weather-provider-api-uvicorn:${{ env.package_version }}
target: uvicorn-image