add a few tests #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Lambda | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - "pytest.ini" | |
| - ".pytest.ini" | |
| - "pyproject.toml" | |
| - "pyproject.lock" | |
| - "tests/**" | |
| - "*.py" | |
| - "app/**" | |
| - ".github/workflows/deploy_lambda.yml" | |
| env: | |
| STACK_NAME: api-python | |
| AWS_REGION: us-east-2 | |
| LOGGING_LEVEL: INFO | |
| WORKERS: 1 | |
| jobs: | |
| sam-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| cache: "pytest" | |
| - run: | | |
| python -m pytest | |
| - name: Install and configure Poetry | |
| uses: snok/install-poetry@v1 | |
| with: | |
| version: 1.7.1 | |
| virtualenvs-create: true | |
| - name: Load cached dependencies | |
| id: cached-poetry-dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: .venv | |
| key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} | |
| - name: Install dependencies | |
| if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | |
| run: poetry install --no-interaction | |
| - uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Login to Amazon ECR | |
| uses: aws-actions/amazon-ecr-login@v2 | |
| - name: Generate image tag | |
| id: image-tag | |
| run: | | |
| IMAGE_TAG=$(git rev-parse --short HEAD) | |
| echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV | |
| - name: Get ECR URI | |
| id: ecr-uri | |
| run: | | |
| REPO_URI=$(aws cloudformation describe-stacks \ | |
| --stack-name ${{ env.STACK_NAME }} \ | |
| --query 'Stacks[0].Outputs[?OutputKey==`RepositoryUri`].OutputValue' \ | |
| --output text) | |
| if [ -z "$REPO_URI" ]; then | |
| echo "Failed to get ECR repository URI" | |
| exit 1 | |
| fi | |
| echo "REPO_URI=${REPO_URI}" >> $GITHUB_ENV | |
| - name: Build and push image | |
| run: | | |
| docker build -f deploy/aws_sam/Dockerfile -t ${{ env.REPO_URI }}:${{ env.IMAGE_TAG }} . | |
| docker push ${{ env.REPO_URI }}:${{ env.IMAGE_TAG }} | |
| - uses: aws-actions/setup-sam@v2 | |
| - name: Deploy with SAM | |
| run: | | |
| cd deploy/aws_sam | |
| sam deploy \ | |
| --stack-name ${{ env.STACK_NAME }} \ | |
| --no-confirm-changeset \ | |
| --no-fail-on-empty-changeset \ | |
| --parameter-overrides \ | |
| ImageTag="${{ env.IMAGE_TAG }}" \ | |
| LoggingLevel="${{ env.LOGGING_LEVEL }}" \ | |
| Workers="${{ env.WORKERS }}" \ | |
| PostgresUri="${{ secrets.POSTGRES_URI }}" \ | |
| Neo4jUri="${{ secrets.NEO4J_URI }}" \ | |
| Neo4jPassword="${{ secrets.NEO4J_PASSWORD }}" \ |