From 4ff208f16c41d2761bf8407b236dba43a75fc18e Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Sun, 25 May 2025 15:40:01 +0000 Subject: [PATCH 01/35] Add initial implementation of foo function --- routes/v2/new_function.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 routes/v2/new_function.py diff --git a/routes/v2/new_function.py b/routes/v2/new_function.py new file mode 100644 index 0000000..9332a27 --- /dev/null +++ b/routes/v2/new_function.py @@ -0,0 +1,2 @@ +def foo(): + pass From fa4a58453869f99407e2b5f5a383c717955b3a9b Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Sun, 25 May 2025 15:41:47 +0000 Subject: [PATCH 02/35] Fix workflow trigger to ensure it only runs on the main branch for pull requests --- .github/workflows/suggest_version_bump.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/suggest_version_bump.yml b/.github/workflows/suggest_version_bump.yml index 157fb8e..581f1e1 100644 --- a/.github/workflows/suggest_version_bump.yml +++ b/.github/workflows/suggest_version_bump.yml @@ -2,6 +2,8 @@ name: Suggest Version Bump on: pull_request: + branches: + - main types: - opened - labeled From f9ccbe409ecd59591299f7ae2e9c3630203aef19 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Sun, 25 May 2025 15:43:03 +0000 Subject: [PATCH 03/35] Update workflows to trigger on push events and set permissions --- .github/workflows/enforce_correct_version_update.yml | 6 +++++- .github/workflows/suggest_version_bump.yml | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/enforce_correct_version_update.yml b/.github/workflows/enforce_correct_version_update.yml index a8f5385..019e408 100644 --- a/.github/workflows/enforce_correct_version_update.yml +++ b/.github/workflows/enforce_correct_version_update.yml @@ -1,7 +1,11 @@ name: Enforce Correct Version Update +permissions: + contents: read + statuses: write + on: - pull_request: + push: branches: - main paths: diff --git a/.github/workflows/suggest_version_bump.yml b/.github/workflows/suggest_version_bump.yml index 581f1e1..0dc9d48 100644 --- a/.github/workflows/suggest_version_bump.yml +++ b/.github/workflows/suggest_version_bump.yml @@ -1,7 +1,11 @@ name: Suggest Version Bump +permissions: + contents: read + statuses: write + on: - pull_request: + push: branches: - main types: From 9950868430ec043d134f06613ed31edc09516af3 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Sun, 25 May 2025 15:46:19 +0000 Subject: [PATCH 04/35] Remove 'master' branch from workflow triggers in devcontainer verification and super-linter --- .github/workflows/devcontainer-verification.yml | 1 - .github/workflows/enforce_correct_version_update.yml | 5 ++--- .github/workflows/suggest_version_bump.yml | 7 +------ .github/workflows/super-linter.yml | 2 -- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/.github/workflows/devcontainer-verification.yml b/.github/workflows/devcontainer-verification.yml index 0d45f9f..c5c79eb 100644 --- a/.github/workflows/devcontainer-verification.yml +++ b/.github/workflows/devcontainer-verification.yml @@ -8,7 +8,6 @@ on: push: branches: - main - - master pull_request: null jobs: diff --git a/.github/workflows/enforce_correct_version_update.yml b/.github/workflows/enforce_correct_version_update.yml index 019e408..e473a3c 100644 --- a/.github/workflows/enforce_correct_version_update.yml +++ b/.github/workflows/enforce_correct_version_update.yml @@ -10,15 +10,14 @@ on: - main paths: - '**/*.py' - paths-ignore: - - '**/tests/**' + - '!**/tests/**' jobs: version-check: runs-on: ubuntu-latest steps: - - name: Checkout repo + - name: Checkout code uses: actions/checkout@v4 - name: Detect changed version folders diff --git a/.github/workflows/suggest_version_bump.yml b/.github/workflows/suggest_version_bump.yml index 0dc9d48..3620ddd 100644 --- a/.github/workflows/suggest_version_bump.yml +++ b/.github/workflows/suggest_version_bump.yml @@ -8,11 +8,6 @@ on: push: branches: - main - types: - - opened - - labeled - - unlabeled - - synchronize paths: - '**/*.py' paths-ignore: @@ -22,7 +17,7 @@ jobs: suggest-bump: runs-on: ubuntu-latest steps: - - name: Check out PR code + - name: Checkout code uses: actions/checkout@v4 - name: Determine affected API versions diff --git a/.github/workflows/super-linter.yml b/.github/workflows/super-linter.yml index db2e48a..dba29c5 100644 --- a/.github/workflows/super-linter.yml +++ b/.github/workflows/super-linter.yml @@ -1,4 +1,3 @@ ---- name: Lint permissions: @@ -10,7 +9,6 @@ on: push: branches: - main - - master pull_request: null jobs: From c7bde402a724cc8fe5c828a847004f48510db327 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Sun, 25 May 2025 15:49:49 +0000 Subject: [PATCH 05/35] Change workflow triggers from push to pull_request for version enforcement and suggestion --- .github/workflows/enforce_correct_version_update.yml | 2 +- .github/workflows/suggest_version_bump.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/enforce_correct_version_update.yml b/.github/workflows/enforce_correct_version_update.yml index e473a3c..3c3f4a2 100644 --- a/.github/workflows/enforce_correct_version_update.yml +++ b/.github/workflows/enforce_correct_version_update.yml @@ -5,7 +5,7 @@ permissions: statuses: write on: - push: + pull_request: branches: - main paths: diff --git a/.github/workflows/suggest_version_bump.yml b/.github/workflows/suggest_version_bump.yml index 3620ddd..c4ba2d3 100644 --- a/.github/workflows/suggest_version_bump.yml +++ b/.github/workflows/suggest_version_bump.yml @@ -5,7 +5,7 @@ permissions: statuses: write on: - push: + pull_request: branches: - main paths: From 88c3789fd692b515b946563957552e85dcf1ba9f Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Sun, 25 May 2025 15:52:36 +0000 Subject: [PATCH 06/35] Implement foo function to print "bar" --- routes/v2/new_function.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/v2/new_function.py b/routes/v2/new_function.py index 9332a27..dd7266e 100644 --- a/routes/v2/new_function.py +++ b/routes/v2/new_function.py @@ -1,2 +1,2 @@ def foo(): - pass + print("bar") From 9725a3da39fdc6bdc112d49b2c5199f3bbedde56 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Sun, 25 May 2025 15:53:46 +0000 Subject: [PATCH 07/35] Update paths in suggest_version_bump workflow to use paths-ignore syntax for excluding test files --- .github/workflows/suggest_version_bump.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/suggest_version_bump.yml b/.github/workflows/suggest_version_bump.yml index c4ba2d3..4338956 100644 --- a/.github/workflows/suggest_version_bump.yml +++ b/.github/workflows/suggest_version_bump.yml @@ -10,8 +10,7 @@ on: - main paths: - '**/*.py' - paths-ignore: - - '**/tests/**' + - '!**/tests/**' jobs: suggest-bump: From 4d71f4c61a1c3160545a8da55bbc81755fb1aa42 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Sun, 25 May 2025 15:54:55 +0000 Subject: [PATCH 08/35] Remove unused foo function from new_function.py --- routes/v2/new_function.py | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 routes/v2/new_function.py diff --git a/routes/v2/new_function.py b/routes/v2/new_function.py deleted file mode 100644 index dd7266e..0000000 --- a/routes/v2/new_function.py +++ /dev/null @@ -1,2 +0,0 @@ -def foo(): - print("bar") From 6011a61eb7147a92fe922d43093befcb0ad198dd Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Sun, 25 May 2025 15:56:11 +0000 Subject: [PATCH 09/35] Add bar function to return "bar" --- routes/v2/foo.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 routes/v2/foo.py diff --git a/routes/v2/foo.py b/routes/v2/foo.py new file mode 100644 index 0000000..ee70a51 --- /dev/null +++ b/routes/v2/foo.py @@ -0,0 +1,2 @@ +def bar(): + return "bar" From 259190130006633ed9138fd6c0af8418fb14bede Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Sun, 25 May 2025 16:54:00 +0000 Subject: [PATCH 10/35] Fix quoting in workflow scripts for environment variable assignments --- .github/workflows/enforce_correct_version_update.yml | 4 ++-- .github/workflows/suggest_version_bump.yml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/enforce_correct_version_update.yml b/.github/workflows/enforce_correct_version_update.yml index 3c3f4a2..841acc4 100644 --- a/.github/workflows/enforce_correct_version_update.yml +++ b/.github/workflows/enforce_correct_version_update.yml @@ -32,7 +32,7 @@ jobs: # Extract unique version folders like v1, v2 VERSIONS=$(echo "$CHANGED" | sed -n 's|^routes/\(v[0-9]\+\)/.*|\1|p' | sort -u) echo "Detected version folders with changes: $VERSIONS" - echo "VERSIONS=$VERSIONS" >> $GITHUB_ENV + echo "VERSIONS=$VERSIONS" >> "$GITHUB_ENV" - name: Verify __version__ change per version folder if: env.VERSIONS != '' @@ -42,7 +42,7 @@ jobs: for v in $VERSIONS; do echo "➡ Checking $v" - VERSION_CHANGED=$(git diff origin/main HEAD -- routes/$v/__init__.py | grep '__version__ = ' || true) + VERSION_CHANGED=$(git diff origin/main HEAD -- "routes/$v/__init__.py" | grep '__version__ = ' || true) if [ -z "$VERSION_CHANGED" ]; then echo "🛑 Version $v was modified, but __version__ was not updated in routes/$v/__init__.py" diff --git a/.github/workflows/suggest_version_bump.yml b/.github/workflows/suggest_version_bump.yml index 4338956..ccaa1bc 100644 --- a/.github/workflows/suggest_version_bump.yml +++ b/.github/workflows/suggest_version_bump.yml @@ -24,13 +24,13 @@ jobs: run: | CHANGED_FOLDERS=$(git diff --name-only origin/main...HEAD | grep "^routes/" | cut -d/ -f2 | sort -u) echo "📁 Changed folders detected: $CHANGED_FOLDERS" - echo "folders=$CHANGED_FOLDERS" >> $GITHUB_OUTPUT + echo "folders=$CHANGED_FOLDERS" >> "$GITHUB_OUTPUT" - name: Get PR labels id: pr_labels run: | - LABELS=$(gh pr view ${{ github.event.pull_request.number }} --json labels --jq '.labels[].name') - echo "labels=$LABELS" >> $GITHUB_OUTPUT + LABELS=$(gh pr view "${{ github.event.pull_request.number }}" --json labels --jq '.labels[].name') + echo "labels=$LABELS" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ github.token }} @@ -44,7 +44,7 @@ jobs: echo "$LABELS" | grep -q 'type: refactor' && BUMP="patch" echo "$LABELS" | grep -q 'type: fix' && BUMP="patch" echo "$LABELS" | grep -q 'type: optimization' && BUMP="patch" - echo "bump=$BUMP" >> $GITHUB_OUTPUT + echo "bump=$BUMP" >> "$GITHUB_OUTPUT" echo "📁 Detected change in: ${{ steps.changed.outputs.folders }}" for folder in ${{ steps.changed.outputs.folders }}; do From c8efb37e36154296c1ca8cb0809404635b83d87f Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Sun, 25 May 2025 17:02:35 +0000 Subject: [PATCH 11/35] Add workflows for version enforcement, suggestion, and unit testing --- .../workflows/devcontainer-verification.yml | 3 + ...version_update.yml => enforce-version.yml} | 3 + ...t_version_bump.yml => suggest-version.yml} | 4 ++ .github/workflows/super-linter.yml | 3 + .github/workflows/unit_tests.yml | 61 +++++++++++++++++++ 5 files changed, 74 insertions(+) rename .github/workflows/{enforce_correct_version_update.yml => enforce-version.yml} (99%) rename .github/workflows/{suggest_version_bump.yml => suggest-version.yml} (94%) create mode 100644 .github/workflows/unit_tests.yml diff --git a/.github/workflows/devcontainer-verification.yml b/.github/workflows/devcontainer-verification.yml index c5c79eb..e57d046 100644 --- a/.github/workflows/devcontainer-verification.yml +++ b/.github/workflows/devcontainer-verification.yml @@ -1,3 +1,4 @@ +--- name: Scan Devcontainer Image permissions: @@ -19,3 +20,5 @@ jobs: image_name: devcontainer dockerfile_path: ./Dockerfile context: .devcontainer + +... diff --git a/.github/workflows/enforce_correct_version_update.yml b/.github/workflows/enforce-version.yml similarity index 99% rename from .github/workflows/enforce_correct_version_update.yml rename to .github/workflows/enforce-version.yml index 841acc4..80affec 100644 --- a/.github/workflows/enforce_correct_version_update.yml +++ b/.github/workflows/enforce-version.yml @@ -1,3 +1,4 @@ +--- name: Enforce Correct Version Update permissions: @@ -51,3 +52,5 @@ jobs: echo "✅ routes/$v/__init__.py includes a version change." fi done + +... diff --git a/.github/workflows/suggest_version_bump.yml b/.github/workflows/suggest-version.yml similarity index 94% rename from .github/workflows/suggest_version_bump.yml rename to .github/workflows/suggest-version.yml index ccaa1bc..35b5be3 100644 --- a/.github/workflows/suggest_version_bump.yml +++ b/.github/workflows/suggest-version.yml @@ -1,3 +1,5 @@ +--- +# TODO: Change the detected changes to the whole pull request, not just the last commit name: Suggest Version Bump permissions: @@ -50,3 +52,5 @@ jobs: for folder in ${{ steps.changed.outputs.folders }}; do echo "📌 Suggest bump for routes/$folder/: $BUMP" done + +... diff --git a/.github/workflows/super-linter.yml b/.github/workflows/super-linter.yml index dba29c5..53f7551 100644 --- a/.github/workflows/super-linter.yml +++ b/.github/workflows/super-linter.yml @@ -1,3 +1,4 @@ +--- name: Lint permissions: @@ -28,3 +29,5 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VALIDATE_ALL_CODEBASE: false FILTER_REGEX_EXCLUDE: "(.devcontainer/Dockerfile|.github/pull_request_template.md|.github/ISSUE_TEMPLATE/*.md)" + +... diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml new file mode 100644 index 0000000..ac98103 --- /dev/null +++ b/.github/workflows/unit_tests.yml @@ -0,0 +1,61 @@ +--- +name: Run Unit Tests + +permissions: + contents: read + +on: + push: + branches: + - main + pull_request: + +jobs: + test: + name: Pytest on ${{ matrix.os }} with Python ${{ matrix.python-version }} + runs-on: ${{ matrix.os }} + + permissions: + contents: read + packages: read + statuses: write + + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + python-version: ["3.x"] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: "pip" + + - name: Install OpenSSL (Linux) + if: runner.os == 'Linux' + run: sudo apt-get update && sudo apt-get install -y libssl-dev + + # MacOS does not require OpenSSL installation as it is pre-installed + + - name: Install OpenSSL (Windows) + if: runner.os == 'Windows' + run: choco install openssl.light --no-progress + + - name: Install dependencies + run: | + pip install -r requirements.txt + pip install pytest pytest-cov + + - name: Run Pytest (Linux/macOS) + if: runner.os != 'Windows' + run: python -m pytest --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + + - name: Run Pytest (Windows) + if: runner.os == 'Windows' + run: python -m pytest --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html + +... From ce83fe52b14748daf606e8da10d35d10d3110f0e Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Sun, 25 May 2025 17:03:42 +0000 Subject: [PATCH 12/35] Refactor workflow configurations for consistency and clarity --- .../workflows/devcontainer-verification.yml | 2 -- .github/workflows/enforce-version.yml | 2 -- .github/workflows/suggest-version.yml | 2 -- .github/workflows/super-linter.yml | 4 +--- .github/workflows/unit_tests.yml | 6 ++--- .vscode/settings.json | 22 +++++-------------- 6 files changed, 8 insertions(+), 30 deletions(-) diff --git a/.github/workflows/devcontainer-verification.yml b/.github/workflows/devcontainer-verification.yml index e57d046..725829c 100644 --- a/.github/workflows/devcontainer-verification.yml +++ b/.github/workflows/devcontainer-verification.yml @@ -20,5 +20,3 @@ jobs: image_name: devcontainer dockerfile_path: ./Dockerfile context: .devcontainer - -... diff --git a/.github/workflows/enforce-version.yml b/.github/workflows/enforce-version.yml index 80affec..1d3ca60 100644 --- a/.github/workflows/enforce-version.yml +++ b/.github/workflows/enforce-version.yml @@ -52,5 +52,3 @@ jobs: echo "✅ routes/$v/__init__.py includes a version change." fi done - -... diff --git a/.github/workflows/suggest-version.yml b/.github/workflows/suggest-version.yml index 35b5be3..967033f 100644 --- a/.github/workflows/suggest-version.yml +++ b/.github/workflows/suggest-version.yml @@ -52,5 +52,3 @@ jobs: for folder in ${{ steps.changed.outputs.folders }}; do echo "📌 Suggest bump for routes/$folder/: $BUMP" done - -... diff --git a/.github/workflows/super-linter.yml b/.github/workflows/super-linter.yml index 53f7551..5394b04 100644 --- a/.github/workflows/super-linter.yml +++ b/.github/workflows/super-linter.yml @@ -28,6 +28,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VALIDATE_ALL_CODEBASE: false - FILTER_REGEX_EXCLUDE: "(.devcontainer/Dockerfile|.github/pull_request_template.md|.github/ISSUE_TEMPLATE/*.md)" - -... + FILTER_REGEX_EXCLUDE: '(.devcontainer/Dockerfile|.github/pull_request_template.md|.github/ISSUE_TEMPLATE/*.md)' diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index ac98103..a1d367f 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ["3.x"] + python-version: ['3.x'] steps: - name: Checkout code @@ -33,7 +33,7 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - cache: "pip" + cache: 'pip' - name: Install OpenSSL (Linux) if: runner.os == 'Linux' @@ -57,5 +57,3 @@ jobs: - name: Run Pytest (Windows) if: runner.os == 'Windows' run: python -m pytest --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html - -... diff --git a/.vscode/settings.json b/.vscode/settings.json index 4ed7278..61c5bc4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,31 +10,19 @@ "**/.pytest_cache": true }, "[python]": { - "editor.rulers": [ - 88 - ], + "editor.rulers": [88], "editor.defaultFormatter": "ms-python.black-formatter", "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.organizeImports": "explicit" } }, - "isort.args": [ - "--profile", - "black" - ], + "isort.args": ["--profile", "black"], "triggerTaskOnSave.tasks": { - "Run on test file": [ - "tests/**/test_*.py" - ], - "Run all tests": [ - "!tests/**", - "**/*.py" - ] + "Run on test file": ["tests/**/test_*.py"], + "Run all tests": ["!tests/**", "**/*.py"] }, - "python.testing.pytestArgs": [ - "tests" - ], + "python.testing.pytestArgs": ["tests"], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true } From 919d2a5cc47d5be817838533a7effbb52fcf02e2 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Sun, 25 May 2025 17:06:14 +0000 Subject: [PATCH 13/35] Update suggest-version workflow to detect changed folders and restore unit tests workflow --- .github/workflows/enforce-version.yml | 10 +++++++--- .github/workflows/suggest-version.yml | 4 +++- .github/workflows/{unit_tests.yml => unit-tests.yml} | 0 3 files changed, 10 insertions(+), 4 deletions(-) rename .github/workflows/{unit_tests.yml => unit-tests.yml} (100%) diff --git a/.github/workflows/enforce-version.yml b/.github/workflows/enforce-version.yml index 1d3ca60..8073dc4 100644 --- a/.github/workflows/enforce-version.yml +++ b/.github/workflows/enforce-version.yml @@ -25,13 +25,17 @@ jobs: id: detect run: | echo "🔍 Checking changed versioned folders..." - CHANGED=$(git diff --name-only origin/main HEAD | grep '^routes/v[0-9]\+/.*\.py$' | grep -v 'test' || true) + + git fetch origin main + BASE_SHA=$(git merge-base HEAD origin/main) + + CHANGED=$(git diff --name-only "$BASE_SHA"...HEAD | grep '^routes/v[0-9]\+/.*\.py$' | grep -v 'test' || true) echo "Changed files:" echo "$CHANGED" # Extract unique version folders like v1, v2 - VERSIONS=$(echo "$CHANGED" | sed -n 's|^routes/\(v[0-9]\+\)/.*|\1|p' | sort -u) + VERSIONS=$(echo "$CHANGED" | sed -n 's|^routes/\(v[0-9]\+\)/.*|\1|p' | sort -u | tr '\n' ' ') echo "Detected version folders with changes: $VERSIONS" echo "VERSIONS=$VERSIONS" >> "$GITHUB_ENV" @@ -43,7 +47,7 @@ jobs: for v in $VERSIONS; do echo "➡ Checking $v" - VERSION_CHANGED=$(git diff origin/main HEAD -- "routes/$v/__init__.py" | grep '__version__ = ' || true) + VERSION_CHANGED=$(git diff "$BASE_SHA"...HEAD -- "routes/$v/__init__.py" | grep '__version__ = ' || true) if [ -z "$VERSION_CHANGED" ]; then echo "🛑 Version $v was modified, but __version__ was not updated in routes/$v/__init__.py" diff --git a/.github/workflows/suggest-version.yml b/.github/workflows/suggest-version.yml index 967033f..17ea80e 100644 --- a/.github/workflows/suggest-version.yml +++ b/.github/workflows/suggest-version.yml @@ -24,7 +24,9 @@ jobs: - name: Determine affected API versions id: changed run: | - CHANGED_FOLDERS=$(git diff --name-only origin/main...HEAD | grep "^routes/" | cut -d/ -f2 | sort -u) + git fetch origin main + BASE_SHA=$(git merge-base HEAD origin/main) + CHANGED_FOLDERS=$(git diff --name-only "$BASE_SHA"...HEAD | grep "^routes/" | cut -d/ -f2 | sort -u | tr '\n' ' ') echo "📁 Changed folders detected: $CHANGED_FOLDERS" echo "folders=$CHANGED_FOLDERS" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit-tests.yml similarity index 100% rename from .github/workflows/unit_tests.yml rename to .github/workflows/unit-tests.yml From 0828819c72217b5dd34be22ba1297bbf0f6718d2 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Sun, 25 May 2025 17:10:25 +0000 Subject: [PATCH 14/35] Set fetch-depth to 0 for checkout steps in version enforcement and suggestion workflows --- .github/workflows/enforce-version.yml | 2 ++ .github/workflows/suggest-version.yml | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/enforce-version.yml b/.github/workflows/enforce-version.yml index 8073dc4..eb85b6e 100644 --- a/.github/workflows/enforce-version.yml +++ b/.github/workflows/enforce-version.yml @@ -20,6 +20,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Detect changed version folders id: detect diff --git a/.github/workflows/suggest-version.yml b/.github/workflows/suggest-version.yml index 17ea80e..be33bec 100644 --- a/.github/workflows/suggest-version.yml +++ b/.github/workflows/suggest-version.yml @@ -1,5 +1,4 @@ --- -# TODO: Change the detected changes to the whole pull request, not just the last commit name: Suggest Version Bump permissions: @@ -20,6 +19,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Determine affected API versions id: changed From bc1efe6fb1fb8c955fc912baa36a339d270022f4 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Sun, 25 May 2025 17:14:36 +0000 Subject: [PATCH 15/35] Add job summary reporting for suggested version bumps --- .github/workflows/suggest-version.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/suggest-version.yml b/.github/workflows/suggest-version.yml index be33bec..7344e35 100644 --- a/.github/workflows/suggest-version.yml +++ b/.github/workflows/suggest-version.yml @@ -55,3 +55,13 @@ jobs: for folder in ${{ steps.changed.outputs.folders }}; do echo "📌 Suggest bump for routes/$folder/: $BUMP" done + + - name: Report in job summary + if: steps.changed.outputs.folders != '' + run: | + { + echo "### 🚀 Suggested Version Bumps" + for folder in ${{ steps.changed.outputs.folders }}; do + echo "- \`routes/$folder/\`: **${{ steps.bump.outputs.bump }}**" + done + } >> $GITHUB_STEP_SUMMARY From 3e3229d0f2eb82681f104d92c2db90697c173631 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Sun, 25 May 2025 17:16:19 +0000 Subject: [PATCH 16/35] Fix pull_request trigger to prevent unintended workflow runs --- .github/workflows/unit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index a1d367f..c413385 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -8,7 +8,7 @@ on: push: branches: - main - pull_request: + pull_request: null jobs: test: From ffbe8035927bc67bebfb38db3b01f678871c26e0 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 11:24:12 +0000 Subject: [PATCH 17/35] Fix quoting for GITHUB_STEP_SUMMARY in suggest-version workflow --- .github/workflows/suggest-version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/suggest-version.yml b/.github/workflows/suggest-version.yml index 7344e35..fb186a0 100644 --- a/.github/workflows/suggest-version.yml +++ b/.github/workflows/suggest-version.yml @@ -64,4 +64,4 @@ jobs: for folder in ${{ steps.changed.outputs.folders }}; do echo "- \`routes/$folder/\`: **${{ steps.bump.outputs.bump }}**" done - } >> $GITHUB_STEP_SUMMARY + } >> "$GITHUB_STEP_SUMMARY" From 2ce0ffeb8a0fc7725395a7420f631bc64a51fe58 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 11:27:03 +0000 Subject: [PATCH 18/35] Remove unused bar function from foo.py --- routes/v2/foo.py | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 routes/v2/foo.py diff --git a/routes/v2/foo.py b/routes/v2/foo.py deleted file mode 100644 index ee70a51..0000000 --- a/routes/v2/foo.py +++ /dev/null @@ -1,2 +0,0 @@ -def bar(): - return "bar" From bde7fa9eab262809dc7acc1f2848268b3e496fba Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 12:55:08 +0000 Subject: [PATCH 19/35] Refactor API structure and update dependencies; remove unused files and add Docker support --- .github/workflows/unit-tests.yml | 2 +- .gitignore | 187 ++++++++++++++++++ .vscode/settings.json | 3 +- .vscode/tasks.json | 24 ++- Dockerfile | 18 ++ LICENSE | 2 +- __pycache__/main.cpython-312.pyc | Bin 692 -> 721 bytes main.py => app/main.py | 10 +- {routes => app/routes}/__init__.py | 0 {routes => app/routes}/home.py | 0 {routes => app/routes}/v1/__init__.py | 0 {routes => app/routes}/v1/orders.py | 0 {routes => app/routes}/v1/products.py | 0 {routes => app/routes}/v2/__init__.py | 0 {tests => app/tests}/test_home.py | 2 +- {utility => app/utility}/test.py | 0 pyproject.toml | 6 + routes/__pycache__/__init__.cpython-312.pyc | Bin 131 -> 0 bytes routes/__pycache__/home.cpython-312.pyc | Bin 460 -> 0 bytes .../v1/__pycache__/__init__.cpython-312.pyc | Bin 580 -> 0 bytes routes/v1/__pycache__/orders.cpython-312.pyc | Bin 1010 -> 0 bytes .../v1/__pycache__/products.cpython-312.pyc | Bin 1074 -> 0 bytes .../v2/__pycache__/__init__.cpython-312.pyc | Bin 282 -> 0 bytes routes/v2/__pycache__/orders.cpython-312.pyc | Bin 734 -> 0 bytes .../v2/__pycache__/products.cpython-312.pyc | Bin 666 -> 0 bytes setup.py | 46 +++++ .../test_home.cpython-312-pytest-8.3.5.pyc | Bin 2163 -> 0 bytes 27 files changed, 288 insertions(+), 12 deletions(-) create mode 100644 Dockerfile rename main.py => app/main.py (89%) rename {routes => app/routes}/__init__.py (100%) rename {routes => app/routes}/home.py (100%) rename {routes => app/routes}/v1/__init__.py (100%) rename {routes => app/routes}/v1/orders.py (100%) rename {routes => app/routes}/v1/products.py (100%) rename {routes => app/routes}/v2/__init__.py (100%) rename {tests => app/tests}/test_home.py (90%) rename {utility => app/utility}/test.py (100%) create mode 100644 pyproject.toml delete mode 100644 routes/__pycache__/__init__.cpython-312.pyc delete mode 100644 routes/__pycache__/home.cpython-312.pyc delete mode 100644 routes/v1/__pycache__/__init__.cpython-312.pyc delete mode 100644 routes/v1/__pycache__/orders.cpython-312.pyc delete mode 100644 routes/v1/__pycache__/products.cpython-312.pyc delete mode 100644 routes/v2/__pycache__/__init__.cpython-312.pyc delete mode 100644 routes/v2/__pycache__/orders.cpython-312.pyc delete mode 100644 routes/v2/__pycache__/products.cpython-312.pyc create mode 100644 setup.py delete mode 100644 tests/__pycache__/test_home.cpython-312-pytest-8.3.5.pyc diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index c413385..5080f60 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ['3.x'] + python-version: ['3.12.10', '3.x'] steps: - name: Checkout code diff --git a/.gitignore b/.gitignore index 4c49bd7..1ad4462 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,188 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +#uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments .env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +# Visual Studio Code +# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore +# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore +# and can be added to the global gitignore or merged into this file. However, if you prefer, +# you could uncomment the following to ignore the enitre vscode folder +# .vscode/ + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc + +# Cursor +# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to +# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data +# refer to https://docs.cursor.com/context/ignore-files +.cursorignore +.cursorindexingignore diff --git a/.vscode/settings.json b/.vscode/settings.json index 61c5bc4..000bbd4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,9 +20,8 @@ "isort.args": ["--profile", "black"], "triggerTaskOnSave.tasks": { "Run on test file": ["tests/**/test_*.py"], - "Run all tests": ["!tests/**", "**/*.py"] + "Run all tests": ["app/**/*.py", "!tests/**"] }, - "python.testing.pytestArgs": ["tests"], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true } diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c3c6322..ae8d245 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -4,11 +4,8 @@ { "label": "Run all tests", "type": "shell", - "command": "python3 -m pytest tests", - "group": { - "kind": "test", - "isDefault": true - }, + "command": "python3 -m pytest app/tests", + "group": "build", "problemMatcher": [], "runOptions": { "runOn": "default" @@ -38,6 +35,23 @@ "panel": "dedicated", "close": true } + }, + { + "label": "Package app", + "type": "shell", + "command": "python setup.py egg_info --egg-base .", + "problemMatcher": [], + "runOptions": { + "runOn": "default" + }, + "presentation": { + "panel": "dedicated", + "close": true + }, + "group": { + "kind": "build", + "isDefault": true + } } ] } diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e598bd9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3.12.10-alpine3.21 + +# Create a user to run the app securely +WORKDIR /app + +# Copy package and dependencies +COPY pyproject.toml ./ +COPY app/* ./ + +# Install app dependencies as the apiuser +RUN pip install --no-cache-dir . + +# Use non-root user +USER apiuser + +EXPOSE 8000 + +CMD ["python3", "main.py"] diff --git a/LICENSE b/LICENSE index 2a88561..aec0d6a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) +Copyright (c) 2025 ChocoMax Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/__pycache__/main.cpython-312.pyc b/__pycache__/main.cpython-312.pyc index 88ab43aa5fe3954fb40229167cc7c06bec761d32..f74f6e74ce0d6405962c4f22d2e4ef080d98f3cb 100644 GIT binary patch delta 303 zcmdnOdXbg)G%qg~0}z~#GRfFFkyn!O!$ft{`V^KZE+&Rl#uU~yY^xbT@(c`7+^O7I zk`OjBnaToF!N>qqA&o2tVW+UCvae=>uyLy4Nacj9ab!s4OX1AcU|=YcOkqgj%HfaV z2Res8O96}F+$lV3c;Q+ZD!D4TH2Ee=FeD+{qZo!yO-AmReMt znV%OQKlvtOys{L~JdpQ_^MS+%W=2NFyA0A#8FcS5$OF*>KG6p5$ze=UED}Iz0C@E- AzyJUM delta 247 zcmcb}x`mbZG%qg~0}wPw7-!6x$ScYCW}>>O7!yM(V+zX}*42z4IR=I(u2ilp@rh;f z^;}t!5FunTg)NnRH4{XHkpZX_n;Q01P9!zFDID1v3=Bn*DGVu`IebxkKr8vO=61"] +build-backend = "setuptools.build_meta" + +[tool.pytest.ini_options] +pythonpath = ["app"] diff --git a/routes/__pycache__/__init__.cpython-312.pyc b/routes/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index 14518c0901d6192e12991b8961b17897ed7a8ec1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 131 zcmX@j%ge<81O+_C86f&Gh(HIQS%4zb87dhx8U0o=6fpsLpFwJVDe0Hz7iAY0Bqpa8 z>pKQ`>KEmgmH?UY@tJv83YAgy!AJf z{Tbc52;CNfqEk1+Tc>7M&4F)z&o|%e?CcDXy`(q1CyHNTF)@9d42zUJfD10xp@C&Y zV8F3A9+w$sr{?5n8eQgUReaWaY}9jOH}HR>w~eg%9S*V>Bz6z?i=yRo8K52Ld!oUq ztNTt>Ri=DEUja12Fw{(f&}B6&K~^gSW`ir`RQZ*4#OoCzuzX?p9=GzIsE7mS(kgkP zY0;xckcp6k0KY5tg^*{e=~TF~X=uw(hO#|kSZlU}gyfEUEQRo8iuMhHnj_bNkJLhc zakHPy_4S+#^%SzPz&vr3?=)*NR2di%nGCclADu^!qh*;47vkFu;kN30N2aMnf?6jx r&=Bz*mOm5o_e&jPU;vBXX09`L`R;kw>tx<=^@kyD4K-j^ltr9>!cu2= diff --git a/routes/v1/__pycache__/__init__.cpython-312.pyc b/routes/v1/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index d976ab1c92639e27bac3f38a2c75441b22a442b5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 580 zcmZ`#OG_g`5U!rd^h^>HFyiCj!ONmqA)|PefCvkMkASziG();IvpdNQJ(H+8`4c<{ z{sl!3d(40EqM#@Zf+8L~EG)=g_Ovz0MDeh7==!SqtFIoHg+dO{e$6d4It1W335I5* z;O!W}32@-VhbD0d0j_b~*P6PMNwI;LBF;Fb27+)ym>2Y18z?xIu)dECWk0;2+~n3S zxyYXDgDipnFf%;I^PiaqBjv(tQdTC){N_gSN^R{GcSvF?gLW)r*I2A9R2I6UtBs%@ zY`FU~+l?TcL1I}`M(oADP-aKS$O~HCtR2dLx9f4FtXhhYMnfrfynU64-QB2b+JWR) zpy*cLZ*sDH{Id8B51tOzEhlie9Vkx4B3e zXYhu4@b`8N@--*bBFS5Ufvwfpz<@@cj= O)yrY}7FOjriv9z8Z=Lo4 diff --git a/routes/v1/__pycache__/orders.cpython-312.pyc b/routes/v1/__pycache__/orders.cpython-312.pyc deleted file mode 100644 index 0022e5616f14b3d18061fc010d65f09123c33ef9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1010 zcmZWoOKTHR6uvXlye3H>=_@AbLt2!GZQA<4g_O4G!WIl^v+E`dbFRr~GBe(}sWhvI zf`UJwoBjdmAMhs#BDA}3K~Qv)T}pPYJa^KxU@zP|=gjvw=gwii#p61`H8TC6Iujt| zw@d~rdKvV-U~o);fKnrMx0N~m&r2_LASf(AnnfFOh*43QHJPaQLiDk?-F2Jw>+ z48sVF!WblA9Jj<2n1D$iQxThjY2U%u`7GZH9g=;Aigut;^<`wx;Pn%3ohtndQt!!C zXMv-1Hq((nRuPfS;?BO);FLAPyH3@f-*#wIUt3vww6yYYY2|Szjyw@6RV~-0(2;)4 z;bMc)`FzzeotnXEN0nBZ&|T(0!{lWPL~Ib-MxBcA>xN--iyt);&x|Im*$sXzub`Tc z*4BoI`F(&7tQe^H4S^daI;%d z*bt#2wLx;*QXJW)HS3Tv3YYiU*$_(3MCfYCZzp|w!+0DMeg%|p5Cxn?(7%QEne-&| zcOm!2VXr*bz@~CIrW})V@^Xi(xju2(Jra6_@^U|AbEvwH+Y8~*B7dS|t>Y*qr{r*)iYjjpo=OlAMxcRae9q9{Me%&$n| zQ@R!GhDmC%J(_7xOtq7@f2K2M%j;h^&trwQ47bjTd*`wJZa_=u$V_J1v)PNuXdu{4 zk<^`mY|)qH&-V7uW2LU9A~)!B?_P}S$W0DPOt+H@|CboZZkAYG)KzS-fd6LrL+Wkn UWB%RTg{mlto<`I$Kk~2p4<~*Tz5oCK diff --git a/routes/v1/__pycache__/products.cpython-312.pyc b/routes/v1/__pycache__/products.cpython-312.pyc deleted file mode 100644 index d7a73c9cd328d2307e032a7dc6c9c083576edf7d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1074 zcmZ`&&2G~`5Z-lS*GZGmByE$Xqz%7npfo@cToAZQ4{&Ix;DFRiwRpCT!HJ`_)2cZI zfdmpKPQCB~sIR~q@B)z~gb-YOOO+cZb{(e#Ijm&+o0)Gu&yW2znT#WTvbpv8M;W1? z!Wf-o00v(;I7WZ~o2Y?zFh&xh_#_DLNFYH3q9B9vDGF1dLM*^>n1)1vlaPXQ0iJ<0 zWFYJFXJHQJ1Ah+kun^z^EW&vx`kW1AwGl5&L0flr z4R8}9+$0U^$}MK-)KzSUIBnaLgl6Uu=}@!Tc0#&qnimm_>^9X&vs9ZvxubbeL7CYw z8&(rS5-Xa=*Tf~Zh)#es3=*Q;)?9g$kv+##e5ER}>+~>0Th+X&VKD};UauQgh;mo+ zRA1sbnb^-w%}s0?wr({YquHk5iLG?fRX)v0?XPPtuIQX{cEk?ELiq`)AWZszEpbzH zVSnehegtFu4HbXHG9MPZN?%2}d@sM!OV9N(#nYH9EB%!3S`E8ygk9Idt|4n-Tbt`0!u#r*gc*+B$JX&?Cm_ygv459R;> diff --git a/routes/v2/__pycache__/__init__.cpython-312.pyc b/routes/v2/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index e27ff23b4e69fa9083da4866bcb29ca96ef241fd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 282 zcmX@j%ge<81cI8z89hMyF^B^LEKtU04IpDWLkdF*V-7PS#GhX0re#oWEL?4&AG)L9}ks_kH5tX6kf^j8DzmP zRsHh(qU_>=#N^aseV}3bMfs&AKxUbdetdjpUS>&ryk0@&Ee@O9{FKt1RJ$S`pe{xr pE|vijAD9^#8NaeIFv>jO6K&vr$i{m?Onrm)6*jv@<|0s#002+HNPhqT diff --git a/routes/v2/__pycache__/orders.cpython-312.pyc b/routes/v2/__pycache__/orders.cpython-312.pyc deleted file mode 100644 index ea0cb0e193fbf542b9252ae259f814c484aa6d71..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 734 zcmYLFO>fgc5Z$#K+i~L3M6?ZQ3PJSZL+dDfoKQs@4uC`y+FLG>m;M3NKZ3-iy+tb_f#8x`s@ym+b`n@=$M1ROy_ubFhM^-krOms&9SNad30a=( z0?bYToFak<_D~5te)Z?BThLlVazu{^tX0+Pq1y11EoKE0@$drX1vVg=6@3=(dm)N)aRA_Hv+vhGH z42w_fA@%&2|Ce_`jnL@uk;pcJe&|t7iKz<1i6b8LDeI&bD+D?TEno!xBn{>$;x>;X zkx7}z@qpW2CuFWeMUgYxk8Fp#f!|rwVarLoEkg1d8SZQq!YSg5-v}MUYMQVeCH0NI zpjndobH{ocu-8#&J2bLjaTZH97g;BDYhJh)4usyNyfdfl2B_BIMk<66`kgC`p0iEB zO;Zu-OB==tU6za>l+=r{q+H10k&4*{&{V-nNkV(rhaG!#pKSw8=8s$mQyF9Y9c};2 z7C&!|l&OZwJL9#=`1;1Ubo<9v%nEdIZoi=MeD_7{%D$!i#k-6D&w2x)p{f3D9n@KRSF&0ee zELSm1CuB_*>?cEfG+#WGw=mQyq9b&3gAno!w!S;{PtA!nw_$x_x^aJ6yE(0IT{)&{ q&8ul@=X&bFzo}-UOegky2dI6v`C;>X|Kpu2O300c0koE)l+16uB%S;K diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..b7afb74 --- /dev/null +++ b/setup.py @@ -0,0 +1,46 @@ +from setuptools import find_packages, setup + + +# Read the Python version from Dockerfile +def get_python_version(): + with open("Dockerfile", encoding="utf-8") as f: + for line in f: + if line.startswith("FROM python:"): + return line.split(":")[1].split("-")[0].strip() + raise RuntimeError("Version not found.") + + +# Read the app version from the main module +def get_app_version(): + with open("app/main.py", encoding="utf-8") as f: + for line in f: + if line.startswith("__version__"): + return line.split("=")[1].strip().strip('"').strip("'") + raise RuntimeError("App version not found in app.main module.") + + +setup( + name="chocomax-api", + version=get_app_version() or "draft", + url="https://github.com/TheChocoMax/API", + description="ChocoMax API", + author="Vianpyro", + packages=find_packages(where="app", exclude=["tests*"]), + package_dir={"": "app"}, + include_package_data=True, + install_requires=[ + "fastapi", + "uvicorn[standard]", + ], + python_requires=f">={get_python_version()}", + classifiers=[ + "Programming Language :: Python :: 3", + "Framework :: FastAPI", + "License :: OSI Approved :: MIT License", + ], + entry_points={ + "console_scripts": [ + "chocomax-api=main:main", + ], + }, +) diff --git a/tests/__pycache__/test_home.cpython-312-pytest-8.3.5.pyc b/tests/__pycache__/test_home.cpython-312-pytest-8.3.5.pyc deleted file mode 100644 index 9beef8dc4d855d8d851174c60013a82f33889204..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2163 zcmds2L2KMb6rPc^((cN3k~%5vrMtAmwR-R-S-VM~+ccO$3$ZD*P}qx5R;$Q3( z8Qs+%suLY*qPd1!j9P5!9=}Cu-$Y4JdBA?tL13F}iHUGm7sj{AhDxB1DUD~-b54E&+?yNf( zm9kEj|8pnH(v#%HPC_@0SRW(n)H=tFXFozGE&N<*wJbboo?i^cmn>HOG6VHiU7!mV zTVkOTZZf;$yQCV|Tj|7##dw(#7WgAZES0NZE6625Rwi=}V}yo@kIP^R%FEms62_bj zGO2$~ypBI4_0X?}JyKuo`5k}F*{Xlq^Mm^JPdRz>(_nGt|2qkl+p!2D4)UbONI zA*`iQaYa(`!HX1@=`5g^lDnEFch#EVdMCNdxVk|?ZWeaUs~-g85H360q5O>9aXina zB%rW`z@dcCz_fjHv+srd5#ze&g9YQS*{tVpdTwHBZ+QMq$FoPyknoDloGuX__}ulR zPJMs$A*DX$^LE##LnpM!R^T}!CxjWUiOpFRS`phYMXg(O2aHVLL z&7|H|(tV_BE?!_FT3wFkZ#HiG^cD-84q*-GP(##%CDiUgE0=;XuOu}R5?z4B;)7@K zl%Q?&+o^N+COeY{Z|#1y{n4-H{E=BZFl+nT!lNdTeY5tcd0;LaY2tU7DN<=l54455 zS5oOo4xc8*srs>SH?^Mvu!e~DT05ES}`>DZo~$eJs{ZA$Ux2k^Z8s9YaMBoV2n$EL2>q{B=7$UQ1~spyf-H z+@}2yj>=TUjZ8>b Date: Mon, 26 May 2025 12:57:16 +0000 Subject: [PATCH 20/35] Update .gitignore to include .pyc files and remove compiled Python bytecode --- .gitignore | 1 + __pycache__/main.cpython-312.pyc | Bin 721 -> 0 bytes 2 files changed, 1 insertion(+) delete mode 100644 __pycache__/main.cpython-312.pyc diff --git a/.gitignore b/.gitignore index 1ad4462..1cc48e5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ __pycache__/ *.py[cod] *$py.class +*.pyc # C extensions *.so diff --git a/__pycache__/main.cpython-312.pyc b/__pycache__/main.cpython-312.pyc deleted file mode 100644 index f74f6e74ce0d6405962c4f22d2e4ef080d98f3cb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 721 zcmZ{hy>HV%7{=d=zhavtY6PNbhi0Q0NSdeCm}?{Aw+U6%teZ$&R7YxNOz0{=aEfh)vZaq%ZQfBIaiyz0EgJC!acHxJ?y8$Qf+@ zgzIOpg=R h4?ZcCZ)$m>mWKC__73+(*6ZER>h{zCb%U?t%s-j0vcUiV From f0aa7bbecb97dfc8df0fbc6fab36672acae96b46 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 13:26:12 +0000 Subject: [PATCH 21/35] Update Python version to 3.13 in Dockerfile and unit-tests.yml; refactor requirements handling in setup.py --- .github/workflows/unit-tests.yml | 2 +- Dockerfile | 13 +++++++++++-- setup.py | 12 +++++++----- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 5080f60..9b4d830 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ['3.12.10', '3.x'] + python-version: ['3.13', '3.x'] steps: - name: Checkout code diff --git a/Dockerfile b/Dockerfile index e598bd9..5e4859d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,14 @@ -FROM python:3.12.10-alpine3.21 +FROM python:3.13-alpine3.21 # Create a user to run the app securely WORKDIR /app +# Install dependencies +RUN apt-get update && apt-get install -y --no-install-recommends curl openssl \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + # Copy package and dependencies -COPY pyproject.toml ./ +COPY requirements.txt . COPY app/* ./ # Install app dependencies as the apiuser @@ -13,6 +17,11 @@ RUN pip install --no-cache-dir . # Use non-root user USER apiuser +# Expose the FastAPI port EXPOSE 8000 +# Add healthcheck for the container +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD curl --fail http://localhost:8000/ || exit 1 + CMD ["python3", "main.py"] diff --git a/setup.py b/setup.py index b7afb74..0d2e2a2 100644 --- a/setup.py +++ b/setup.py @@ -19,19 +19,21 @@ def get_app_version(): raise RuntimeError("App version not found in app.main module.") +def get_requirements(): + with open("requirements.txt", encoding="utf-8") as f: + return [line.strip() for line in f if line.strip() and not line.startswith("#")] + + setup( name="chocomax-api", - version=get_app_version() or "draft", + version=get_app_version(), url="https://github.com/TheChocoMax/API", description="ChocoMax API", author="Vianpyro", packages=find_packages(where="app", exclude=["tests*"]), package_dir={"": "app"}, include_package_data=True, - install_requires=[ - "fastapi", - "uvicorn[standard]", - ], + install_requires=get_requirements(), python_requires=f">={get_python_version()}", classifiers=[ "Programming Language :: Python :: 3", From c008aee6204f88ae7dacd33f33ecc51a4d132cff Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 13:40:48 +0000 Subject: [PATCH 22/35] Add docstrings to main API files and enhance test coverage for home endpoint --- app/main.py | 5 +++++ app/routes/home.py | 8 +++++++- app/routes/v1/__init__.py | 4 +--- app/routes/v1/orders.py | 5 +++++ app/routes/v1/products.py | 5 +++++ app/routes/v2/__init__.py | 2 +- setup.py | 7 +++++++ {app/tests => tests}/test_home.py | 7 ++++++- 8 files changed, 37 insertions(+), 6 deletions(-) rename {app/tests => tests}/test_home.py (72%) diff --git a/app/main.py b/app/main.py index 472f260..b8b49eb 100644 --- a/app/main.py +++ b/app/main.py @@ -1,3 +1,8 @@ +""" +This is the main entry point for the API application. +It sets up the FastAPI application, includes the home router, and mounts versioned APIs. +""" + from fastapi import FastAPI from routes.home import router as home_router from routes.v1 import api as v1 diff --git a/app/routes/home.py b/app/routes/home.py index 1962be8..05ac404 100644 --- a/app/routes/home.py +++ b/app/routes/home.py @@ -1,3 +1,8 @@ +""" +This is the main entry point for the API. +It sets up the home router and defines the root endpoint. +""" + from fastapi import APIRouter router = APIRouter() @@ -5,4 +10,5 @@ @router.get("/", tags=["Home"]) def read_root(): - return {"message": "Welcome to the ChocoMax Shop API"} + """Root endpoint that returns a welcome message.""" + return {"message": "Welcome to the ChocoMax Shop API!"} diff --git a/app/routes/v1/__init__.py b/app/routes/v1/__init__.py index 82b9bc5..89fffea 100644 --- a/app/routes/v1/__init__.py +++ b/app/routes/v1/__init__.py @@ -1,5 +1,3 @@ -# routes/v1/__init__.py - from fastapi import FastAPI from .orders import router as order_router @@ -7,7 +5,7 @@ __version__ = "1.0.0" -api = FastAPI(title=f"ChocoMax Shop API", version=__version__) +api = FastAPI(title="ChocoMax Shop API", version=__version__) api.include_router(product_router, prefix="/products", tags=["Products"]) api.include_router(order_router, prefix="/orders", tags=["Orders"]) diff --git a/app/routes/v1/orders.py b/app/routes/v1/orders.py index ee93497..dab208d 100644 --- a/app/routes/v1/orders.py +++ b/app/routes/v1/orders.py @@ -1,3 +1,7 @@ +""" +This module defines the API routes for order management. +""" + from fastapi import APIRouter router = APIRouter() @@ -43,4 +47,5 @@ @router.get("/") def get_orders(): + """Retrieve all orders.""" return orders diff --git a/app/routes/v1/products.py b/app/routes/v1/products.py index 6eb70ee..f323509 100644 --- a/app/routes/v1/products.py +++ b/app/routes/v1/products.py @@ -1,3 +1,7 @@ +""" +This module defines the API routes for managing products. +""" + from fastapi import APIRouter router = APIRouter() @@ -62,4 +66,5 @@ @router.get("/") def get_products(): + """Retrieve a list of all products.""" return products diff --git a/app/routes/v2/__init__.py b/app/routes/v2/__init__.py index 211c0ed..ee88288 100644 --- a/app/routes/v2/__init__.py +++ b/app/routes/v2/__init__.py @@ -4,4 +4,4 @@ __version__ = "2.0.0" -api = FastAPI(title=f"ChocoMax Shop API", version=__version__) +api = FastAPI(title="ChocoMax Shop API", version=__version__) diff --git a/setup.py b/setup.py index 0d2e2a2..0f22516 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,10 @@ +""" +Package setup script for the API. +This script is used to package the API application for distribution. +It reads the Python version from the Dockerfile and the application version from the main module. +It also reads the requirements from a requirements.txt file and sets up the package metadata. +""" + from setuptools import find_packages, setup diff --git a/app/tests/test_home.py b/tests/test_home.py similarity index 72% rename from app/tests/test_home.py rename to tests/test_home.py index dd6ebbc..75fbedc 100644 --- a/app/tests/test_home.py +++ b/tests/test_home.py @@ -1,3 +1,7 @@ +""" +Test the home endpoint of the API. +""" + from fastapi.testclient import TestClient from app.main import app @@ -6,6 +10,7 @@ def test_home(): + """Test the home endpoint.""" response = client.get("/") assert response.status_code == 200 - assert response.json() == {"message": "Welcome to the ChocoMax Shop API"} + assert response.json() == {"message": "Welcome to the ChocoMax Shop API!"} From 5361a61b0b92c3d6a045c22c3946306bfe9518b5 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 13:46:35 +0000 Subject: [PATCH 23/35] Enhance documentation and improve linter configuration; update test command and add docstrings --- .github/workflows/super-linter.yml | 2 ++ .vscode/tasks.json | 2 +- app/routes/__init__.py | 3 +++ app/routes/v1/__init__.py | 4 ++++ setup.py | 3 +++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/super-linter.yml b/.github/workflows/super-linter.yml index 5394b04..f0f2356 100644 --- a/.github/workflows/super-linter.yml +++ b/.github/workflows/super-linter.yml @@ -29,3 +29,5 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} VALIDATE_ALL_CODEBASE: false FILTER_REGEX_EXCLUDE: '(.devcontainer/Dockerfile|.github/pull_request_template.md|.github/ISSUE_TEMPLATE/*.md)' + VALIDATE_PYTHON_ISORT: false + VALIDATE_PYTHON_MYPY: false diff --git a/.vscode/tasks.json b/.vscode/tasks.json index ae8d245..4eaebd1 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -4,7 +4,7 @@ { "label": "Run all tests", "type": "shell", - "command": "python3 -m pytest app/tests", + "command": "python3 -m pytest tests", "group": "build", "problemMatcher": [], "runOptions": { diff --git a/app/routes/__init__.py b/app/routes/__init__.py index e69de29..1fb5f66 100644 --- a/app/routes/__init__.py +++ b/app/routes/__init__.py @@ -0,0 +1,3 @@ +""" +Base module for the API version 2 routes. +""" diff --git a/app/routes/v1/__init__.py b/app/routes/v1/__init__.py index 89fffea..d025933 100644 --- a/app/routes/v1/__init__.py +++ b/app/routes/v1/__init__.py @@ -1,3 +1,7 @@ +""" +Base module for the API version 1 routes. +""" + from fastapi import FastAPI from .orders import router as order_router diff --git a/setup.py b/setup.py index 0f22516..28b57c1 100644 --- a/setup.py +++ b/setup.py @@ -10,6 +10,7 @@ # Read the Python version from Dockerfile def get_python_version(): + """Retrieve the Python version from the Dockerfile.""" with open("Dockerfile", encoding="utf-8") as f: for line in f: if line.startswith("FROM python:"): @@ -19,6 +20,7 @@ def get_python_version(): # Read the app version from the main module def get_app_version(): + """Retrieve the application version from the main module.""" with open("app/main.py", encoding="utf-8") as f: for line in f: if line.startswith("__version__"): @@ -27,6 +29,7 @@ def get_app_version(): def get_requirements(): + """Retrieve the requirements from the requirements.txt file.""" with open("requirements.txt", encoding="utf-8") as f: return [line.strip() for line in f if line.strip() and not line.startswith("#")] From 2efc8e2ff8dd16a47ae57ce8e114f69a9fb53de2 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 14:00:35 +0000 Subject: [PATCH 24/35] Remove redundant docstring from v1 routes and add it to v2 routes for clarity --- app/main.py | 4 ++++ app/routes/__init__.py | 3 --- app/routes/v2/__init__.py | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index b8b49eb..11973fb 100644 --- a/app/main.py +++ b/app/main.py @@ -21,6 +21,10 @@ def main(): + """ + Main function to run the FastAPI application. + This is typically used when running the app with a command like `python main.py`. + """ import uvicorn uvicorn.run("main:app", reload=True) diff --git a/app/routes/__init__.py b/app/routes/__init__.py index 1fb5f66..e69de29 100644 --- a/app/routes/__init__.py +++ b/app/routes/__init__.py @@ -1,3 +0,0 @@ -""" -Base module for the API version 2 routes. -""" diff --git a/app/routes/v2/__init__.py b/app/routes/v2/__init__.py index ee88288..ba29719 100644 --- a/app/routes/v2/__init__.py +++ b/app/routes/v2/__init__.py @@ -1,4 +1,6 @@ -# routes/v1/__init__.py +""" +Base module for the API version 2 routes. +""" from fastapi import FastAPI From 16082024f984c424c0c3d7c8fdd64e28c8872cd3 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 14:11:36 +0000 Subject: [PATCH 25/35] Fix label retrieval in PR workflow to join labels into a single string --- .github/workflows/suggest-version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/suggest-version.yml b/.github/workflows/suggest-version.yml index fb186a0..1d28d96 100644 --- a/.github/workflows/suggest-version.yml +++ b/.github/workflows/suggest-version.yml @@ -34,7 +34,7 @@ jobs: - name: Get PR labels id: pr_labels run: | - LABELS=$(gh pr view "${{ github.event.pull_request.number }}" --json labels --jq '.labels[].name') + LABELS=$(gh pr view "${{ github.event.pull_request.number }}" --json labels --jq '[.labels[].name] | join(" ")') echo "labels=$LABELS" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ github.token }} From 8e4954aeccf25619e8504ecdb3e3d0b5786ecc77 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 14:13:01 +0000 Subject: [PATCH 26/35] Update version comment in main.py to indicate future GitHub Actions integration --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 11973fb..4227718 100644 --- a/app/main.py +++ b/app/main.py @@ -8,7 +8,7 @@ from routes.v1 import api as v1 from routes.v2 import api as v2 -__version__ = "0.1.0" +__version__ = "0.1.0" # TODO: Update this version with GitHub Actions app = FastAPI(title="ChocoMax Shop API") From 7810dd1143e9ba65a9b194e21e9c07fee0969368 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 14:20:05 +0000 Subject: [PATCH 27/35] Refactor GitHub Actions workflows: consolidate version detection and PR label retrieval; remove obsolete suggest version bump workflow --- .github/workflows/detect-changed-versions.yml | 34 ++++++++++ .github/workflows/enforce-version.yml | 43 ++++-------- .github/workflows/get-pr-labels.yml | 28 ++++++++ .github/workflows/suggest-version-bump.yml | 42 ++++++++++++ .github/workflows/suggest-version.yml | 67 ------------------- .github/workflows/super-linter.yml | 2 +- 6 files changed, 117 insertions(+), 99 deletions(-) create mode 100644 .github/workflows/detect-changed-versions.yml create mode 100644 .github/workflows/get-pr-labels.yml create mode 100644 .github/workflows/suggest-version-bump.yml delete mode 100644 .github/workflows/suggest-version.yml diff --git a/.github/workflows/detect-changed-versions.yml b/.github/workflows/detect-changed-versions.yml new file mode 100644 index 0000000..fc2e467 --- /dev/null +++ b/.github/workflows/detect-changed-versions.yml @@ -0,0 +1,34 @@ +--- +name: Detect Changed Versions + +permissions: + contents: read + statuses: read + +on: + workflow_call: + outputs: + versions: + description: "Changed version folders" + value: ${{ jobs.detect.outputs.versions }} + +jobs: + detect: + runs-on: ubuntu-latest + outputs: + versions: ${{ steps.detect.outputs.versions }} + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Detect changed version folders + id: detect + run: | + git fetch origin main + BASE_SHA=$(git merge-base HEAD origin/main) + + CHANGED=$(git diff --name-only "$BASE_SHA"...HEAD | grep '^routes/v[0-9]\+/.*\.py$' | grep -v 'test' || true) + VERSIONS=$(echo "$CHANGED" | sed -n 's|^routes/\(v[0-9]\+\)/.*|\1|p' | sort -u | tr '\n' ' ') + echo "versions=$VERSIONS" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/enforce-version.yml b/.github/workflows/enforce-version.yml index eb85b6e..8809672 100644 --- a/.github/workflows/enforce-version.yml +++ b/.github/workflows/enforce-version.yml @@ -3,7 +3,7 @@ name: Enforce Correct Version Update permissions: contents: read - statuses: write + statuses: read on: pull_request: @@ -14,47 +14,28 @@ on: - '!**/tests/**' jobs: - version-check: - runs-on: ubuntu-latest + detect: + uses: ./.github/workflows/detect-changed-versions.yml + check-version: + needs: detect + runs-on: ubuntu-latest + if: needs.detect.outputs.versions != '' steps: - - name: Checkout code - uses: actions/checkout@v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Detect changed version folders - id: detect + - name: Check __version__ changes run: | - echo "🔍 Checking changed versioned folders..." - git fetch origin main BASE_SHA=$(git merge-base HEAD origin/main) - - CHANGED=$(git diff --name-only "$BASE_SHA"...HEAD | grep '^routes/v[0-9]\+/.*\.py$' | grep -v 'test' || true) - - echo "Changed files:" - echo "$CHANGED" - - # Extract unique version folders like v1, v2 - VERSIONS=$(echo "$CHANGED" | sed -n 's|^routes/\(v[0-9]\+\)/.*|\1|p' | sort -u | tr '\n' ' ') - echo "Detected version folders with changes: $VERSIONS" - echo "VERSIONS=$VERSIONS" >> "$GITHUB_ENV" - - - name: Verify __version__ change per version folder - if: env.VERSIONS != '' - run: | - echo "🔍 Checking for __version__ changes in modified version folders..." - - for v in $VERSIONS; do - echo "➡ Checking $v" - + for v in ${{ needs.detect.outputs.versions }}; do VERSION_CHANGED=$(git diff "$BASE_SHA"...HEAD -- "routes/$v/__init__.py" | grep '__version__ = ' || true) - if [ -z "$VERSION_CHANGED" ]; then - echo "🛑 Version $v was modified, but __version__ was not updated in routes/$v/__init__.py" + echo "🛑 Version $v changed, but __version__ not updated." exit 1 else - echo "✅ routes/$v/__init__.py includes a version change." + echo "✅ $v version updated." fi done diff --git a/.github/workflows/get-pr-labels.yml b/.github/workflows/get-pr-labels.yml new file mode 100644 index 0000000..cd379a2 --- /dev/null +++ b/.github/workflows/get-pr-labels.yml @@ -0,0 +1,28 @@ +--- +name: Get PR Labels + +permissions: + contents: read + statuses: read + +on: + workflow_call: + outputs: + labels: + description: "Labels on the pull request" + value: ${{ jobs.get-labels.outputs.labels }} + +jobs: + get-labels: + runs-on: ubuntu-latest + outputs: + labels: ${{ steps.labels.outputs.labels }} + + steps: + - name: Get PR labels + id: labels + run: | + LABELS=$(gh pr view "${{ github.event.pull_request.number }}" --json labels --jq '[.labels[].name] | join(" ")') + echo "labels=$LABELS" >> "$GITHUB_OUTPUT" + env: + GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/suggest-version-bump.yml b/.github/workflows/suggest-version-bump.yml new file mode 100644 index 0000000..5087f70 --- /dev/null +++ b/.github/workflows/suggest-version-bump.yml @@ -0,0 +1,42 @@ +name: Suggest Version Bump + +permissions: + contents: read + statuses: read + +on: + pull_request: + branches: [main] + paths: + - '**/*.py' + - '!**/tests/**' + +jobs: + suggest: + uses: ./.github/workflows/detect-changed-versions.yml + labels: + uses: ./.github/workflows/get-pr-labels.yml + + analyze: + needs: [suggest, labels] + runs-on: ubuntu-latest + steps: + - name: Determine bump type + id: bump + run: | + LABELS="${{ needs.labels.outputs.labels }}" + BUMP="patch" + echo "$LABELS" | grep -q 'type: feature' && BUMP="minor" + echo "$LABELS" | grep -q 'type: security' && BUMP="minor" + # ... other types + echo "bump=$BUMP" >> "$GITHUB_OUTPUT" + + - name: Report summary + if: needs.suggest.outputs.versions != '' + run: | + { + echo "### 🚀 Suggested Version Bumps" + for v in ${{ needs.suggest.outputs.versions }}; do + echo "- \`routes/$v/\`: **${{ steps.bump.outputs.bump }}**" + done + } >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/suggest-version.yml b/.github/workflows/suggest-version.yml deleted file mode 100644 index 1d28d96..0000000 --- a/.github/workflows/suggest-version.yml +++ /dev/null @@ -1,67 +0,0 @@ ---- -name: Suggest Version Bump - -permissions: - contents: read - statuses: write - -on: - pull_request: - branches: - - main - paths: - - '**/*.py' - - '!**/tests/**' - -jobs: - suggest-bump: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Determine affected API versions - id: changed - run: | - git fetch origin main - BASE_SHA=$(git merge-base HEAD origin/main) - CHANGED_FOLDERS=$(git diff --name-only "$BASE_SHA"...HEAD | grep "^routes/" | cut -d/ -f2 | sort -u | tr '\n' ' ') - echo "📁 Changed folders detected: $CHANGED_FOLDERS" - echo "folders=$CHANGED_FOLDERS" >> "$GITHUB_OUTPUT" - - - name: Get PR labels - id: pr_labels - run: | - LABELS=$(gh pr view "${{ github.event.pull_request.number }}" --json labels --jq '[.labels[].name] | join(" ")') - echo "labels=$LABELS" >> "$GITHUB_OUTPUT" - env: - GH_TOKEN: ${{ github.token }} - - - name: Determine bump type - id: bump - run: | - LABELS="${{ steps.pr_labels.outputs.labels }}" - BUMP="patch" - echo "$LABELS" | grep -q 'type: feature' && BUMP="minor" - echo "$LABELS" | grep -q 'type: security' && BUMP="minor" - echo "$LABELS" | grep -q 'type: refactor' && BUMP="patch" - echo "$LABELS" | grep -q 'type: fix' && BUMP="patch" - echo "$LABELS" | grep -q 'type: optimization' && BUMP="patch" - echo "bump=$BUMP" >> "$GITHUB_OUTPUT" - - echo "📁 Detected change in: ${{ steps.changed.outputs.folders }}" - for folder in ${{ steps.changed.outputs.folders }}; do - echo "📌 Suggest bump for routes/$folder/: $BUMP" - done - - - name: Report in job summary - if: steps.changed.outputs.folders != '' - run: | - { - echo "### 🚀 Suggested Version Bumps" - for folder in ${{ steps.changed.outputs.folders }}; do - echo "- \`routes/$folder/\`: **${{ steps.bump.outputs.bump }}**" - done - } >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/super-linter.yml b/.github/workflows/super-linter.yml index f0f2356..a7cb6ca 100644 --- a/.github/workflows/super-linter.yml +++ b/.github/workflows/super-linter.yml @@ -4,7 +4,7 @@ name: Lint permissions: contents: read packages: read - statuses: write + statuses: read on: push: From 524cb75c4af42469bbed1fbb98a9de03f500cd48 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 14:22:37 +0000 Subject: [PATCH 28/35] Update permissions and add checkout step in get-pr-labels workflow --- .github/workflows/get-pr-labels.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/get-pr-labels.yml b/.github/workflows/get-pr-labels.yml index cd379a2..cd032f1 100644 --- a/.github/workflows/get-pr-labels.yml +++ b/.github/workflows/get-pr-labels.yml @@ -4,6 +4,7 @@ name: Get PR Labels permissions: contents: read statuses: read + pull-requests: read on: workflow_call: @@ -19,6 +20,11 @@ jobs: labels: ${{ steps.labels.outputs.labels }} steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Get PR labels id: labels run: | From b34b549bea9b91dc99fa285faa598d924e21c616 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 14:26:54 +0000 Subject: [PATCH 29/35] Refactor workflow jobs: rename detect job for clarity and update dependencies in enforce-version and suggest-version-bump workflows --- .github/workflows/detect-changed-versions.yml | 5 +++-- .github/workflows/enforce-version.yml | 11 ++++++----- .github/workflows/suggest-version-bump.yml | 6 +++++- .github/workflows/unit-tests.yml | 5 ----- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/detect-changed-versions.yml b/.github/workflows/detect-changed-versions.yml index fc2e467..6299877 100644 --- a/.github/workflows/detect-changed-versions.yml +++ b/.github/workflows/detect-changed-versions.yml @@ -13,7 +13,8 @@ on: value: ${{ jobs.detect.outputs.versions }} jobs: - detect: + detect-changed-versions: + name: Detect Changed Versions runs-on: ubuntu-latest outputs: versions: ${{ steps.detect.outputs.versions }} @@ -24,7 +25,7 @@ jobs: fetch-depth: 0 - name: Detect changed version folders - id: detect + id: list-folders run: | git fetch origin main BASE_SHA=$(git merge-base HEAD origin/main) diff --git a/.github/workflows/enforce-version.yml b/.github/workflows/enforce-version.yml index 8809672..356a67c 100644 --- a/.github/workflows/enforce-version.yml +++ b/.github/workflows/enforce-version.yml @@ -14,23 +14,24 @@ on: - '!**/tests/**' jobs: - detect: + detect-changed-versions: uses: ./.github/workflows/detect-changed-versions.yml check-version: - needs: detect + name: Check __version__ Changes + needs: detect-changed-versions runs-on: ubuntu-latest - if: needs.detect.outputs.versions != '' + if: needs.detect-changed-versions.outputs.versions != '' steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Check __version__ changes + - name: Check __version__ change for each version run: | git fetch origin main BASE_SHA=$(git merge-base HEAD origin/main) - for v in ${{ needs.detect.outputs.versions }}; do + for v in ${{ needs.detect-changed-versions.outputs.versions }}; do VERSION_CHANGED=$(git diff "$BASE_SHA"...HEAD -- "routes/$v/__init__.py" | grep '__version__ = ' || true) if [ -z "$VERSION_CHANGED" ]; then echo "🛑 Version $v changed, but __version__ not updated." diff --git a/.github/workflows/suggest-version-bump.yml b/.github/workflows/suggest-version-bump.yml index 5087f70..37db7a3 100644 --- a/.github/workflows/suggest-version-bump.yml +++ b/.github/workflows/suggest-version-bump.yml @@ -18,8 +18,12 @@ jobs: uses: ./.github/workflows/get-pr-labels.yml analyze: - needs: [suggest, labels] + name: Analyze Changes and Suggest Bumps + needs: + - suggest + - labels runs-on: ubuntu-latest + steps: - name: Determine bump type id: bump diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 9b4d830..b274b07 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -15,11 +15,6 @@ jobs: name: Pytest on ${{ matrix.os }} with Python ${{ matrix.python-version }} runs-on: ${{ matrix.os }} - permissions: - contents: read - packages: read - statuses: write - strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] From 3607e7cde32c6c8f88f48bb6ab4ab9a050c4f98b Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 14:52:48 +0000 Subject: [PATCH 30/35] Update workflows: change permissions to write and enhance step names for clarity --- .github/workflows/detect-changed-versions.yml | 1 + .github/workflows/enforce-version.yml | 62 ++++++++++++++----- .github/workflows/get-pr-labels.yml | 1 + .github/workflows/super-linter.yml | 4 +- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/.github/workflows/detect-changed-versions.yml b/.github/workflows/detect-changed-versions.yml index 6299877..1332a36 100644 --- a/.github/workflows/detect-changed-versions.yml +++ b/.github/workflows/detect-changed-versions.yml @@ -20,6 +20,7 @@ jobs: versions: ${{ steps.detect.outputs.versions }} steps: + - name: Checkout code - uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/.github/workflows/enforce-version.yml b/.github/workflows/enforce-version.yml index 356a67c..13f42c4 100644 --- a/.github/workflows/enforce-version.yml +++ b/.github/workflows/enforce-version.yml @@ -3,7 +3,7 @@ name: Enforce Correct Version Update permissions: contents: read - statuses: read + statuses: write on: pull_request: @@ -14,29 +14,63 @@ on: - '!**/tests/**' jobs: - detect-changed-versions: - uses: ./.github/workflows/detect-changed-versions.yml - - check-version: - name: Check __version__ Changes - needs: detect-changed-versions + version-check: runs-on: ubuntu-latest - if: needs.detect-changed-versions.outputs.versions != '' + steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Check __version__ change for each version + - name: Detect changed version folders and main.py + id: detect run: | + echo "🔍 Checking changed versioned folders and main.py..." + git fetch origin main BASE_SHA=$(git merge-base HEAD origin/main) - for v in ${{ needs.detect-changed-versions.outputs.versions }}; do - VERSION_CHANGED=$(git diff "$BASE_SHA"...HEAD -- "routes/$v/__init__.py" | grep '__version__ = ' || true) + + # List changed Python files (excluding tests) + CHANGED=$(git diff --name-only "$BASE_SHA"...HEAD | grep '\.py$' | grep -v 'test' || true) + echo "$CHANGED" + + # Extract unique version folders like v1, v2 + VERSIONS=$(echo "$CHANGED" | sed -n 's|^app/routes/\(v[0-9]\+\)/.*|\1|p' | sort -u | tr '\n' ' ') + echo "Detected version folders with changes: $VERSIONS" + echo "VERSIONS=$VERSIONS" >> "$GITHUB_ENV" + + # Check if main.py was modified + MAIN_CHANGED=$(echo "$CHANGED" | grep '^app/main.py$' || true) + echo "MAIN_CHANGED=$MAIN_CHANGED" >> "$GITHUB_ENV" + + - name: Verify __version__ change in version folders + if: env.VERSIONS != '' + run: | + echo "🔍 Checking for __version__ changes in versioned routes..." + + for v in $VERSIONS; do + echo "➡ Checking app/routes/$v/__init__.py" + VERSION_CHANGED=$(git diff "$BASE_SHA"...HEAD -- "app/routes/$v/__init__.py" | grep '__version__ = ' || true) + if [ -z "$VERSION_CHANGED" ]; then - echo "🛑 Version $v changed, but __version__ not updated." + echo "🛑 Version $v was modified, but __version__ was not updated in app/routes/$v/__init__.py" exit 1 else - echo "✅ $v version updated." + echo "✅ app/routes/$v/__init__.py includes a version change." fi done + + - name: Verify __version__ change in main.py + if: env.MAIN_CHANGED != '' + run: | + echo "🔍 Checking for __version__ changes in main.py..." + + VERSION_CHANGED=$(git diff "$BASE_SHA"...HEAD -- "app/main.py" | grep '__version__ = ' || true) + + if [ -z "$VERSION_CHANGED" ]; then + echo "🛑 main.py was modified, but __version__ was not updated in app/main.py" + exit 1 + else + echo "✅ app/main.py includes a version change." + fi diff --git a/.github/workflows/get-pr-labels.yml b/.github/workflows/get-pr-labels.yml index cd032f1..95ab82a 100644 --- a/.github/workflows/get-pr-labels.yml +++ b/.github/workflows/get-pr-labels.yml @@ -15,6 +15,7 @@ on: jobs: get-labels: + name: Get PR Labels runs-on: ubuntu-latest outputs: labels: ${{ steps.labels.outputs.labels }} diff --git a/.github/workflows/super-linter.yml b/.github/workflows/super-linter.yml index a7cb6ca..a945641 100644 --- a/.github/workflows/super-linter.yml +++ b/.github/workflows/super-linter.yml @@ -4,7 +4,7 @@ name: Lint permissions: contents: read packages: read - statuses: read + statuses: write on: push: @@ -23,7 +23,7 @@ jobs: with: fetch-depth: 0 - - name: Super-linter + - name: Run Super Linter uses: super-linter/super-linter@v7 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From b1762a4261d64891061baa40529a280dee08dd04 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 14:56:51 +0000 Subject: [PATCH 31/35] Update devcontainer-verification and enforce-version workflows: add permissions and enhance version change verification logic --- .../workflows/devcontainer-verification.yml | 1 + .github/workflows/enforce-version.yml | 46 +++++++++++-------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/.github/workflows/devcontainer-verification.yml b/.github/workflows/devcontainer-verification.yml index 725829c..c0a1948 100644 --- a/.github/workflows/devcontainer-verification.yml +++ b/.github/workflows/devcontainer-verification.yml @@ -3,6 +3,7 @@ name: Scan Devcontainer Image permissions: actions: read + contents: read security-events: write on: diff --git a/.github/workflows/enforce-version.yml b/.github/workflows/enforce-version.yml index 13f42c4..e056b10 100644 --- a/.github/workflows/enforce-version.yml +++ b/.github/workflows/enforce-version.yml @@ -1,4 +1,3 @@ ---- name: Enforce Correct Version Update permissions: @@ -44,33 +43,44 @@ jobs: MAIN_CHANGED=$(echo "$CHANGED" | grep '^app/main.py$' || true) echo "MAIN_CHANGED=$MAIN_CHANGED" >> "$GITHUB_ENV" - - name: Verify __version__ change in version folders - if: env.VERSIONS != '' + - name: Verify version changes and summarize run: | - echo "🔍 Checking for __version__ changes in versioned routes..." + echo "📋 Running version change checks..." + git fetch origin main + BASE_SHA=$(git merge-base HEAD origin/main) + + REPORT="" + EXIT_CODE=0 + + # Check version folders for v in $VERSIONS; do echo "➡ Checking app/routes/$v/__init__.py" VERSION_CHANGED=$(git diff "$BASE_SHA"...HEAD -- "app/routes/$v/__init__.py" | grep '__version__ = ' || true) if [ -z "$VERSION_CHANGED" ]; then - echo "🛑 Version $v was modified, but __version__ was not updated in app/routes/$v/__init__.py" - exit 1 + REPORT+="🛑 Version $v was modified, but __version__ was not updated in app/routes/$v/__init__.py\n" + EXIT_CODE=1 else - echo "✅ app/routes/$v/__init__.py includes a version change." + REPORT+="✅ app/routes/$v/__init__.py includes a version change.\n" fi done - - name: Verify __version__ change in main.py - if: env.MAIN_CHANGED != '' - run: | - echo "🔍 Checking for __version__ changes in main.py..." - - VERSION_CHANGED=$(git diff "$BASE_SHA"...HEAD -- "app/main.py" | grep '__version__ = ' || true) + # Check main.py + if [ -n "$MAIN_CHANGED" ]; then + echo "➡ Checking app/main.py" + VERSION_CHANGED=$(git diff "$BASE_SHA"...HEAD -- "app/main.py" | grep '__version__ = ' || true) - if [ -z "$VERSION_CHANGED" ]; then - echo "🛑 main.py was modified, but __version__ was not updated in app/main.py" - exit 1 - else - echo "✅ app/main.py includes a version change." + if [ -z "$VERSION_CHANGED" ]; then + REPORT+="🛑 main.py was modified, but __version__ was not updated in app/main.py\n" + EXIT_CODE=1 + else + REPORT+="✅ app/main.py includes a version change.\n" + fi fi + + echo -e "\n==== Version Check Report ====" + echo -e "$REPORT" + echo "================================" + + exit $EXIT_CODE From 00850038985c9a90be204a6a67e53cc238551c1e Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 14:59:27 +0000 Subject: [PATCH 32/35] Fix output references in detect-changed-versions workflow for consistency --- .github/workflows/detect-changed-versions.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/detect-changed-versions.yml b/.github/workflows/detect-changed-versions.yml index 1332a36..7348b62 100644 --- a/.github/workflows/detect-changed-versions.yml +++ b/.github/workflows/detect-changed-versions.yml @@ -10,18 +10,18 @@ on: outputs: versions: description: "Changed version folders" - value: ${{ jobs.detect.outputs.versions }} + value: ${{ jobs.detect-changed-versions.outputs.versions }} jobs: detect-changed-versions: name: Detect Changed Versions runs-on: ubuntu-latest outputs: - versions: ${{ steps.detect.outputs.versions }} + versions: ${{ steps.list-folders.outputs.versions }} steps: - name: Checkout code - - uses: actions/checkout@v4 + uses: actions/checkout@v4 with: fetch-depth: 0 From 67e1fa50da1c57ee483c4aa13390d851bcfb6225 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 15:01:11 +0000 Subject: [PATCH 33/35] Fix description quotes in workflow outputs for consistency --- .github/workflows/detect-changed-versions.yml | 2 +- .github/workflows/get-pr-labels.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/detect-changed-versions.yml b/.github/workflows/detect-changed-versions.yml index 7348b62..28ed34b 100644 --- a/.github/workflows/detect-changed-versions.yml +++ b/.github/workflows/detect-changed-versions.yml @@ -9,7 +9,7 @@ on: workflow_call: outputs: versions: - description: "Changed version folders" + description: 'Changed version folders' value: ${{ jobs.detect-changed-versions.outputs.versions }} jobs: diff --git a/.github/workflows/get-pr-labels.yml b/.github/workflows/get-pr-labels.yml index 95ab82a..3cb4d49 100644 --- a/.github/workflows/get-pr-labels.yml +++ b/.github/workflows/get-pr-labels.yml @@ -10,7 +10,7 @@ on: workflow_call: outputs: labels: - description: "Labels on the pull request" + description: 'Labels on the pull request' value: ${{ jobs.get-labels.outputs.labels }} jobs: From fa478da8ecea9fb64fd1d0be562fafae41bcc6a3 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 15:04:43 +0000 Subject: [PATCH 34/35] Update suggest-version-bump workflow: add pull-requests permission --- .github/workflows/suggest-version-bump.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/suggest-version-bump.yml b/.github/workflows/suggest-version-bump.yml index 37db7a3..10ae9e0 100644 --- a/.github/workflows/suggest-version-bump.yml +++ b/.github/workflows/suggest-version-bump.yml @@ -3,6 +3,7 @@ name: Suggest Version Bump permissions: contents: read statuses: read + pull-requests: read on: pull_request: From 189bd8031694b71e15b59b80822ef57c860b26e5 Mon Sep 17 00:00:00 2001 From: Vianpyro Date: Mon, 26 May 2025 15:07:23 +0000 Subject: [PATCH 35/35] Remove TODO comment for version update in main.py --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 4227718..11973fb 100644 --- a/app/main.py +++ b/app/main.py @@ -8,7 +8,7 @@ from routes.v1 import api as v1 from routes.v2 import api as v2 -__version__ = "0.1.0" # TODO: Update this version with GitHub Actions +__version__ = "0.1.0" app = FastAPI(title="ChocoMax Shop API")