mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-12-23 19:08:55 +01:00
The building and pushing of artifacts takes to long. With those changes build experimental images aren't pushed anymore. This saves build time and disc space.
227 lines
6.7 KiB
YAML
227 lines
6.7 KiB
YAML
name: Test & Build
|
|
|
|
on:
|
|
push:
|
|
pull_request:
|
|
types: [reopened, opened, synchronize]
|
|
release:
|
|
types:
|
|
- created
|
|
|
|
jobs:
|
|
test:
|
|
name: Pytest
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
|
|
steps:
|
|
- name: Check out repository code
|
|
uses: actions/checkout@v4
|
|
- name: Setup Python
|
|
uses: actions/setup-python@v4
|
|
with:
|
|
python-version: 3.11
|
|
- name: Install APT
|
|
run: |
|
|
sudo apt update
|
|
- name: Install and configure Poetry
|
|
uses: snok/install-poetry@v1
|
|
with:
|
|
version: 1.6.1
|
|
virtualenvs-path: ~/local/share/virtualenvs
|
|
- id: cache-pipenv
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: ~/.local/share/virtualenvs
|
|
key: venv
|
|
- run: poetry install --without develop,doc,lint --all-extras
|
|
- name: Run test suite
|
|
run: |
|
|
poetry run pytest --junit-xml=unit-test-results.xml --cov-report "xml:coverage.xml" --cov=src tests/
|
|
- name: Archive code coverage results
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: code-coverage-report
|
|
path: |
|
|
coverage.xml
|
|
.coverage
|
|
- name: Archive code coverage results
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: test-report
|
|
path: |
|
|
unit-test-results.xml
|
|
if-no-files-found: error
|
|
|
|
coverage_pull_request:
|
|
name: Coverage Report on pull request
|
|
if: ${{ github.event_name == 'pull_request' && !startsWith(github.ref, 'refs/heads/dependabot/')}}
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
steps:
|
|
- uses: actions/download-artifact@v3
|
|
with:
|
|
name: code-coverage-report
|
|
- name: Get Cover
|
|
uses: orgoro/coverage@v3.1
|
|
with:
|
|
coverageFile: coverage.xml
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
thresholdAll: 0.7
|
|
thresholdNew: 0.7
|
|
thresholdModified: 0.7
|
|
|
|
coverage_report:
|
|
name: Coverage HTML Report
|
|
if: ${{ github.event_name == 'push' }}
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
steps:
|
|
- name: Check out repository code
|
|
uses: actions/checkout@v4
|
|
- name: Setup Python
|
|
uses: actions/setup-python@v4
|
|
with:
|
|
python-version: 3.11
|
|
- id: cache-pipenv
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: ~/.local/share/virtualenvs
|
|
key: venv
|
|
- name: Install and configure Poetry
|
|
uses: snok/install-poetry@v1
|
|
with:
|
|
version: 1.6.1
|
|
virtualenvs-path: ~/local/share/virtualenvs
|
|
- run: |
|
|
poetry install --only test --all-extras
|
|
- uses: actions/download-artifact@v3
|
|
with:
|
|
name: code-coverage-report
|
|
- name: Make Coverage Report
|
|
run: |
|
|
poetry run coverage html
|
|
- name: Archive builds
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: Coverage Report HTML
|
|
path: htmlcov/
|
|
|
|
build:
|
|
name: Wheel-Build
|
|
if: ${{ github.event_name == 'push'}}
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
steps:
|
|
- name: Setup Python
|
|
uses: actions/setup-python@v4
|
|
with:
|
|
python-version: 3.11
|
|
- name: Install and configure Poetry
|
|
uses: snok/install-poetry@v1
|
|
with:
|
|
version: 1.6.1
|
|
virtualenvs-path: ~/local/share/virtualenvs
|
|
- id: cache-pipenv
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: ~/.local/share/virtualenvs
|
|
key: venv
|
|
- name: Check out repository code
|
|
uses: actions/checkout@v4
|
|
- run: |
|
|
poetry build
|
|
- name: Archive builds
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: wheel-builds
|
|
path: dist/
|
|
|
|
docker-build:
|
|
name: Docker Build
|
|
if: ${{ github.event_name == 'push' && !startsWith(github.ref, 'refs/heads/dependabot/')}}
|
|
runs-on: ubuntu-latest
|
|
needs: [build]
|
|
steps:
|
|
- name: Check out repository code
|
|
uses: actions/checkout@v4
|
|
|
|
- uses: actions/download-artifact@v3
|
|
with:
|
|
name: wheel-builds
|
|
path: dist
|
|
|
|
- id: tag_or_main
|
|
run: |
|
|
if [ "$GITHUB_EVENT_NAME" = "release" ]; then
|
|
echo "TAG_OR_MAIN=$(echo $GITHUB_REF | awk -F / '{print $NF}')" >> $GITHUB_ENV
|
|
echo "LATEST=latest" >> $GITHUB_ENV
|
|
elif [ "$GITHUB_EVENT_NAME" = "push" ] && [ "$GITHUB_REF" = "refs/heads/main" ]; then
|
|
echo "TAG_OR_MAIN=main" >> $GITHUB_ENV
|
|
echo "LATEST=main" >> $GITHUB_ENV
|
|
else
|
|
echo "TAG_OR_MAIN=experimental" >> $GITHUB_ENV
|
|
echo "LATEST=experimental" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- run: |
|
|
echo "Print ${{ env.TAG_OR_MAIN }}"
|
|
|
|
- name: Build All prior to push
|
|
run: |
|
|
docker build --target ingest --build-arg GIT_HASH=${{github.sha}} .
|
|
docker build --target data-transformation --build-arg GIT_HASH=${{github.sha}} .
|
|
docker build --target web-server --build-arg GIT_HASH=${{github.sha}} .
|
|
docker image ls
|
|
|
|
- name: Exit workflow on pull request
|
|
if: ${{ github.event_name == 'pull_request' }}
|
|
run: exit 0
|
|
|
|
- name: Exit workflow on not main branch
|
|
if: ${{ github.ref != 'refs/heads/main'}}
|
|
run: exit 0
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Build and push ingest
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
build-args: |
|
|
"GIT_HASH=${{github.sha}}"
|
|
push: ${{ github.ref == 'refs/heads/main'}}
|
|
tags: |
|
|
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/ingest:${{ env.TAG_OR_MAIN }}
|
|
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/ingest:${{ env.LATEST }}
|
|
target: ingest
|
|
context: .
|
|
|
|
- name: Build and push data-transformation
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
build-args: |
|
|
"GIT_HASH=${{github.sha}}"
|
|
push: ${{ github.ref == 'refs/heads/main'}}
|
|
tags: |
|
|
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/data-transformation:${{ env.TAG_OR_MAIN }}
|
|
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/data-transformation:${{ env.LATEST }}
|
|
target: data-transformation
|
|
context: .
|
|
|
|
- name: Build and push web-server
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
build-args: |
|
|
"GIT_HASH=${{github.sha}}"
|
|
push: ${{ github.ref == 'refs/heads/main'}}
|
|
tags: |
|
|
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/web-server:${{ env.TAG_OR_MAIN }}
|
|
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/web-server:${{ env.LATEST }}
|
|
target: web-server
|
|
context: .
|