Skip to content

Commit

Permalink
Merge pull request #234 from camptocamp/github-actions
Browse files Browse the repository at this point in the history
GitHub actions
  • Loading branch information
arnaud-morvan authored Oct 5, 2022
2 parents f4d578c + b9ed2f4 commit d616e58
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 81 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---

name: Continuous integration

on:
push:

jobs:
main:
name: Continuous integration
runs-on: ubuntu-18.04
timeout-minutes: 60
env:
TX_USR: ${{ secrets.TX_USR }}
TX_PWD: ${{ secrets.TX_PWD }}
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
steps:
- name: Install packages
run: sudo apt-get install -y gettext python3-virtualenv
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 10
- name: Build
run: make build
- name: Lint
run: make check
- name: Tests
run: make test
- name: Docker compose logs
if: always()
run: |
docker-compose logs
docker-compose down -v --remove-orphans
- name: Deploy PyPI
if: >
github.repository == 'camptocamp/c2cgeoform'
&& success()
&& (
startsWith(github.ref, 'refs/tags/')
)
run: |
sudo python3 -m pip install twine wheel
scripts/deploy-pypi
49 changes: 0 additions & 49 deletions .travis.yml

This file was deleted.

15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ help:
@echo

.PHONY: build
build: .build/requirements.timestamp compile-catalog c2cgeoform/static/dist/index.js
build: docker-build-db .build/requirements.timestamp compile-catalog c2cgeoform/static/dist/index.js

.PHONY: check
check: flake8 check_c2cgeoform_demo
Expand All @@ -64,10 +64,12 @@ test: test_c2cgeoform test_c2cgeoform_demo

.PHONY: test_c2cgeoform
test_c2cgeoform: build .build/requirements-dev.timestamp
docker-compose up -d db
$(VENV_BIN)/nosetests --ignore-files=test_views.py

.PHONY: test_c2cgeoform_demo
test_c2cgeoform_demo: $(BUILD_DIR)/c2cgeoform_demo
docker-compose up -d db
make -C $(BUILD_DIR)/c2cgeoform_demo -f ./dev.mk test

$(BUILD_DIR)/c2cgeoform_demo: build c2cgeoform/scaffolds/c2cgeoform c2cgeoform_demo_dev.mk
Expand Down Expand Up @@ -102,14 +104,15 @@ prettier:

.build/venv.timestamp:
# Create a Python virtual environment.
virtualenv $(PYTHON3) .build/venv
python3 -m venv .build/venv
# Upgrade packaging tools.
$(VENV_BIN)/$(PIP_UPGRADE)
$(VENV_BIN)/pip install wheel # Avoid error when building wheels
touch $@

.build/requirements.timestamp: .build/venv.timestamp setup.py requirements.txt
$(VENV_BIN)/pip install -r requirements.txt
# Workaround before upgrading to Pyramid 2 and cookiecutter
$(VENV_BIN)/pip install -r requirements.txt "pyramid<2"
$(VENV_BIN)/pip install -e .
touch $@

Expand Down Expand Up @@ -143,3 +146,9 @@ serve: build $(BUILD_DIR)/c2cgeoform_demo
.PHONY: modwsgi
modwsgi: $(BUILD_DIR)/c2cgeoform_demo
make -C $(BUILD_DIR)/c2cgeoform_demo modwsgi


# Docker builds

docker-build-db:
docker build -t camptocamp/c2cgeoform-db:latest db
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class Excavation(Base):
# to show a map for a geometry column, the column has to be defined as
# follows.
location_position = Column(
geoalchemy2.Geometry('POINT', 4326, management=True), info={
geoalchemy2.Geometry('POINT', 4326, management=False), info={
'colanderalchemy': {
'title': _('Position'),
'typ':
Expand Down Expand Up @@ -304,7 +304,7 @@ class Excavation(Base):

# Work footprint
work_footprint = Column(
geoalchemy2.Geometry('MULTIPOLYGON', 4326, management=True),
geoalchemy2.Geometry('MULTIPOLYGON', 4326, management=False),
info={
'colanderalchemy': {
'title': _('Footprint for the Work'),
Expand Down Expand Up @@ -364,7 +364,7 @@ class BusStop(Base):

id = Column(BigInteger, primary_key=True)
name = Column(Text)
geom = Column(geoalchemy2.Geometry('POINT', 4326, management=True))
geom = Column(geoalchemy2.Geometry('POINT', 4326, management=False))


class Comment(Base):
Expand Down
2 changes: 1 addition & 1 deletion c2cgeoform/scaffolds/c2cgeoform/Makefile_tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ dist: .build/venv.timestamp compile-catalog

.build/venv.timestamp:
# Create a Python virtual environment.
virtualenv $(PYTHON3) .build/venv
python3 -m venv .build/venv
# Upgrade packaging tools.
$(VENV_BIN)/$(PIP_UPGRADE)
touch $@
Expand Down
2 changes: 1 addition & 1 deletion c2cgeoform/scaffolds/c2cgeoform/tests.ini_tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pyramid.includes =
pyramid_debugtoolbar
pyramid_tm

sqlalchemy.url = postgresql://www-data:www-data@localhost:5432/{{package}}_tests
sqlalchemy.url = postgresql://www-data:www-data@localhost:54321/{{package}}_tests

# By default, the toolbar only appears for clients from IP addresses
# '127.0.0.1' and '::1'.
Expand Down
21 changes: 20 additions & 1 deletion c2cgeoform/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import os
import time
import unittest
from pyramid import testing
from pyramid.paster import get_appsettings
from sqlalchemy import engine_from_config
from sqlalchemy import engine_from_config, text
from webob.multidict import MultiDict

from c2cgeoform.models import (DBSession, Base)
from c2cgeoform.settings import apply_local_settings
from c2cgeoform import init_deform


def wait_for_db(engine):
sleep_time = 1
max_sleep = 30
while sleep_time < max_sleep:
try:
with engine.connect() as connection:
connection.execute(text("SELECT 1;"))
return
except Exception as e:
print(str(e))
print("Waiting for the DataBase server to be reachable")
time.sleep(sleep_time)
sleep_time *= 2
exit(1) # noqa


class DatabaseTestCase(unittest.TestCase):
def setUp(self): # noqa
curdir = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -20,6 +37,8 @@ def setUp(self): # noqa
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)

wait_for_db(engine)

from .models_test import Person, EmploymentStatus, Tag # noqa
Base.metadata.create_all(engine)
self.cleanup()
Expand Down
3 changes: 3 additions & 0 deletions db/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM camptocamp/postgres:12

COPY docker-entrypoint-initdb.d /docker-entrypoint-initdb.d
1 change: 1 addition & 0 deletions db/docker-entrypoint-initdb.d/01-createdb.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE EXTENSION postgis;
17 changes: 17 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---

# The project Docker compose file for development.

version: '2.3'

services:

db:
image: camptocamp/c2cgeoform-db:latest
restart: unless-stopped
environment:
- POSTGRES_USER=www-data
- POSTGRES_PASSWORD=www-data
- POSTGRES_DB=c2cgeoform_demo_tests
ports:
- "54321:5432"
27 changes: 27 additions & 0 deletions scripts/deploy-pypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash -ex

if [[ "${GITHUB_ACTIONS}" == "true" ]]
then
if [[ "${GITHUB_REF}" =~ ^refs/tags/.* ]]
then
GIT_TAGS=$(echo "${GITHUB_REF}"|sed 's|^refs/tags/||g')
elif [[ "${GITHUB_REF}" =~ ^refs/heads/.* ]]
then
GIT_BRANCH=$(echo "${GITHUB_REF}"|sed 's|^refs/heads/||g')
fi
else
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`
GIT_TAGS=`git tag --points-at HEAD`
fi

function deploy_pypi {
make compile-catalog
VERSION=$1 python3 setup.py egg_info sdist bdist_wheel
twine upload dist/*
}

# Deploy tags
for GIT_TAG in ${GIT_TAGS}
do
deploy_pypi $GIT_TAG
done
2 changes: 1 addition & 1 deletion tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pyramid.default_locale_name = en
pyramid.includes =
pyramid_debugtoolbar

sqlalchemy.url = postgresql://www-data:www-data@localhost:5432/c2cgeoform_demo_tests
sqlalchemy.url = postgresql://www-data:www-data@localhost:54321/c2cgeoform_demo_tests

# By default, the toolbar only appears for clients from IP addresses
# '127.0.0.1' and '::1'.
Expand Down
22 changes: 0 additions & 22 deletions travis/deploy-pypi

This file was deleted.

0 comments on commit d616e58

Please sign in to comment.