Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved CI/CD #49

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 0 additions & 66 deletions .github/workflows/docker.yml

This file was deleted.

121 changes: 121 additions & 0 deletions .github/workflows/merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Merge tag and release

on:
push:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
# Don't want multiple builds running in parallel
cancel-in-progress: true

jobs:
docker-build-and-push:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- run: echo "TAG=$(date +%Y%m%d).${{ github.run_number }}" >> $GITHUB_ENV
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:latest,worthnl/notifynl-api:${{ env.TAG }}
name: Docker build and push ${{ env.TAG }}

- uses: mathieudutour/github-tag-action@v6.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ env.TAG }}
name: Create git tag

- uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TAG }}
make_latest: true
name: Create Github release

outputs:
tag: ${{ steps.set-tag.outputs.tag }}

helm-chart-bump:
runs-on: ubuntu-latest
needs: docker-build-and-push

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: pietrobolcato/action-read-yaml@1.0.0
with:
config: notifynl-api/Chart.yaml
name: Read Chart.yaml
id: yaml-read

- uses: olegsu/semver-action@v1
with:
version: ${{ steps.yaml-read.outputs['version'] }}
name: Chart version bump
id: version-bump

- uses: rmeneely/update-yaml@v1
with:
infile: notifynl-api/Chart.yaml
varlist: version=${{ steps.version-bump.outputs.version }},appVersion=${{ needs.docker-build-and-push.outputs.tag }}
name: Update Chart.yaml

- uses: offensive-vk/auto-commit-push@v7
with:
message: 🤖 notifynl-api chart bump
github-token: ${{ secrets.WORTHNL_PAT }}

helm-release:
runs-on: ubuntu-latest
needs: helm-chart-bump
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: |
mkdir -p $HOME/.kube
echo "${{ secrets.K8S_CONFIG }}" > $HOME/.kube/config
name: Setup kubernetes config

- uses: azure/setup-helm@v4
name: Install helm

- run: |
helm version
helm upgrade --install notifynl-api notifynl-api/ -n ${{ secrets.K8S_NAMESPACE }} --reuse-values --set dockerTagOverride=${{ needs.docker-build-and-push.outputs.tag }} --wait
name: Deploy chart
130 changes: 130 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
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

- uses: bwvolleyball/k8s-toolkit@v1.0.0
with:
config: ${{ secrets.K8S_CONFIG }}

- run: |
helm version
helm upgrade --install notifynl-api notifynl-api/ -n ${{ secrets.K8S_NAMESPACE }} --reuse-values --set dockerTagOverride=${{ needs.docker-build-and-push.outputs.tag }} --wait
name: Deploy chart
45 changes: 0 additions & 45 deletions .github/workflows/test.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ repos:
- id: check-yaml
- id: debug-statements
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.275'
rev: 'v0.8.3'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 23.10.1
rev: 24.10.0
hooks:
- id: black
name: black (python)
2 changes: 1 addition & 1 deletion app/dao/date_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_current_financial_year_start_year():


def get_financial_year_for_datetime(start_date):
if type(start_date) == date:
if type(start_date) is date:
start_date = datetime.combine(start_date, time.min)

year = int(start_date.strftime("%Y"))
Expand Down
1 change: 1 addition & 0 deletions app/history_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
session events.

"""

import datetime

from sqlalchemy import Column, Integer, Table, util
Expand Down
Loading
Loading