2021-12-28 16:21:55 +01:00
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches: [master]
|
|
|
|
|
2021-12-28 16:33:44 +01:00
|
|
|
env:
|
|
|
|
IMAGE_NAME: network_inventory
|
|
|
|
|
2021-12-28 16:21:55 +01:00
|
|
|
jobs:
|
2021-12-28 16:30:49 +01:00
|
|
|
tests:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v2
|
|
|
|
- name: Set up Python 3.9
|
|
|
|
uses: actions/setup-python@v2
|
|
|
|
with:
|
|
|
|
python-version: 3.9
|
|
|
|
- name: Install dependencies
|
|
|
|
run: |
|
|
|
|
python -m pip install --upgrade pip
|
|
|
|
pip install -r requirements/local.txt
|
|
|
|
- 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
|
|
|
|
- name: Test with pytest
|
|
|
|
run: |
|
2022-02-07 23:04:45 +01:00
|
|
|
pytest -nauto --ds=network_inventory.settings.ram_test --nomigrations
|
2021-12-28 16:30:49 +01:00
|
|
|
|
2021-12-28 16:21:55 +01:00
|
|
|
publish:
|
|
|
|
# Ensure test job passes before pushing image.
|
|
|
|
needs: tests
|
|
|
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v2
|
|
|
|
|
2021-12-28 16:30:49 +01:00
|
|
|
- name: "Remove any .pyc files"
|
|
|
|
run: find . \( -name __pycache__ -o -name "*.pyc" \) -delete
|
|
|
|
|
2021-12-28 16:21:55 +01:00
|
|
|
- name: Build image
|
|
|
|
run: docker build . --file Dockerfile --tag $IMAGE_NAME
|
|
|
|
|
|
|
|
- name: Log into registry
|
|
|
|
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
|
|
|
|
|
|
|
|
- name: Push image
|
|
|
|
run: |
|
|
|
|
IMAGE_ID=ghcr.io/${{ github.repository }}/$IMAGE_NAME
|
|
|
|
# Change all uppercase to lowercase
|
|
|
|
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
|
|
|
|
# Strip git ref prefix from version
|
|
|
|
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
|
|
|
|
# Strip "v" prefix from tag name
|
|
|
|
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
|
|
|
|
# Use Docker `latest` tag convention
|
|
|
|
[ "$VERSION" == "main" ] && VERSION=latest
|
|
|
|
echo IMAGE_ID=$IMAGE_ID
|
|
|
|
echo VERSION=$VERSION
|
|
|
|
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
|
|
|
|
docker push $IMAGE_ID:$VERSION
|