diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 57d5ebe..35ddd8a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,33 +1,75 @@ -name: deploy to lambda -on: [push] +name: Deploy Python Lambda + +on: + push: + branches: + - main + jobs: - deploy_source: - name: build and deploy lambda + deploy: + name: deploy + runs-on: ubuntu-latest + env: + NODE_VERSION: 14.x # used for installing the serverless-python-requirements dependency from NPM strategy: matrix: - node-version: [12.x] - runs-on: ubuntu-latest + python-version: + - 3.12 # with a build matrix, you can specify a list of python versions to deploy with steps: - - uses: actions/checkout@v1 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 + # --------- use Python to install Python dependencies and run linter, tests, etc. --------- + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 with: - node-version: ${{ matrix.node-version }} - - name: npm install and build + python-version: ${{ matrix.python-version }} + + - name: Cache pip + uses: actions/cache@v2 + with: + # This path is specific to Ubuntu + path: ~/.cache/pip + # Look to see if there is a cache hit for the corresponding requirements file + key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + - name: Install dependencies run: | - npm ci - npm run build --if-present - env: - CI: true - - name: zip - uses: montudor/action-zip@v0.1.0 + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + + # --------- Use Node and NPM to install serverless-python-requirements --------- + - name: Use Node.js ${{ env.NODE_VERSION }} + uses: actions/setup-node@v1 with: - args: zip -qq -r ./bundle.zip ./ - - name: default deploy - uses: appleboy/lambda-action@master + node-version: ${{ env.NODE_VERSION }} + + - name: Cache node modules + uses: actions/cache@v2 + env: + cache-name: cache-node-modules with: - aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws_region: eu-west-1 - function_name: my-function - zip_file: bundle.zip + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + - name: Install Node dependencies (specifically, serverless-python-requirements) + run: npm install + + - name: Serverless Deploy + uses: dhollerbach/github-action-serverless-with-python-requirements@master + env: + # SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }} + # or if using AWS credentials directly + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}