Improved CI/CD #19
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
name: PR Validation | |
on: | |
pull_request: | |
branches: ["main"] | |
types: [opened, synchronize] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
# Don't want the tests running in parallel | |
cancel-in-progress: true | |
jobs: | |
app-build-and-test: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.11"] | |
steps: | |
- uses: szenius/set-timezone@v2.0 | |
with: | |
timezoneLinux: "Europe/Amsterdam" | |
name: Set Timezone to Europe/Amsterdam | |
- uses: actions/checkout@v4 | |
name: Checkout repository | |
- uses: gerlero/apt-install@v1 | |
with: | |
packages: build-essential git libcurl4-openssl-dev curl libssl-dev | |
install-recommends: false | |
name: Install OS dependencies (apt) | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: pip | |
cache-dependency-path: pyproject.toml | |
name: Install Python [${{ matrix.python-version }}] and setup cache | |
- uses: BSFishy/pip-action@v1 | |
with: | |
requirements: requirements_for_test.txt | |
name: Install application requirements (pip) | |
- uses: astral-sh/ruff-action@v2 | |
name: Linting (ruff) | |
- uses: jpetrucciani/black-check@master | |
name: Formatting (black) | |
- uses: BSFishy/pip-action@v1 | |
with: | |
packages: | | |
pytest-md | |
pytest-emoji | |
name: Install test dependencies | |
# TODO: fix automated tests | |
# Connection from runner to test database is needed for tests to run | |
# or somehow sending a custom job to k8s that would run the tests and report back | |
- uses: pavelzw/pytest-action@v2 | |
with: | |
verbose: false | |
job-summary: true | |
continue-on-error: true | |
name: Run tests (pytest) | |
docker-build-and-push: | |
runs-on: ubuntu-latest | |
needs: app-build-and-test | |
steps: | |
- uses: actions/checkout@v4 | |
- run: | | |
TAG=$(date +%Y%m%d).${{ github.run_number }}.dev | |
echo "TAG=$TAG" >> $GITHUB_ENV | |
echo "tag=$TAG" >> $GITHUB_OUTPUT | |
name: Set tag | |
id: set-tag | |
- run: | | |
echo -e "__git_commit__ = \"${{ github.sha }}\"\n__time__ = \"$(date)\"\n__version__ = \"${{ env.TAG }}\"" > ./app/version.py | |
name: Generate version.py before building image | |
- uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
name: Login at dockerhub | |
- uses: docker/setup-qemu-action@v3 | |
name: Setup QEMU | |
- uses: docker/setup-buildx-action@v3 | |
name: Setup buildx | |
- uses: docker/build-push-action@v6 | |
with: | |
file: docker/Dockerfile | |
push: true | |
tags: worthnl/notifynl-api:${{ env.TAG }} | |
name: Docker build and push ${{ env.TAG }} | |
outputs: | |
tag: ${{ steps.set-tag.outputs.tag }} | |
helm-release: | |
runs-on: ubuntu-latest | |
needs: docker-build-and-push | |
environment: Test | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
repository: Worth-NL/notifynl-charts-private | |
ref: main | |
token: ${{ secrets.WORTHNL_PAT }} | |
name: Checkout Worth-NL/notifynl-charts-private | |
- run: echo "${{ secrets.K8S_CONFIG }}" > $HOME/.kube/config | |
name: Setup kubernetes config | |
- uses: azure/setup-helm@v1 | |
- run: helm repo add notifynl-private file://$GITHUB_WORKSPACE | |
name: Setup helm repository | |
- run: | | |
helm repo update | |
name: Update helm repository |