Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IT-3241] Copy coverage and periodic changes #11

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[run]
relative_files = True

# Use 'source' instead of 'omit' in order to ignore 'tests/unit/__init__.py'
source = restrict_download_region
2 changes: 2 additions & 0 deletions .github/actions/sam-build/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ runs:
python-version: 3.9
- run: pip install -U pipenv
shell: bash

# This needs to be in the 'CodeUri' directory
- run: pipenv requirements > requirements.txt
shell: bash

Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/periodic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: periodic

on:
# Run once a month
schedule:
- cron: '30 16 15 * *' # 16:30 UTC (9:30 PST) on the 15th of the month

jobs:
# Check that our current dependencies still work
dependency-check:
uses: "./.github/workflows/test.yaml"
2 changes: 1 addition & 1 deletion .github/workflows/post-merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
with:
aws-region: us-east-1
role-to-assume: arn:aws:iam::745159704268:role/sagebase-github-oidc-lambda-template-deploy-sageit
role-session-name: GHA-${{ github.event.repository.name }}-${{ github.run_id }} # must not exceed 64 chars
role-session-name: GHA-${{ github.event.repository.name }}-${{ github.run_id }} # Must not exceed 64 chars
role-duration-seconds: 900

# upload the lambda artifact to s3 and generate a cloudformation template referencing it
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ jobs:
python-version: 3.9
- run: pip install -U pipenv
- run: pipenv install --dev
- run: pipenv run python3 -m pytest tests/ -vv
- run: pipenv run coverage run -m pytest tests/ -svv
- name: upload coverage to coveralls
uses: coverallsapp/github-action@v2

sam-build-and-lint:
runs-on: ubuntu-latest
Expand Down
12 changes: 6 additions & 6 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pytest = "~=6.0.1"
pytest-mock = "~=3.3.1"
pre-commit = "~=2.15.0"
aws-sam-cli = "~=1.35.0"
awscli = "~=1.22.5"
autopep8 = "*"
pytest = "~=6.0"
pytest-mock = "~=3.3"
pre-commit = "~=2.15"
aws-sam-cli = "~=1.35"
awscli = "~=1.22"
coverage = "~=7.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think this project needs autopep8?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, I'm not even sure why it was here to begin with


[requires]
python_version = "3.9"
1,439 changes: 1,139 additions & 300 deletions Pipfile.lock

Large diffs are not rendered by default.

51 changes: 46 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,70 @@ This Lambda is being used as a AWS Custom Resource, but it is **not a singleton
### Contributions
Contributions are welcome.

### Requirements
### Setup Development Environment

Install the following applications:
* [AWS CLI](https://github.com/aws/aws-cli)
* [AWS SAM CLI](https://github.com/aws/aws-sam-cli)
* [pre-commit](https://github.com/pre-commit/pre-commit)
* [pipenv](https://github.com/pypa/pipenv)

### Install Requirements

Run `pipenv install --dev` to install both production and development
requirements, and `pipenv shell` to activate the virtual environment. For more
information see the [pipenv docs](https://pipenv.pypa.io/en/latest/).

After activating the virtual environment, run `pre-commit install` to install
the [pre-commit](https://pre-commit.com/) git hook.

### Update Requirements

First, make any needed updates to the base requirements in `Pipfile`, then use
`pipenv` to regenerate both `Pipfile.lock` and `requirements.txt`.

```shell script
$ pipenv update --dev
```

We use `pipenv` to control versions in testing, but `sam` relies on
`requirements.txt` directly for building the lambda artifact, so we dynamically
generate `requirements.txt` from `Pipfile.lock` before building the artifact.
The file must be created in the `CodeUri` directory specified in
`template.yaml`.

```shell script
$ pipenv requirements > requirements.txt
```

Additionally, `pre-commit` manages its own requirements.

```shell script
$ pre-commit autoupdate
```

### Create a local build

Use a Lambda-like docker container to build the Lambda artifact

```shell script
sam build
$ sam build --use-container
```

### Run unit tests
Tests are defined in the `tests` folder in this project. Use PIP to install the
[pytest](https://docs.pytest.org/en/latest/) and run unit tests.

Tests are defined in the `tests` folder in this project, and dependencies are
managed with `pipenv`. Install the development dependencies and run the tests
using `coverage`.

```shell script
python -m pytest tests/ -vv
$ pipenv run coverage run -m pytest tests/ -svv
```

Automated testing will upload coverage results to [Coveralls](coveralls.io).

### Run integration tests

Running integration tests
[requires docker](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-start-api.html)

Expand Down