Merge branch 'feature/fixing-docs' into develop #61
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: Python & Docker | |
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: | |
venv: | |
name: Virtual Environment | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Cache venv | |
id: cache-python-venv | |
uses: actions/cache@v4 | |
with: | |
path: venv/ | |
key: python-venv | |
- name: Set up Python | |
if: steps.cache-python-venv.outputs.cache-hit != 'true' | |
uses: actions/setup-python@v5 | |
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 toml build 'coverage[toml]' pdoc3 flake8 flake8-docstrings | |
python -c 'import toml; c = toml.load("pyproject.toml"); print("\n".join([*c["project"].get("dependencies", []), *[row for optional_dependency in c["project"].get("optional-dependencies", {}).values() for row in optional_dependency]]))' > /tmp/requirements.txt | |
pip install -r /tmp/requirements.txt | |
lint: | |
name: Linter Test | |
needs: venv | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Cache venv | |
uses: actions/cache@v4 | |
with: | |
path: venv/ | |
key: python-venv | |
- name: Lint with flake8 | |
run: | | |
. venv/bin/activate | |
python -m flake8 --exclude build/,venv/ | |
unittest: | |
name: Unit Test | |
needs: venv | |
runs-on: ubuntu-latest | |
permissions: | |
pull-requests: write | |
contents: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Cache venv | |
uses: actions/cache@v4 | |
with: | |
path: venv/ | |
key: python-venv | |
- name: Activate venv | |
run: | | |
. venv/bin/activate | |
echo PATH=$PATH >> $GITHUB_ENV | |
- name: Install package | |
run: pip install '.[converter,gsheet,s3,sql]' | |
- name: Test | |
run: python -m coverage run -m unittest | |
- name: Display coverage | |
run: python -m coverage report -m | |
- name: Coverage comment | |
if: github.ref_type != 'tag' | |
uses: py-cov-action/python-coverage-comment-action@v3 | |
with: | |
GITHUB_TOKEN: ${{ github.token }} | |
- name: Test coverage must be 100% passed! | |
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/') | |
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@v4 | |
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: [lint, unittest] | |
if: github.ref_type == 'tag' | |
runs-on: ubuntu-latest | |
environment: | |
name: docker | |
url: https://registry.digitalservice.id/harbor/projects/82/repositories/datasae | |
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: | |
registry: registry.digitalservice.id | |
username: ${{ secrets.USERNAME }} | |
password: ${{ secrets.PASSWORD }} | |
- name: Build and push venv's image | |
uses: docker/build-push-action@v5 | |
with: | |
platforms: linux/amd64 | |
target: venv | |
context: . | |
cache-from: type=registry,ref=registry.digitalservice.id/datasae/datasae:venv | |
cache-to: type=inline | |
tags: registry.digitalservice.id/datasae/datasae:venv | |
push: true | |
- name: Build and push app's image | |
uses: docker/build-push-action@v5 | |
with: | |
platforms: linux/amd64 | |
target: app | |
context: . | |
cache-from: type=registry,ref=registry.digitalservice.id/datasae/datasae:latest | |
cache-to: type=inline | |
tags: registry.digitalservice.id/datasae/datasae:latest | |
push: true | |
- name: Push app's image with version | |
run: | | |
export IMAGE_VERSION=$(docker run --platform linux/amd64 --rm --entrypoint pip registry.digitalservice.id/datasae/datasae:latest show datasae | grep Version | awk '{print $2}') | |
docker tag registry.digitalservice.id/datasae/datasae:latest registry.digitalservice.id/datasae/datasae:$IMAGE_VERSION | |
docker push registry.digitalservice.id/datasae/datasae:$IMAGE_VERSION | |
- name: Show package info | |
run: docker run --platform linux/amd64 --rm --entrypoint pip registry.digitalservice.id/datasae/datasae:latest show datasae --verbose | |
docs: | |
name: Release Docs | |
needs: [pypi, docker] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
concurrency: | |
group: pages | |
cancel-in-progress: false | |
environment: | |
name: github-pages | |
url: ${{ steps.docs.outputs.page_url }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Cache venv | |
uses: actions/cache@v4 | |
with: | |
path: venv/ | |
key: python-venv | |
- name: Generate docs | |
run: | | |
. venv/bin/activate | |
pip install '.[converter,gsheet,s3,sql]' | |
python -m pdoc \ | |
datasae \ | |
--html \ | |
--force \ | |
-o docs/ | |
- name: Setup Pages | |
uses: actions/configure-pages@v4 | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v2 | |
with: | |
path: 'docs/datasae/' | |
- name: Deploy to GitHub Pages | |
id: docs | |
uses: actions/deploy-pages@v3 |