-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
148 additions
and
47 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
env: | ||
POETRY_VERSION: 1.7.1 | ||
GHCR_IMAGE_REPOSITORY: ghcr.io/${{ github.repository_owner }}/poetry | ||
PLATFORMS: linux/amd64,linux/arm64/v8 | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python: | ||
- "3.8" | ||
- "3.9" | ||
- "3.10" | ||
- "3.11" | ||
- "3.12" | ||
variant: | ||
- bookworm | ||
- slim | ||
steps: | ||
- uses: actions/checkout@v4.1.1 | ||
- name: Build Docker Image | ||
uses: docker/build-push-action@v5.1.0 | ||
with: | ||
context: . | ||
push: false | ||
tags: test-image | ||
target: test | ||
build-args: POETRY_VERSION=${{ env.POETRY_VERSION }} | ||
- name: Run Tests in Docker | ||
run: | | ||
docker run --rm \ | ||
-e POETRY_VERSION=${{ env.POETRY_VERSION }} \ | ||
test-image python3 /usr/src/app/tests.py | ||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Set up multiplatform builds | ||
uses: docker/setup-qemu-action@v3 | ||
with: | ||
platforms: ${{ env.PLATFORMS }} | ||
- name: Set up buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Build and Push Docker Image | ||
uses: docker/build-push-action@v5.1.0 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ env.GHCR_IMAGE_REPOSITORY }}:${{ github.sha }}-${{ matrix.python }}-${{ matrix.variant }} | ||
platforms: ${{ env.PLATFORMS }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
build-args: | | ||
POETRY_VERSION=${{ env.POETRY_VERSION }} | ||
PYTHON_VERSION=${{ matrix.python }} | ||
VARIANT=${{ matrix.variant }} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import os | ||
import re | ||
import subprocess | ||
import unittest | ||
|
||
|
||
class TestPoetrySetup(unittest.TestCase): | ||
def test_poetry_binary_available(self): | ||
""" | ||
Test if Poetry binary is available. | ||
""" | ||
|
||
result = subprocess.run(["which", "poetry"], capture_output=True, text=True) | ||
self.assertEqual(result.returncode, 0, "Poetry binary is not available in PATH") | ||
|
||
def test_poetry_version(self): | ||
""" | ||
Test if the installed Poetry version is correct. | ||
""" | ||
|
||
expected_version = os.environ.get("POETRY_VERSION") | ||
result = subprocess.run(["poetry", "--version"], capture_output=True, text=True) | ||
self.assertEqual(result.returncode, 0, "Error executing Poetry") | ||
version_match = re.search(r"Poetry \(version (\S+)\)", result.stdout) | ||
self.assertIsNotNone(version_match, "Unable to parse Poetry version") | ||
self.assertEqual( | ||
version_match.group(1), | ||
expected_version, | ||
f"Expected Poetry version {expected_version}, got {version_match.group(1)}", | ||
) | ||
|
||
def test_poetry_without_virtualenvs(self): | ||
""" | ||
Test if Poetry is configured to work without virtual environments. | ||
""" | ||
|
||
result = subprocess.run( | ||
["poetry", "config", "virtualenvs.create"], capture_output=True, text=True | ||
) | ||
self.assertEqual(result.returncode, 0, "Error executing Poetry config command") | ||
self.assertEqual( | ||
result.stdout.strip(), | ||
"false", | ||
"Poetry is not configured to work without virtual environments", | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |