From 69c78aa3c06fa9a923417ba413ee19e2ac7cf219 Mon Sep 17 00:00:00 2001 From: "TeranGmoravian.edu" Date: Thu, 13 Feb 2025 22:21:06 -0500 Subject: [PATCH 01/11] Added Linter File --- lint.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lint.sh diff --git a/lint.sh b/lint.sh new file mode 100644 index 0000000..7d3755c --- /dev/null +++ b/lint.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Lint Python files with flake8 +echo "Running flake8..." +flake8 endpoints/ || exit 1 + +echo "Running black (format check)..." +black --check endpoints/ || exit 1 + +# Lint YAML files (AWS SAM and configs) +echo "Running yamllint..." +yamllint template.yml || exit 1 +yamllint samconfig.toml || exit 1 + +echo "All lint checks passed!" + +# To run linting before each commit, add this script to .git/hooks/pre-commit +# and make it executable with the following command: +# chmod +x .git/hooks/pre-commit + From e385a05dc11ae7730e921eb061e654aa428c1df1 Mon Sep 17 00:00:00 2001 From: "TeranGmoravian.edu" Date: Fri, 14 Feb 2025 14:49:34 -0500 Subject: [PATCH 02/11] Added pull request linting and tests --- .github/workflows/ci.yml | 39 +++++++++++++++++++++++++++++++++++++++ tests/test_app.py | 7 +++++++ 2 files changed, 46 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 tests/test_app.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6df3a69 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +name: CI Checks + +on: + pull_request: + branches: + - main # Runs on pull requests targeting main + +jobs: + lint-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.13' # Ensure this matches your runtime + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 black pytest yamllint + + - name: Run flake8 (Python linting) + run: flake8 endpoints/ + + - name: Run black (Code formatting check) + run: black --check endpoints/ + + - name: Run yamllint (YAML validation) + run: | + yamllint template.yml + yamllint samconfig.toml + + - name: Run unit tests + run: pytest tests/ + diff --git a/tests/test_app.py b/tests/test_app.py new file mode 100644 index 0000000..52cb324 --- /dev/null +++ b/tests/test_app.py @@ -0,0 +1,7 @@ +import pytest +from endpoints.app import test_handler + +def test_dummy(): + assert test_handler({}, {}) == {"statusCode": 200, "body": "Hello, world!"} + + From 5e38e28cbadd3023d8550d5b93e6467c943e4847 Mon Sep 17 00:00:00 2001 From: "TeranGmoravian.edu" Date: Fri, 14 Feb 2025 14:54:49 -0500 Subject: [PATCH 03/11] Test workflow --- .github/workflows/github-actions.yml | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 .github/workflows/github-actions.yml diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml deleted file mode 100644 index 69f6d37..0000000 --- a/.github/workflows/github-actions.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: GitHub Actions AWS connection -run-name: ${{ github.actor }} triggered the Github actions -on: [push] - -jobs: - Explore-GitHub-Actions: - runs-on: ubuntu-latest - steps: - - - run: echo "The job was automatically triggered by a ${{ github.event_name }} event." - - run: echo "This job is now running on a ${{ runner.os }} server hosted by GitHub!" - - run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - - name: Check out repository code - uses: actions/checkout@v4 - - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v3 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: us-east-1 - - name: Test AWS CLI connectivity - run: | - echo "Your ARN is: $(aws sts get-caller-identity --query Arn --output text)" - - name: Deploy with SAM - run: | - sam deploy --config-file samconfig.toml --config-env prod --resolve-s3 --no-confirm-changeset --no-fail-on-empty-changeset - - run: echo "This job's status is ${{ job.status }}." From 92e94ecaa49f02f2f372c46fac6df6cf287d727a Mon Sep 17 00:00:00 2001 From: "TeranGmoravian.edu" Date: Fri, 14 Feb 2025 14:58:41 -0500 Subject: [PATCH 04/11] reset to main --- .github/workflows/ci.yml | 39 ---------------------------- .github/workflows/github-actions.yml | 32 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 39 deletions(-) delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/github-actions.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 6df3a69..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: CI Checks - -on: - pull_request: - branches: - - main # Runs on pull requests targeting main - -jobs: - lint-and-test: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.13' # Ensure this matches your runtime - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 black pytest yamllint - - - name: Run flake8 (Python linting) - run: flake8 endpoints/ - - - name: Run black (Code formatting check) - run: black --check endpoints/ - - - name: Run yamllint (YAML validation) - run: | - yamllint template.yml - yamllint samconfig.toml - - - name: Run unit tests - run: pytest tests/ - diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml new file mode 100644 index 0000000..64e4135 --- /dev/null +++ b/.github/workflows/github-actions.yml @@ -0,0 +1,32 @@ +name: GitHub Actions AWS connection +run-name: ${{ github.actor }} triggered the Github actions +on: [push] + +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + + - run: echo "The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v3 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - name: Test AWS CLI connectivity + run: | + echo "Your ARN is: $(aws sts get-caller-identity --query Arn --output text)" + + - name: Deploy with SAM + run: | + sam deploy --config-file samconfig.toml --config-env default --resolve-s3 --no-confirm-changeset --no-fail-on-empty-changeset + + - run: echo "This job's status is ${{ job.status }}." From 77bc6250e3ac1d2465a11c208f3b70bf17c6c1b4 Mon Sep 17 00:00:00 2001 From: "TeranGmoravian.edu" Date: Fri, 14 Feb 2025 15:04:44 -0500 Subject: [PATCH 05/11] Change readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b329846..d064c9e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # API -## How to run the API for testing +## How to Run the API for Testing ### Installing AWS and SAM - Install the AWS CLI and configure your credentials. (We did this in class, but if needed, the process is detailed [here](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/prerequisites.html)). From a6e06fbf44d44bc735c183a7459871549a724ac8 Mon Sep 17 00:00:00 2001 From: "TeranGmoravian.edu" Date: Fri, 14 Feb 2025 15:16:21 -0500 Subject: [PATCH 06/11] Made github actons run tests and lint --- .github/workflows/github-actions.yml | 51 ++++++++++++++++++++++++++-- lint.sh => tests/lint.sh | 0 2 files changed, 49 insertions(+), 2 deletions(-) rename lint.sh => tests/lint.sh (100%) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 64e4135..f226b88 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -1,12 +1,58 @@ name: GitHub Actions AWS connection run-name: ${{ github.actor }} triggered the Github actions -on: [push] +on: + pull_request: + branches: + - main # or specify your branch + push: + branches: + - '**' jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Set up Python (for linting tools like flake8, black, yamllint) + uses: actions/setup-python@v2 + with: + python-version: '3.x' # Adjust based on your Python version + + - name: Install linting dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 black yamllint # Install your linting tools + + - name: Run Linting (Python files, YAML files) + run: | + ./test/lint.sh # Run your custom lint script from the test folder + + unit-test: + runs-on: ubuntu-latest + needs: lint # Ensures linting passes before running tests + steps: + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Set up Python (for unit testing) + uses: actions/setup-python@v2 + with: + python-version: '3.x' # Adjust as needed + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt # Adjust based on your setup + + - name: Run unit tests + run: | + pytest test/ # Run your tests from the 'test' folder + Explore-GitHub-Actions: runs-on: ubuntu-latest steps: - - run: echo "The job was automatically triggered by a ${{ github.event_name }} event." - run: echo "This job is now running on a ${{ runner.os }} server hosted by GitHub!" - run: echo "The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." @@ -30,3 +76,4 @@ jobs: sam deploy --config-file samconfig.toml --config-env default --resolve-s3 --no-confirm-changeset --no-fail-on-empty-changeset - run: echo "This job's status is ${{ job.status }}." + diff --git a/lint.sh b/tests/lint.sh similarity index 100% rename from lint.sh rename to tests/lint.sh From 068e1d781303ee4f365acd4d9858efc1380fdb37 Mon Sep 17 00:00:00 2001 From: "TeranGmoravian.edu" Date: Fri, 14 Feb 2025 15:19:13 -0500 Subject: [PATCH 07/11] added permissions --- tests/lint.sh | 0 tests/test_app.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 tests/lint.sh mode change 100644 => 100755 tests/test_app.py diff --git a/tests/lint.sh b/tests/lint.sh old mode 100644 new mode 100755 diff --git a/tests/test_app.py b/tests/test_app.py old mode 100644 new mode 100755 From e81a6d2592932b64465b227d37a4b4751dba8d40 Mon Sep 17 00:00:00 2001 From: "TeranGmoravian.edu" Date: Fri, 14 Feb 2025 15:39:43 -0500 Subject: [PATCH 08/11] Ensure difference in run on pull and push --- .github/workflows/github-actions.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index f226b88..bc351bd 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -1,16 +1,18 @@ name: GitHub Actions AWS connection run-name: ${{ github.actor }} triggered the Github actions + on: pull_request: branches: - - main # or specify your branch + - main # Trigger on PR to the 'main' branch (adjust to your target branch) push: branches: - - '**' + - '**' # Runs on any push to any branch (for Explore-GitHub-Actions) jobs: lint: runs-on: ubuntu-latest + if: github.event_name == 'pull_request' # Ensure linting only runs for PR events steps: - name: Check out repository code uses: actions/checkout@v4 @@ -32,6 +34,7 @@ jobs: unit-test: runs-on: ubuntu-latest needs: lint # Ensures linting passes before running tests + if: github.event_name == 'pull_request' # Ensure unit tests only run for PR events steps: - name: Check out repository code uses: actions/checkout@v4 From 102284448bcbfaf4a08e85193775a55d5f4e9adb Mon Sep 17 00:00:00 2001 From: Davin Glynn <99268114+dg25moravian@users.noreply.github.com> Date: Fri, 14 Feb 2025 15:55:49 -0500 Subject: [PATCH 09/11] Update github-actions.yml changed actions to only run on push to main branch --- .github/workflows/github-actions.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index bc351bd..2208b1a 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -6,8 +6,8 @@ on: branches: - main # Trigger on PR to the 'main' branch (adjust to your target branch) push: - branches: - - '**' # Runs on any push to any branch (for Explore-GitHub-Actions) + branches: + - main # Runs on push to main branch only (for Explore-GitHub-Actions) jobs: lint: From f50ef4a94bdf881b8737c54b9f3d1a83ccce520a Mon Sep 17 00:00:00 2001 From: "TeranGmoravian.edu" Date: Mon, 17 Feb 2025 12:14:44 -0500 Subject: [PATCH 10/11] remove unneeded test sample --- tests/test_app.py | 7 ------- 1 file changed, 7 deletions(-) delete mode 100755 tests/test_app.py diff --git a/tests/test_app.py b/tests/test_app.py deleted file mode 100755 index 52cb324..0000000 --- a/tests/test_app.py +++ /dev/null @@ -1,7 +0,0 @@ -import pytest -from endpoints.app import test_handler - -def test_dummy(): - assert test_handler({}, {}) == {"statusCode": 200, "body": "Hello, world!"} - - From 0e372b79731f5ee743eba92bfc4984295ab14c5f Mon Sep 17 00:00:00 2001 From: "TeranGmoravian.edu" Date: Mon, 17 Feb 2025 12:28:26 -0500 Subject: [PATCH 11/11] lint file with loose rules --- tests/.pylintrc | 37 +++++++++++++++++++++++++++++++++++++ tests/lint.sh | 20 -------------------- 2 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 tests/.pylintrc delete mode 100755 tests/lint.sh diff --git a/tests/.pylintrc b/tests/.pylintrc new file mode 100644 index 0000000..95863f2 --- /dev/null +++ b/tests/.pylintrc @@ -0,0 +1,37 @@ +[MASTER] +# Set the Python version +py-version=3.13 + +[MESSAGES CONTROL] +disable= + missing-docstring, + invalid-name, + too-few-public-methods, + too-many-arguments, + too-many-locals, + too-many-branches, + too-many-statements, + too-many-instance-attributes, + duplicate-code + +[BASIC] +good-names=i,j,k,x,y,z,_ + +[FORMAT] +# Set max line length to a loose standard +max-line-length=150 + +[DESIGN] +# Allow higher complexity before warnings +max-attributes=10 +max-args=10 +max-locals=20 +max-returns=10 +max-branches=15 +max-statements=50 + +[TYPECHECK] +disable= + no-member, + no-self-use + diff --git a/tests/lint.sh b/tests/lint.sh deleted file mode 100755 index 7d3755c..0000000 --- a/tests/lint.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# Lint Python files with flake8 -echo "Running flake8..." -flake8 endpoints/ || exit 1 - -echo "Running black (format check)..." -black --check endpoints/ || exit 1 - -# Lint YAML files (AWS SAM and configs) -echo "Running yamllint..." -yamllint template.yml || exit 1 -yamllint samconfig.toml || exit 1 - -echo "All lint checks passed!" - -# To run linting before each commit, add this script to .git/hooks/pre-commit -# and make it executable with the following command: -# chmod +x .git/hooks/pre-commit -