fix: coverage report command on tasks.json and github action #194
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
# Copyright (C) Free Software Foundation, Inc. All rights reserved. | |
# Licensed under the AGPL-3.0-only License. See LICENSE in the project root | |
# for license information. | |
name: CI/CD | |
on: | |
pull_request: | |
push: | |
branches: ['**'] | |
tags: | |
- '[0-9]+.[0-9]+.[0-9]+' | |
- '[0-9]+.[0-9]+.[0-9]+-[a-z]+' | |
- '[0-9]+.[0-9]+.[0-9]+-[a-z]+.[0-9]+' | |
jobs: | |
lint: | |
name: Linter Test | |
runs-on: ubuntu-latest | |
container: | |
image: pipelinecomponents/flake8 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Lint with flake8 | |
run: flake8 | |
jar: | |
name: Get Jar File | |
if: | |
github.ref_type == 'tag' || | |
github.event_name == 'pull_request' || | |
contains('refs/heads/main refs/heads/develop', github.ref) || | |
startsWith(github.ref, 'refs/heads/release/') || | |
startsWith(github.ref, 'refs/heads/hotfix/') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Cache jar | |
id: cache-java-jar | |
uses: actions/cache@v3 | |
with: | |
path: app/asicverifier.jar | |
key: java-jar | |
- name: Get jar file from docker | |
if: steps.cache-java-jar.outputs.cache-hit != 'true' | |
run: docker run --rm --platform linux/amd64 -v $PWD/app/:/app/ --entrypoint cp niis/xroad-security-server-sidecar:7.0.4 /usr/share/xroad/jlib/asicverifier.jar app/asicverifier.jar | |
venv: | |
name: Virtual Environment | |
if: | |
github.ref_type == 'tag' || | |
github.event_name == 'pull_request' || | |
contains('refs/heads/main refs/heads/develop', github.ref) || | |
startsWith(github.ref, 'refs/heads/release/') || | |
startsWith(github.ref, 'refs/heads/hotfix/') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Cache venv | |
id: cache-python-venv | |
uses: actions/cache@v3 | |
with: | |
path: venv/ | |
key: python-venv | |
- name: Set up Python | |
if: steps.cache-python-venv.outputs.cache-hit != 'true' | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.8' | |
- name: Install dependencies | |
if: steps.cache-python-venv.outputs.cache-hit != 'true' | |
run: | | |
python -m venv venv/ | |
. venv/bin/activate | |
pip install --upgrade pip | |
pip install build 'coverage[toml]' httpx | |
unittest: | |
name: Unit Test | |
needs: [jar, venv] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Cache venv | |
uses: actions/cache@v3 | |
with: | |
path: venv/ | |
key: python-venv | |
- name: Activate venv | |
run: | | |
. venv/bin/activate | |
echo PATH=$PATH >> $GITHUB_ENV | |
- name: Install package | |
run: pip install '.[restful-api]' | |
- name: Set up Java | |
uses: actions/setup-java@v3 | |
with: | |
distribution: temurin | |
java-version: '8' | |
- name: Cache jar | |
uses: actions/cache@v3 | |
with: | |
path: app/asicverifier.jar | |
key: java-jar | |
- name: Test | |
env: | |
JAR_PATH: app/asicverifier.jar | |
run: python -m coverage run -m unittest | |
- name: Display test coverage | |
run: python -m coverage report -m | |
- name: Upload coverage reports to Codecov | |
uses: codecov/codecov-action@v3 | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
- name: Test coverage must be 100% passed! | |
run: if [ $(printf '%.0f' $(python -m coverage report | awk '$1 == "TOTAL" {print $NF+0}')) = 100 ]; then exit; else exit 1; fi | |
pypi: | |
name: PyPI | |
needs: [lint, unittest] | |
if: github.ref_type == 'tag' | |
runs-on: ubuntu-latest | |
environment: | |
name: python | |
url: https://pypi.org/project/${{ github.event.repository.name }}/ | |
permissions: | |
id-token: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Cache venv | |
uses: actions/cache@v3 | |
with: | |
path: venv/ | |
key: python-venv | |
- name: Build package | |
run: | | |
. venv/bin/activate | |
python -m build | |
- name: Publish package distributions to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
skip-existing: true | |
docker: | |
name: Docker | |
needs: pypi | |
if: echo ${{ github.ref }} | egrep '^refs/tags/[0-9]+.[0-9]+.[0-9]+$' | |
runs-on: ubuntu-latest | |
environment: | |
name: docker | |
url: https://hub.docker.com/r/${{ github.repository }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
driver: docker | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.TOKEN }} | |
- name: Build and push image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64 | |
cache-from: | | |
type=registry,ref=${{ github.repository }} | |
type=registry,ref=niis/xroad-security-server-sidecar:7.0.4 | |
type=registry,ref=eclipse-temurin:8-alpine | |
cache-to: type=inline | |
tags: ${{ github.repository }} | |
push: true | |
- name: Update repo description | |
uses: peter-evans/dockerhub-description@v3 | |
with: | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.TOKEN }} | |
short-description: ${{ github.event.repository.description }} | |
- name: Show package info | |
run: docker run --platform linux/amd64 --rm --entrypoint pip ${{ github.repository }} show ${{ github.event.repository.name }} --verbose |