From a3401b8782bc83f05e13ef7fa177cbc73a6f0239 Mon Sep 17 00:00:00 2001 From: Chris Taylor Date: Wed, 25 Jun 2025 15:11:10 -0500 Subject: [PATCH 1/5] Implement pre-commit --- .github/workflows/python-tests.yml | 14 +++++-- .pre-commit-config.yaml | 39 +++++++++++++++++++ .tool-versions | 1 + .../production/us-east-1/000/terraform.tfvars | 1 - pyproject.toml | 5 +++ terragrunt.hcl | 16 ++++---- 6 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index e681095..7ccde69 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -15,6 +15,17 @@ permissions: pull-requests: write jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f + - name: Set up Python 3.13 + uses: astral-sh/setup-uv@7bbb36f4345bf059635fb6d04d0fb369ca42338e + with: + python-version: 3.13 + - uses: launchbynttdata/actions-asdf-install_tools@v0 + - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd + run-tests: runs-on: ubuntu-latest strategy: @@ -29,9 +40,6 @@ jobs: uses: astral-sh/setup-uv@7bbb36f4345bf059635fb6d04d0fb369ca42338e with: python-version: ${{ matrix.python-version }} - - name: Ruff check - run: | - uvx ruff check - name: Install dependencies run: | uv sync diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..3467417 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,39 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # v5.0.0 + hooks: + - id: trailing-whitespace + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-json + - id: check-merge-conflict + - id: check-shebang-scripts-are-executable + - id: check-yaml + args: + - --allow-multiple-documents + - id: end-of-file-fixer + - id: mixed-line-ending + args: + - --fix=auto + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: 8a948e557ca98afa9489998ad0b85515964df9c4 # v0.12.0 + hooks: + - id: ruff-check + types_or: [python, pyi] + args: [--fix] + - id: ruff-format + types_or: [python, pyi] + - repo: https://github.com/RobertCraigie/pyright-python + rev: 708a9d4a964376a7be931b7721d315ef1d2db31d # v1.1.402 + hooks: + - id: pyright + - repo: https://github.com/antonbabenko/pre-commit-terraform + rev: 2f8bda194a420ad77a050a9de627d77a74841fdc # v1.99.4 + hooks: + - id: terragrunt_fmt + - id: terragrunt_validate_inputs + exclude: "^[^/]+$" + args: + - --env-vars=TF_VAR_organization_tag="THIS_ORGANIZATION" + - --env-vars=TF_VAR_repository_tag="THIS_REPOSITORY" + - --env-vars=TF_VAR_commit_hash_tag="THIS_COMMIT_HASH" diff --git a/.tool-versions b/.tool-versions index 3b06445..e400a79 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,3 +1,4 @@ +pre-commit 3.3.3 python 3.13.1 terraform 1.5.5 terragrunt 0.54.11 diff --git a/platform/production/us-east-1/000/terraform.tfvars b/platform/production/us-east-1/000/terraform.tfvars index db8aaa6..55027fa 100644 --- a/platform/production/us-east-1/000/terraform.tfvars +++ b/platform/production/us-east-1/000/terraform.tfvars @@ -7,4 +7,3 @@ name = "platform_sample-useast1-production-000-fn-000" environment_variables = { PAYLOAD = "Primary" } - diff --git a/pyproject.toml b/pyproject.toml index 7816a03..6c82dc3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,3 +54,8 @@ exclude = [ "site-packages", ".venv", ] + +[tool.pyright] +# ... +venvPath = "." +venv = ".venv" diff --git a/terragrunt.hcl b/terragrunt.hcl index 51a78cb..78c37fc 100644 --- a/terragrunt.hcl +++ b/terragrunt.hcl @@ -1,13 +1,13 @@ locals { - naming_prefix = "sample_lambda" - relative_path = path_relative_to_include() - path_parts = split("/", local.relative_path) - account_name = local.path_parts[1] - region = local.path_parts[2] + naming_prefix = "sample_lambda" + relative_path = path_relative_to_include() + path_parts = split("/", local.relative_path) + account_name = local.path_parts[1] + region = local.path_parts[2] environment_instance = basename(local.relative_path) - bucket = "${replace(local.naming_prefix, "_", "-")}-${local.region}-${local.account_name}-${local.environment_instance}-tfstate" - dynamodb_table = "${local.naming_prefix}-${local.region}-${local.account_name}-${local.environment_instance}-tflocks" + bucket = "${replace(local.naming_prefix, "_", "-")}-${local.region}-${local.account_name}-${local.environment_instance}-tfstate" + dynamodb_table = "${local.naming_prefix}-${local.region}-${local.account_name}-${local.environment_instance}-tflocks" } # Generate the AWS provider settings @@ -75,4 +75,4 @@ inputs = { naming_prefix = local.naming_prefix environment = local.account_name region = local.region -} \ No newline at end of file +} From 9eb68a95cfc318055113161115408fcddfc36696 Mon Sep 17 00:00:00 2001 From: Chris Taylor Date: Wed, 25 Jun 2025 15:19:43 -0500 Subject: [PATCH 2/5] Drop UV setup step from pre-commit --- .github/workflows/python-tests.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 7ccde69..198dd89 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -19,10 +19,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f - - name: Set up Python 3.13 - uses: astral-sh/setup-uv@7bbb36f4345bf059635fb6d04d0fb369ca42338e - with: - python-version: 3.13 - uses: launchbynttdata/actions-asdf-install_tools@v0 - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd From 4245d7bb66511ef86d4d52a413c38c92a30a2e5b Mon Sep 17 00:00:00 2001 From: Chris Taylor Date: Wed, 25 Jun 2025 15:38:47 -0500 Subject: [PATCH 3/5] Add uv hook --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3467417..fd0ab6c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,8 @@ repos: + - repo: https://github.com/astral-sh/uv-pre-commit + rev: ac44eab0cf35cf4268a18f1e7c20e0980550d6fa # 0.7.15 + hooks: + - id: uv-lock - repo: https://github.com/pre-commit/pre-commit-hooks rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # v5.0.0 hooks: From b4f4bbb844c7fdfa8342656d07cf614d6d56e455 Mon Sep 17 00:00:00 2001 From: Chris Taylor Date: Wed, 25 Jun 2025 17:39:57 -0500 Subject: [PATCH 4/5] Install python through cacheable action, exclude from asdf install --- .github/workflows/python-tests.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index a85080a..d7ca44a 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -19,10 +19,16 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f - - uses: launchbynttdata/actions-asdf-install_tools@v0 + - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 + with: + python-version: '3.13' + - uses: launchbynttdata/actions-asdf-install_tools@feature/exclude-tools + with: + exclude_tools: "python" - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd run-tests: + needs: [ pre-commit ] runs-on: ubuntu-latest strategy: matrix: From a775884162a6531dfaff49a7fb04b84b2cc0d434 Mon Sep 17 00:00:00 2001 From: Chris Taylor Date: Wed, 25 Jun 2025 17:43:03 -0500 Subject: [PATCH 5/5] Tests only on PR update to avoid double-runs --- .github/workflows/python-tests.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index d7ca44a..2c2b74c 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -1,11 +1,6 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - name: Python Tests on: - push: - branches-ignore: [ "main" ] pull_request: branches: [ "**" ]