From 29ac11a42037b8cbacfddbc8bb8409588ef836b4 Mon Sep 17 00:00:00 2001 From: Kumaran Rajendhiran Date: Fri, 8 Nov 2024 11:37:19 +0530 Subject: [PATCH 1/9] Add script to generate replay files and generated replay files --- cookiecutter_replay/fastapi+mesop_3.10.json | 8 +++++ cookiecutter_replay/fastapi+mesop_3.11.json | 8 +++++ cookiecutter_replay/fastapi+mesop_3.12.json | 8 +++++ cookiecutter_replay/mesop_3.10.json | 8 +++++ cookiecutter_replay/mesop_3.11.json | 8 +++++ cookiecutter_replay/mesop_3.12.json | 8 +++++ .../nats+fastapi+mesop_3.10.json | 8 +++++ .../nats+fastapi+mesop_3.11.json | 8 +++++ .../nats+fastapi+mesop_3.12.json | 8 +++++ scripts/generate_cookiecutter_replay.py | 33 +++++++++++++++++++ scripts/generate_cookiecutter_replay.sh | 3 ++ 11 files changed, 108 insertions(+) create mode 100644 cookiecutter_replay/fastapi+mesop_3.10.json create mode 100644 cookiecutter_replay/fastapi+mesop_3.11.json create mode 100644 cookiecutter_replay/fastapi+mesop_3.12.json create mode 100644 cookiecutter_replay/mesop_3.10.json create mode 100644 cookiecutter_replay/mesop_3.11.json create mode 100644 cookiecutter_replay/mesop_3.12.json create mode 100644 cookiecutter_replay/nats+fastapi+mesop_3.10.json create mode 100644 cookiecutter_replay/nats+fastapi+mesop_3.11.json create mode 100644 cookiecutter_replay/nats+fastapi+mesop_3.12.json create mode 100644 scripts/generate_cookiecutter_replay.py create mode 100755 scripts/generate_cookiecutter_replay.sh diff --git a/cookiecutter_replay/fastapi+mesop_3.10.json b/cookiecutter_replay/fastapi+mesop_3.10.json new file mode 100644 index 0000000..a01a39f --- /dev/null +++ b/cookiecutter_replay/fastapi+mesop_3.10.json @@ -0,0 +1,8 @@ +{ + "cookiecutter": { + "project_name": "My FastAgency App", + "project_slug": "my_fastagency_app", + "app_type": "fastapi+mesop", + "python_version": "3.10" + } +} \ No newline at end of file diff --git a/cookiecutter_replay/fastapi+mesop_3.11.json b/cookiecutter_replay/fastapi+mesop_3.11.json new file mode 100644 index 0000000..a01cd63 --- /dev/null +++ b/cookiecutter_replay/fastapi+mesop_3.11.json @@ -0,0 +1,8 @@ +{ + "cookiecutter": { + "project_name": "My FastAgency App", + "project_slug": "my_fastagency_app", + "app_type": "fastapi+mesop", + "python_version": "3.11" + } +} \ No newline at end of file diff --git a/cookiecutter_replay/fastapi+mesop_3.12.json b/cookiecutter_replay/fastapi+mesop_3.12.json new file mode 100644 index 0000000..d426f06 --- /dev/null +++ b/cookiecutter_replay/fastapi+mesop_3.12.json @@ -0,0 +1,8 @@ +{ + "cookiecutter": { + "project_name": "My FastAgency App", + "project_slug": "my_fastagency_app", + "app_type": "fastapi+mesop", + "python_version": "3.12" + } +} \ No newline at end of file diff --git a/cookiecutter_replay/mesop_3.10.json b/cookiecutter_replay/mesop_3.10.json new file mode 100644 index 0000000..3eb76aa --- /dev/null +++ b/cookiecutter_replay/mesop_3.10.json @@ -0,0 +1,8 @@ +{ + "cookiecutter": { + "project_name": "My FastAgency App", + "project_slug": "my_fastagency_app", + "app_type": "mesop", + "python_version": "3.10" + } +} \ No newline at end of file diff --git a/cookiecutter_replay/mesop_3.11.json b/cookiecutter_replay/mesop_3.11.json new file mode 100644 index 0000000..5ee9899 --- /dev/null +++ b/cookiecutter_replay/mesop_3.11.json @@ -0,0 +1,8 @@ +{ + "cookiecutter": { + "project_name": "My FastAgency App", + "project_slug": "my_fastagency_app", + "app_type": "mesop", + "python_version": "3.11" + } +} \ No newline at end of file diff --git a/cookiecutter_replay/mesop_3.12.json b/cookiecutter_replay/mesop_3.12.json new file mode 100644 index 0000000..3cc0111 --- /dev/null +++ b/cookiecutter_replay/mesop_3.12.json @@ -0,0 +1,8 @@ +{ + "cookiecutter": { + "project_name": "My FastAgency App", + "project_slug": "my_fastagency_app", + "app_type": "mesop", + "python_version": "3.12" + } +} \ No newline at end of file diff --git a/cookiecutter_replay/nats+fastapi+mesop_3.10.json b/cookiecutter_replay/nats+fastapi+mesop_3.10.json new file mode 100644 index 0000000..0b7bafd --- /dev/null +++ b/cookiecutter_replay/nats+fastapi+mesop_3.10.json @@ -0,0 +1,8 @@ +{ + "cookiecutter": { + "project_name": "My FastAgency App", + "project_slug": "my_fastagency_app", + "app_type": "nats+fastapi+mesop", + "python_version": "3.10" + } +} \ No newline at end of file diff --git a/cookiecutter_replay/nats+fastapi+mesop_3.11.json b/cookiecutter_replay/nats+fastapi+mesop_3.11.json new file mode 100644 index 0000000..d021970 --- /dev/null +++ b/cookiecutter_replay/nats+fastapi+mesop_3.11.json @@ -0,0 +1,8 @@ +{ + "cookiecutter": { + "project_name": "My FastAgency App", + "project_slug": "my_fastagency_app", + "app_type": "nats+fastapi+mesop", + "python_version": "3.11" + } +} \ No newline at end of file diff --git a/cookiecutter_replay/nats+fastapi+mesop_3.12.json b/cookiecutter_replay/nats+fastapi+mesop_3.12.json new file mode 100644 index 0000000..67b9031 --- /dev/null +++ b/cookiecutter_replay/nats+fastapi+mesop_3.12.json @@ -0,0 +1,8 @@ +{ + "cookiecutter": { + "project_name": "My FastAgency App", + "project_slug": "my_fastagency_app", + "app_type": "nats+fastapi+mesop", + "python_version": "3.12" + } +} \ No newline at end of file diff --git a/scripts/generate_cookiecutter_replay.py b/scripts/generate_cookiecutter_replay.py new file mode 100644 index 0000000..f77647f --- /dev/null +++ b/scripts/generate_cookiecutter_replay.py @@ -0,0 +1,33 @@ +import json +from pathlib import Path + +PROJECT_NAME = "My FastAgency App" +PROJECT_SLUG = "my_fastagency_app" + +APP_TYPES = ["fastapi+mesop", "mesop", "nats+fastapi+mesop"] + +PYTHON_VERSIONS = ["3.12", "3.11", "3.10"] + + +def generate_cookiecutter_replay(): + for app_type in APP_TYPES: + for python_version in PYTHON_VERSIONS: + print(f"Generating cookiecutter replay for {app_type} with Python {python_version}") + cookiecutter_replay = { + "cookiecutter": { + "project_name": PROJECT_NAME, + "project_slug": PROJECT_SLUG, + "app_type": app_type, + "python_version": python_version, + } + } + + # Write to cookiecutter replay file + replay_file = Path(__file__).parent.parent.resolve() / "cookiecutter_replay" / f"{app_type}_{python_version}.json" + + with open(replay_file, "w") as f: + json.dump(cookiecutter_replay, f, indent=4) + + +if __name__ == "__main__": + generate_cookiecutter_replay() diff --git a/scripts/generate_cookiecutter_replay.sh b/scripts/generate_cookiecutter_replay.sh new file mode 100755 index 0000000..e1cb593 --- /dev/null +++ b/scripts/generate_cookiecutter_replay.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +python3 scripts/generate_cookiecutter_replay.py From 4f821778d9f6cdc23197914f91e51abedd52f170 Mon Sep 17 00:00:00 2001 From: Kumaran Rajendhiran Date: Fri, 8 Nov 2024 13:03:44 +0530 Subject: [PATCH 2/9] Add CI to run cookiecutter tests --- .github/workflows/test.yml | 62 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..85a15c9 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,62 @@ +name: Test + +on: + push: + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + pre-commit-check: + strategy: + matrix: + python-version: ["3.12", "3.11", "3.10"] + app-type: ["fastapi+mesop", "mesop", "nats+fastapi+mesop"] + fail-fast: false + runs-on: ubuntu-latest + timeout-minutes: 15 + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: "pip" + + - name: Install Cookiecutter + run: pip install cookiecutter + + - name: Run cookiecutter + run: cookiecutter --replay-file ./cookiecutter_replay/${{ matrix.app-type }}_${{ matrix.python-version }}.json ./ + + - name: Install Generated Project Dependencies + run: cd my_fastagency_app && pip install .[dev] + + - name: Run Pre-commit + run: cd my_fastagency_app && pre-commit run --all-files + + # https://github.com/marketplace/actions/alls-green#why + check: # This job does nothing and is only used for the branch protection + # from: https://github.com/re-actors/alls-green + # Important: For this to work properly, it is a must to have the job always + # run, otherwise GitHub will make it skipped when any of the dependencies + # fail. In some contexts, skipped is interpreted as success which may lead + # to undersired, unobvious and even dangerous (as in security breach + # "dangerous") side-effects. + if: always() + + needs: + - pre-commit-check + + runs-on: ubuntu-latest + + steps: + - name: Decide whether the needed jobs succeeded or failed + uses: re-actors/alls-green@release/v1 # nosemgrep + with: + # allowed-failures: docs, linters + # allowed-skips: non-voting-flaky-job + jobs: ${{ toJSON(needs) }} From 3d6ead8cdb28252517e40d672e3557f672879b56 Mon Sep 17 00:00:00 2001 From: Kumaran Rajendhiran Date: Fri, 8 Nov 2024 13:13:12 +0530 Subject: [PATCH 3/9] Run pre-commit only for the generated project files --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 85a15c9..b00bad6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,7 +36,7 @@ jobs: run: cd my_fastagency_app && pip install .[dev] - name: Run Pre-commit - run: cd my_fastagency_app && pre-commit run --all-files + run: cd my_fastagency_app && pre-commit run --show-diff-on-failure --color=always --files my_fastagency_app/* # https://github.com/marketplace/actions/alls-green#why check: # This job does nothing and is only used for the branch protection From 3e0c762c93a9c12e665453ca184a396ee62d7725 Mon Sep 17 00:00:00 2001 From: Kumaran Rajendhiran Date: Fri, 8 Nov 2024 14:12:20 +0530 Subject: [PATCH 4/9] Fix issues with running pre-commit in CI --- .github/workflows/test.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b00bad6..f090214 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,7 +36,12 @@ jobs: run: cd my_fastagency_app && pip install .[dev] - name: Run Pre-commit - run: cd my_fastagency_app && pre-commit run --show-diff-on-failure --color=always --files my_fastagency_app/* + run: | + cd my_fastagency_app + ls -lah + git init + git add . + pre-commit run --show-diff-on-failure --color=always # https://github.com/marketplace/actions/alls-green#why check: # This job does nothing and is only used for the branch protection From 3d9aa921a94c4b1a2225a581208d148350ec4e5b Mon Sep 17 00:00:00 2001 From: Kumaran Rajendhiran Date: Fri, 8 Nov 2024 14:21:17 +0530 Subject: [PATCH 5/9] Add --all-files flag --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f090214..6c8b158 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,7 +41,7 @@ jobs: ls -lah git init git add . - pre-commit run --show-diff-on-failure --color=always + pre-commit run --show-diff-on-failure --color=always --all-files # https://github.com/marketplace/actions/alls-green#why check: # This job does nothing and is only used for the branch protection From 09b0bb4752828a11b8d0687e5652e80da23647b6 Mon Sep 17 00:00:00 2001 From: Kumaran Rajendhiran Date: Fri, 8 Nov 2024 14:46:27 +0530 Subject: [PATCH 6/9] Add script to create cookiecutter project and to run pre-commit on the generated project --- .github/workflows/test.yml | 25 ++++++++++++++----------- .gitignore | 20 ++++++++++++++++++++ scripts/test_cookiecutter.sh | 22 ++++++++++++++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 .gitignore create mode 100755 scripts/test_cookiecutter.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6c8b158..a19a0f5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,19 +29,22 @@ jobs: - name: Install Cookiecutter run: pip install cookiecutter - - name: Run cookiecutter - run: cookiecutter --replay-file ./cookiecutter_replay/${{ matrix.app-type }}_${{ matrix.python-version }}.json ./ + - name: Test Cookiecutter + run: ./scripts/test-cookiecutter.sh ${{ matrix.app-type }} ${{ matrix.python-version }} - - name: Install Generated Project Dependencies - run: cd my_fastagency_app && pip install .[dev] + # - name: Run cookiecutter + # run: cookiecutter --replay-file ./cookiecutter_replay/${{ matrix.app-type }}_${{ matrix.python-version }}.json ./ - - name: Run Pre-commit - run: | - cd my_fastagency_app - ls -lah - git init - git add . - pre-commit run --show-diff-on-failure --color=always --all-files + # - name: Install Generated Project Dependencies + # run: cd my_fastagency_app && pip install .[dev] + + # - name: Run Pre-commit + # run: | + # cd my_fastagency_app + # ls -lah + # git init + # git add . + # pre-commit run --show-diff-on-failure --color=always --all-files # https://github.com/marketplace/actions/alls-green#why check: # This job does nothing and is only used for the branch protection diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c8dbc02 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +__pycache__ +dist +.idea +venv* +.venv* +.env +.env* +*.lock +.vscode +.pypirc +.pytest_cache +.ruff_cache +.mypy_cache +.coverage* +.cache +htmlcov +token +.DS_Store + +generated/ diff --git a/scripts/test_cookiecutter.sh b/scripts/test_cookiecutter.sh new file mode 100755 index 0000000..2a44a5f --- /dev/null +++ b/scripts/test_cookiecutter.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# This script is used to test the cookiecutter template +# It will create a new project using the cookiecutter template under the generated/ directory +# The script accepts two positional arguments: app-type and python-version +# The cookiecutter replay file is used to provide the default values for the cookiecutter template + +# Accept two arguments: app-type and python-version +echo "Generating project using cookiecutter template with app-type: $1 and python-version: $2" +cookiecutter -f --replay-file ./cookiecutter_replay/$1_$2.json --output-dir generated/ ./ + +# Install generated project's dependencies +echo "Installing dependencies for the generated project" +cd generated/my_fastagency_app && pip install -e .[dev] && cd ../../ + +# Initialize git in the generated project(needed for pre-commit) +echo "Initializing git in the generated project" +cd generated/my_fastagency_app && git init && git add . && cd ../../ + +# Run pre-commit +echo "Running pre-commit" +cd generated/my_fastagency_app && pre-commit run --show-diff-on-failure --color=always --all-files && cd ../../ From e7e1b8b914e3c730ad8b7c6ebdcb12845f488f03 Mon Sep 17 00:00:00 2001 From: Kumaran Rajendhiran Date: Fri, 8 Nov 2024 14:50:10 +0530 Subject: [PATCH 7/9] Fix typo --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a19a0f5..8ffdd9d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: run: pip install cookiecutter - name: Test Cookiecutter - run: ./scripts/test-cookiecutter.sh ${{ matrix.app-type }} ${{ matrix.python-version }} + run: ./scripts/test_cookiecutter.sh ${{ matrix.app-type }} ${{ matrix.python-version }} # - name: Run cookiecutter # run: cookiecutter --replay-file ./cookiecutter_replay/${{ matrix.app-type }}_${{ matrix.python-version }}.json ./ From 8f03219ba8bea295ac401a5e626c1166f7697483 Mon Sep 17 00:00:00 2001 From: Kumaran Rajendhiran Date: Fri, 8 Nov 2024 14:53:03 +0530 Subject: [PATCH 8/9] Remove commented out lines --- .github/workflows/test.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8ffdd9d..23cbc7d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,20 +32,6 @@ jobs: - name: Test Cookiecutter run: ./scripts/test_cookiecutter.sh ${{ matrix.app-type }} ${{ matrix.python-version }} - # - name: Run cookiecutter - # run: cookiecutter --replay-file ./cookiecutter_replay/${{ matrix.app-type }}_${{ matrix.python-version }}.json ./ - - # - name: Install Generated Project Dependencies - # run: cd my_fastagency_app && pip install .[dev] - - # - name: Run Pre-commit - # run: | - # cd my_fastagency_app - # ls -lah - # git init - # git add . - # pre-commit run --show-diff-on-failure --color=always --all-files - # https://github.com/marketplace/actions/alls-green#why check: # This job does nothing and is only used for the branch protection # from: https://github.com/re-actors/alls-green From 7e9fea28b069fcb030a6ff0dfa9d1113f67409e1 Mon Sep 17 00:00:00 2001 From: Kumaran Rajendhiran Date: Fri, 8 Nov 2024 14:54:58 +0530 Subject: [PATCH 9/9] Change echo to print in green colour --- scripts/test_cookiecutter.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/test_cookiecutter.sh b/scripts/test_cookiecutter.sh index 2a44a5f..bc2fcb3 100755 --- a/scripts/test_cookiecutter.sh +++ b/scripts/test_cookiecutter.sh @@ -6,17 +6,17 @@ # The cookiecutter replay file is used to provide the default values for the cookiecutter template # Accept two arguments: app-type and python-version -echo "Generating project using cookiecutter template with app-type: $1 and python-version: $2" +echo -e "\033[32mGenerating project using cookiecutter template with app-type: $1 and python-version: $2\033[0m" cookiecutter -f --replay-file ./cookiecutter_replay/$1_$2.json --output-dir generated/ ./ # Install generated project's dependencies -echo "Installing dependencies for the generated project" +echo -e "\033[32mInstalling dependencies for the generated project\033[0m" cd generated/my_fastagency_app && pip install -e .[dev] && cd ../../ # Initialize git in the generated project(needed for pre-commit) -echo "Initializing git in the generated project" +echo -e "\033[32mInitializing git in the generated project\033[0m" cd generated/my_fastagency_app && git init && git add . && cd ../../ # Run pre-commit -echo "Running pre-commit" +echo -e "\033[32mRunning pre-commit\033[0m" cd generated/my_fastagency_app && pre-commit run --show-diff-on-failure --color=always --all-files && cd ../../