Skip to content

Improved CI/CD

Improved CI/CD #3

Workflow file for this run

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"]
node-version: ["20.10.0"]
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: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
cache-dependency-path: package-lock.json
name: Install NodeJS [${{ matrix.node-version }}] and setup cache
- run: npm ci
name: Install application requirements (npm)
- 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)
- run: npm test
name: Run tests (node)
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-admin:${{ 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
- uses: bwvolleyball/k8s-toolkit@v1.0.0
with:
config: ${{ secrets.K8S_CONFIG }}
- run: |
helm version
helm upgrade --install notifynl-admin notifynl-admin/ -n ${{ secrets.K8S_NAMESPACE }} --reuse-values --set dockerTagOverride=${{ needs.docker-build-and-push.outputs.tag }} --wait
name: Deploy chart