diff --git a/.github/workflows/publish-image-to-ghcr.yml b/.github/workflows/publish-image-to-ghcr.yml index 5eeb241..a7f0fc2 100644 --- a/.github/workflows/publish-image-to-ghcr.yml +++ b/.github/workflows/publish-image-to-ghcr.yml @@ -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 @@ -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: @@ -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 }} @@ -64,12 +77,13 @@ 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: | @@ -77,7 +91,7 @@ jobs: # 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 }} @@ -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 diff --git a/Makefile b/Makefile index d6ce1fc..93e1308 100644 --- a/Makefile +++ b/Makefile @@ -6,10 +6,20 @@ DOCKER_REPO = ghcr.io/managedkaos help: @echo "Run make 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 @@ -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: @@ -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 diff --git a/development-requirements.txt b/development-requirements.txt new file mode 100644 index 0000000..85072f9 --- /dev/null +++ b/development-requirements.txt @@ -0,0 +1,5 @@ +# Development dependencies +flake8 +pylint +black +isort diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d00fce3 --- /dev/null +++ b/pyproject.toml @@ -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"] diff --git a/requirements.txt b/requirements.txt index 1362987..4e33666 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1 @@ -flake8 -pylint -black - +# Runtime dependencies diff --git a/test_script.py b/test_script.py index 793479b..72a90d3 100644 --- a/test_script.py +++ b/test_script.py @@ -3,6 +3,7 @@ """ import unittest + from script import custom_function