Skip to content

Commit

Permalink
Merge GitHub Actions to lint, test and build and push Docker image.
Browse files Browse the repository at this point in the history
  • Loading branch information
edonosotti committed Jan 2, 2021
1 parent fd8bed2 commit a20403f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 57 deletions.
29 changes: 25 additions & 4 deletions .github/workflows/docker_build_push.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
# Taken from: https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-python
# and: https://docs.github.com/en/free-pro-team@latest/actions/guides/publishing-docker-images
# and adapted. More info on workflow syntax: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions
name: Build and push Docker image upon release
name: Lint the code, run tests, build and push Docker image

on:
# Build and push Docker images *only* for releases.
push:
# Match all branches *without* a / in the name.
# This will exclude "sub" branches, such as "feature branches",
# named something like: "feature/my-feature". Those branches will
# likely contain "work in progress" code, so we will run the tests
# on the local machine and avoid using up GitHub Actions credits
# (if applicable, such as in `private` repositories).
# Filter syntax info: https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
branches:
- '*'
pull_request:
# Since pull requests come from "third parties", we will automatically
# test everything coming from the outside world, for good measure.
# The `branches` tag could also be omitted, yielding the same effect here.
branches:
- '**'
release:
types: [published] # , created, edited
types: [published, created, edited]

jobs:
# Run code tests before building the image, to ensure it is good to go
Expand All @@ -23,30 +38,36 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint the code 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
- name: Test with unittest
run: |
python -m unittest discover
# Build and push the Docker image
push_to_registry:
name: Build and push Docker image to Docker Hub
# ...but only when a `release` is `published`
if: github.event_name == 'release' && github.event.action == 'published'
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v2
# if: ${{ github.ref == 'ref/head/master' }} # Info: https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions#about-contexts-and-expressions
- name: Push to Docker Hub

- name: Build and push image to the Docker Hub
uses: docker/build-push-action@v1 # Info: https://github.com/docker/build-push-action/tree/releases/v1#tags
# if: ${{ github.ref == 'ref/head/master' }}
with:
Expand Down
53 changes: 0 additions & 53 deletions .github/workflows/run_tests.yml

This file was deleted.

0 comments on commit a20403f

Please sign in to comment.