[DRAFT] CI test #39
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: | |
- develop | |
pull_request: | |
branches: | |
- develop | |
env: | |
HASH_SEEDS: pdm.lock docker/bin/* docker/conf/* docker/Dockerfile | |
DOCKER_CACHE_IMAGE: ${{ vars.DOCKERHUB_ORGANIZATION }}/hope-support-images | |
BUILD_DATE: $(date +"%Y-%m-%d %H:%M") | |
jobs: | |
build: | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: DockerHub login | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Check Dev Image | |
continue-on-error: true | |
id: image_exists | |
run: | | |
set +e | |
LOCK_SHA=$(echo sha1sum ${{env.HASH_SEEDS}}| sha1sum | awk '{print $1}' | cut -c 1-8) | |
exists=$(docker manifest inspect ${DOCKER_CACHE_IMAGE}:${LOCK_SHA} > /dev/null 2>&1 && echo "exists" || echo "not_found") | |
echo "result=$exists" >> "$GITHUB_OUTPUT" | |
echo "SHA=$LOCK_SHA" >> "$GITHUB_OUTPUT" | |
if [ $exists = "exists" ];then | |
echo "Tag ${{ steps.image_exists.outputs.SHA }} found" | |
else | |
echo "Tag ${{ steps.image_exists.outputs.SHA }} does not exist" | |
fi | |
- name: Build Dev Image | |
if: ${{ steps.image_exists.outputs.result == 'not_found' || contains(github.event.head_commit.message, 'rebuild') }} | |
run: | | |
LOCK_SHA=${{ steps.image_exists.outputs.SHA }} | |
docker buildx create --use --platform x86_64 --name builder --driver docker-container | |
docker buildx build \ | |
--platform x86_64 \ | |
--builder builder \ | |
--build-arg BUILD_DATE="${BUILD_DATE}" \ | |
--progress=plain \ | |
--cache-to type=local,ref=${DOCKER_CACHE_IMAGE}:hde-dev-latest,dest=./.AAA \ | |
--cache-from ${DOCKER_CACHE_IMAGE}:hde-dev-latest \ | |
-t ${DOCKER_CACHE_IMAGE}:hde-dev-${LOCK_SHA} \ | |
-t ${DOCKER_CACHE_IMAGE}:hde-dev-latest \ | |
-f ./docker/Dockerfile \ | |
--push \ | |
--target python_dev_deps . | |
lint: | |
runs-on: ubuntu-20.04 | |
needs: [build] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: DockerHub login | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Pull | |
run: docker pull ${DOCKER_CACHE_IMAGE}:hde-dev-latest | |
- name: Black | |
run: docker run --rm -it -v .:/hde/src/ -t ${DOCKER_CACHE_IMAGE}:hde-dev-latest black --check ./src/ | |
- name: Flake8 | |
run: docker run --rm -it -v .:/hde/src/ -t ${DOCKER_CACHE_IMAGE}:hde-dev-latest flake8 src/ | |
# - name: pre-commit | |
# run: docker run --rm -it -v .:/hde/src/ -t ${DOCKER_IMAGE_DEV}:latest pre-commit run --all-files | |
test: | |
runs-on: ubuntu-20.04 | |
needs: [build] | |
services: | |
redis: | |
image: redis | |
db: | |
image: postgres:14 | |
env: | |
POSTGRES_DATABASE: dedupe | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_USERNAME: postgres | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
env: | |
DATABASE_URL: postgres://postgres:postgres@db:5432/dedupe | |
PYTHONPATH: /hde/code/src/ | |
SECRET_KEY: secret-key | |
CACHE_URL: redis://redis:6379/0 | |
CELERY_BROKER_URL: redis://redis:6379/0 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: DockerHub login | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Pull | |
run: docker pull ${DOCKER_CACHE_IMAGE}:hde-dev-latest | |
- name: Run tests | |
run: | | |
docker run --rm -it \ | |
-v .:/hde/code/ \ | |
-w /hde/code/ \ | |
-t ${DOCKER_CACHE_IMAGE}:hde-dev-latest pytest tests/ --create-db -v --cov --cov-report xml:coverage.xml | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v4 | |
with: | |
directory: ./coverage/reports/ | |
env_vars: OS,PYTHON | |
fail_ci_if_error: true | |
files: /hde/code/coverage1.xml | |
flags: unittests | |
name: codecov-umbrella | |
token: ${{ secrets.CODECOV_TOKEN }} | |
verbose: true |