Skip to content

Instantly share code, notes, and snippets.

@merltron-pa
Last active June 8, 2020 11:53
Show Gist options
  • Save merltron-pa/f41c3606efa3ca2b63a677986f6018c8 to your computer and use it in GitHub Desktop.
Save merltron-pa/f41c3606efa3ca2b63a677986f6018c8 to your computer and use it in GitHub Desktop.
name: CI
on:
push:
branches:
- '**'
jobs:
tests:
name: Tests
runs-on: ubuntu-latest
services:
backend-db:
image: postgres:12.1
env:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: backend_db
ports:
- 5432:5432
backend-gcloud-pubsub:
image: 'knarz/pubsub-emulator'
ports:
- '8085:8085'
steps:
- name: Checkout working branch
uses: actions/checkout@v1
- name: Setup ssh
run: |
mkdir ~/.ssh/
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
touch ~/.ssh/known_hosts
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install PostgreSQL 11 client
run: |
sudo apt-get -yqq install libpq-dev
- name: Cache Poetry
uses: actions/cache@v1
id: cache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies, config poetry virtualenv
run: |
python -m pip install --upgrade pip
pip install poetry
poetry config virtualenvs.create false
poetry install --no-interaction
- name: Lint with flake8
run: |
pip install flake8
# 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: Install gettext for translations
run: |
sudo apt-get update && sudo apt-get install -y gettext
- name: Test with pytest
run: |
python manage.py compilemessages
pytest --verbose
env:
CLUSTER_ENV: test
RUN_DEV: 0
POSTGRES_DB: backend_db
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB_PORT: 5432
POSTGRES_DB_HOST: localhost
SECRET_KEY: thisisasecret
SENDGRID_API_KEY: 'test-key'
PUBSUB_EMULATOR_HOST: localhost:8085
GCLOUD_PUBSUB_PROJECT_ID: 'test-project'
HERBIE_TOKEN: 'random-key'
HERBIE_HOST: 'http://localhost:8000'
docker-image:
name: Build & Publish Docker Image
needs: [tests]
runs-on: ubuntu-latest
steps:
- name: Checkout working branch
uses: actions/checkout@v1
- name: Set Docker Registry
run: echo ::set-env name=DOCKER_REGISTRY::eu.gcr.io
- name: Set Docker Image
run: echo ::set-env name=DOCKER_IMAGE::${{ env.DOCKER_REGISTRY }}/acme-555555/backend
- uses: actions/checkout@v1
- name: Login to gcloud registry
id: gcloud
uses: elgohr/gcloud-login-action@0.2
with:
account_key: ${{ secrets.GCLOUD_KEY }}
- name: Publish Docker Image
uses: elgohr/Publish-Docker-Github-Action@2.14
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
with:
name: ${{ env.DOCKER_IMAGE }}
username: ${{ steps.gcloud.outputs.username }}
password: ${{ steps.gcloud.outputs.password }}
registry: ${{ env.DOCKER_REGISTRY }}
buildargs: SSH_PRIVATE_KEY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment