# PJones
# bh83dq
# 10/08/2022
# This workflow will install Python dependencies, run tests and lint with a variety of Python
versions
# It will then zip the lambda function and push it to a pre-determined S3 bucket
name: Python package
on:
push:
branches: [ main ]
jobs:
Code-Analysis-and-Testing:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f [Link] ]; then pip install -r [Link]; fi
pip install twisted --upgrade
pip install jinja2 --upgrade
pip install httplib2 --upgrade
pip install cryptography --upgrade
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 .
- name: Lint with pylint
run: |
# stop the build if there are Python syntax errors or undefined names
pylint *.py
- name: Run Bandit to check for issues around secure code
run: |
# stop the build if there are any nonsecure code in the function (i.e. hardcoded access keys
etc.)
bandit lambda_function.py
- name: Run safety to check for bad packages
run: |
# stop the build if there are any bad or out of date python packages identified
safety check
- name: Run Unit Tests
run: |
# Run the Unit Test file for the function, stopping the build if the unit tests fail
python -m unittest "unit_tests.py"
Package-File-and-Push-to-S3:
needs: Code-Analysis-and-Testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: List the files located in the directory
run: |
ls ${{ [Link] }}
- name: Make the directory
run: |
mkdir -p ./artifacts/${{ [Link] }}
ls ${{ [Link] }}
- name: Create the Zip File
uses: montudor/action-zip@v0.1.0
with:
args: zip -qq -r [Link] lambda_function.py
- name: move the zip file to the artifacts directory
run: mv [Link] ./artifacts
- name: List files in the directory to ensure it has been moved
run:
cd ./artifacts && ls
- name: Push the Zip to S3 Bucket
uses: jakejarvis/s3-sync-action@v0.3.1
env:
SOURCE_DIR: './artifacts/.'
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_S3_BUCKET: ${{ secrets.AWS_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }}
- name: Job Statistics and Results
run: echo "Job complete. The status of the job is - ${{ [Link] }}"