Skip to content

Commit

Permalink
ci: restructure ci pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
mikonse committed Nov 10, 2023
1 parent e6c7355 commit ce476b4
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 133 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/backend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: backend
on:
workflow_call:

jobs:
pylint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install dependencies
run: pip install -e '.[dev,test]'
- name: Analysing the code with pylint
run: make pylint

mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install dependencies
run: pip install -e '.[dev,test]'
- name: Analysing the code with mypy
run: make mypy

test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version:
- "3.10"
- "3.11"
os: [ubuntu-latest]
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: "password"
POSTGRES_USER: "abrechnung"
POSTGRES_DB: "abrechnung"
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
env:
TEST_DB_USER: "abrechnung"
TEST_DB_HOST: "localhost"
TEST_DB_DATABASE: "abrechnung"
TEST_DB_PASSWORD: "password"
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install -e '.[dev,test]'
- name: Run all tests
run: pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html

format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install dependencies
run: pip install -e '.[dev,test]'
- name: Check formatting
run: make check-format
103 changes: 12 additions & 91 deletions .github/workflows/ci_testing.yaml → .github/workflows/frontend.yaml
Original file line number Diff line number Diff line change
@@ -1,88 +1,9 @@
name: Tests
name: frontend
on:
push:
branches: [ "master" ]
pull_request:
workflow_call:

jobs:
pylint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install dependencies
run: pip install -e '.[dev,test]'
- name: Analysing the code with pylint
run: make pylint

mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install dependencies
run: pip install -e '.[dev,test]'
- name: Analysing the code with mypy
run: make mypy

test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version:
- "3.10"
- "3.11"
os: [ubuntu-latest]
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: "password"
POSTGRES_USER: "abrechnung"
POSTGRES_DB: "abrechnung"
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
env:
TEST_DB_USER: "abrechnung"
TEST_DB_HOST: "localhost"
TEST_DB_DATABASE: "abrechnung"
TEST_DB_PASSWORD: "password"
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install -e '.[dev,test]'
- name: Run all tests
run: pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html

format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install dependencies
run: pip install -e '.[dev,test]'
- name: Check formatting
run: make check-format

format-frontend:
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -100,7 +21,7 @@ jobs:
- name: Check JavaScript formatting
run: npx prettier --check .

build-web:
test:
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -116,9 +37,9 @@ jobs:
- name: Install dependencies
run: npm ci
- name: Build web app
run: npx nx build web
test-frontend:
run: npx nx run-many --target test

lint:
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -134,9 +55,9 @@ jobs:
- name: Install dependencies
run: npm ci
- name: Build web app
run: npx nx run-many --target test
lint-frontend:
run: npx nx run-many --target lint

build-web:
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -152,7 +73,7 @@ jobs:
- name: Install dependencies
run: npm ci
- name: Build web app
run: npx nx run-many --target lint
run: npx nx build web

build-app:
runs-on: ubuntu-latest
Expand All @@ -170,7 +91,7 @@ jobs:
- name: Install dependencies
run: npm ci
- name: Setup Android SDK
uses: actions/setup-android@v2
uses: android-actions/setup-android@v2
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Build web app
Expand All @@ -179,4 +100,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: app-debug-apk
path: frontend/apps/mobile/android/app/build/outputs/apk/debug/app-debug.apk
path: frontend/apps/mobile/android/app/build/outputs/apk/debug/app-debug.apk
10 changes: 10 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Pull Request
on:
pull_request:

jobs:
build_and_test_frontend:
uses: ./.github/workflows/frontend.yaml

build_and_test_backend:
uses: ./.github/workflows/backend.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build release artifacts
name: Push or tag on master
on:
# we build on all pushes to master to (hopefully) get early warning
# of things breaking (but only build one set of debs)
Expand All @@ -13,44 +13,18 @@ env:
DOCKER_IMAGE_TAGS: latest ${{ github.sha }} ${{github.ref_name}}

jobs:
build-and-publish-sdist:
name: Build and publish Python distributions to PyPI and TestPyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
build_and_test_frontend:
uses: ./.github/workflows/frontend.yaml

- name: Set up Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.9

- name: Install pypa/flit
run: pip install flit

- name: Build a binary wheel and a source tarball
run: flit build

- uses: actions/upload-artifact@v2
with:
name: python-dist
path: dist/*

#- name: Publish distribution 📦 to Test PyPI
# if: startsWith(github.ref, 'refs/tags')
# uses: pypa/gh-action-pypi-publish@master
# with:
# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
# repository_url: https://test.pypi.org/legacy/

#- name: Publish distribution 📦 to PyPI
# if: startsWith(github.ref, 'refs/tags')
# uses: pypa/gh-action-pypi-publish@master
# with:
# password: ${{ secrets.PYPI_API_TOKEN }}
build_and_test_backend:
uses: ./.github/workflows/backend.yaml

get-distros:
name: "Calculate list of debian distros and docker image tags"
runs-on: ubuntu-latest
needs:
- frontend
- backend
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand All @@ -69,11 +43,12 @@ jobs:
outputs:
distros: ${{ steps.set-distros.outputs.distros }}
tags: ${{ steps.set-distros.outputs.tags }}

build-and-publish-docker:
name: Build and publish ready made docker containers
runs-on: ubuntu-latest
needs: get-distros
needs:
- get-distros
steps:
- uses: actions/checkout@master

Expand All @@ -95,7 +70,7 @@ jobs:
registry: quay.io/abrechnung
username: ${{ secrets.DOCKERHUB_REGISTRY_USER }}
password: ${{ secrets.DOCKERHUB_REGISTRY_PASSWORD }}

- name: Build Frontend Image
id: build-frontend-image
uses: redhat-actions/buildah-build@v2
Expand All @@ -117,7 +92,8 @@ jobs:

# now build the packages with an abrechnung build.
build-debs:
needs: get-distros
needs:
- get-distros
name: "Build .deb packages"
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -182,23 +158,22 @@ jobs:
name: "Attach assets to release"
if: ${{ !failure() && !cancelled() && startsWith(github.ref, 'refs/tags/') }}
needs:
- frontend
- backend
- build-debs
- build-and-publish-sdist
runs-on: ubuntu-latest
steps:
- name: Download all workflow run artifacts
uses: actions/download-artifact@v2
- name: Build a tarball for the debs
run: tar -cvJf debs.tar.xz debs
- name: Attach to release
uses: softprops/action-gh-release@a929a66f232c1b11af63782948aa2210f981808a # PR#109
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
python-dist/*
debs/*.deb
debs.tar.xz
frontend/apps/mobile/android/app/build/outputs/apk/debug/app-debug.apk
# if it's not already published, keep the release as a draft.
draft: true
# mark it as a prerelease if the tag contains 'rc'.
Expand Down

0 comments on commit ce476b4

Please sign in to comment.