flask/.github/workflows/flaskr-ci.yaml
2023-02-23 14:33:21 -05:00

59 lines
2 KiB
YAML

name: Build and Test
on:
workflow_dispatch: # Enables manually running the workflow
push:
# pull_request:
# branches:
# - main
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11.x'
architecture: 'x64'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
# Install project file for flaskr app
pip install -e examples/tutorial
- name: Lint with flake8
run: |
cd examples/tutorial
# 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
- name: Test with pytest
run: |
cd examples/tutorial
pytest
# Build Docker image in a separate job so that it's not taited by cached python build/test files
build-image:
needs: tests
permissions:
# Required permission to push images with the built-in GITHUB_TOKEN
packages: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set job vars
id: vars
run: echo "sha_short=${GITHUB_SHA:0:10}" >> $GITHUB_OUTPUT
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image and push to GHCR
uses: docker/build-push-action@v4
with:
context: examples/tutorial
push: true
tags: "ghcr.io/${{ github.repository }}:${{ steps.vars.outputs.sha_short }}"