Skip to content
Merged
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
64 changes: 39 additions & 25 deletions .github/workflows/publish-image-to-ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ name: Build and Push Image

on:
push:
branches: [ main ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ main ]
workflow_dispatch:

env:
# Use docker.io for Docker Hub if empty
Expand All @@ -16,23 +13,41 @@ env:


jobs:
lint-and-test:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5.1.0
with:
python-version: "3.12"
- name: Install dependencies
run: make requirements
- name: Lint with flake8, pylint, and black
run: make lint
- name: Test with unittest
run: make test
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install dependencies
run: make development-requirements

- name: Lint with flake8, pylint, black, and isort
run: make lint

test:
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install dependencies
run: make development-requirements

- name: Test with unittest
run: make test

build:
needs: lint-and-test
needs: test
runs-on: ubuntu-latest

permissions:
Expand All @@ -43,18 +58,16 @@ jobs:
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v4.1.1
- uses: actions/checkout@v4

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3.1.0
uses: docker/setup-buildx-action@v3

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3.0.0
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
Expand All @@ -64,20 +77,21 @@ jobs:
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5.5.1
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,format=short,prefix=,suffix=
type=sha,format=long,prefix=,suffix=
type=ref,event=branch,prefix=,suffix=

- name: Disply metadata
run: |
cat ${{steps.meta.outputs.bake-file }}

# https://github.com/actions/upload-artifact
- name: Archive metadata
uses: actions/upload-artifact@v4.3.1
uses: actions/upload-artifact@v4
with:
name: metadata-${{ matrix.context }}.json
path: ${{steps.meta.outputs.bake-file }}
Expand All @@ -86,7 +100,7 @@ jobs:
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5.1.0
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64, linux/arm64
Expand Down
26 changes: 20 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ DOCKER_REPO = ghcr.io/managedkaos
help:
@echo "Run make <target> where target is one of the following..."
@echo
@echo " pip - install required libraries"
@echo " lint - run flake8 and pylint"
@echo " build - build docker container"
@echo " clean - stop local container, clean up workspace"
@echo " all - run requirements, lint, test, and build"
@echo " requirements - install runtime dependencies"
@echo " development-requirements - install development dependencies"
@echo " lint - run flake8, pylint, black, and isort checks"
@echo " black - format code with black"
@echo " isort - sort imports with isort"
@echo " test - run unit tests"
@echo " build - build docker container"
@echo " clean - clean up workspace and containers"

all: requirements lint test build

development-requirements: requirements
pip install --quiet --upgrade --requirement development-requirements.txt

requirements:
pip install --upgrade pip
Expand All @@ -19,14 +29,18 @@ lint:
flake8 --ignore=E501,E231 *.py
pylint --errors-only --disable=C0301 *.py
black --diff *.py
isort --check-only --diff *.py

black:
black *.py

isort:
isort *.py

test:
python -m unittest --verbose --failfast

build: pip lint
build: lint test
docker build --tag $(APP):$(TAG) .

clean:
Expand All @@ -35,4 +49,4 @@ clean:
@rm -rf ./__pycache__ ./tests/__pycache__
@rm -f .*~ *.pyc

.PHONY: build clean deploy help interactive lint pip run test unittest upload
.PHONY: help requirements lint black isort test build clean development-requirements
5 changes: 5 additions & 0 deletions development-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Development dependencies
flake8
pylint
black
isort
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[tool.black]
line-length = 88
target-version = ['py311']
include = '\.pyi?$'

[tool.isort]
profile = "black"
multi_line_output = 3
line_length = 88

[tool.pylint.messages_control]
disable = "C0111,C0103,E0401"

[tool.pylint.format]
max-line-length = 88

[tool.flake8]
max-line-length = 88
extend-ignore = ["E203", "E501", "W503", "W503"]
exclude = [".git", "__pycache__", "build", "dist"]
5 changes: 1 addition & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
flake8
pylint
black

# Runtime dependencies
1 change: 1 addition & 0 deletions test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import unittest

from script import custom_function


Expand Down