Merge pull request #128 from JSv4/JSv4/v2-bugfixes #280
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: Backend CI | |
# Enable Buildkit and let compose use it to speed up image building | |
env: | |
DOCKER_BUILDKIT: 1 | |
COMPOSE_DOCKER_CLI_BUILD: 1 | |
SKLEARN_ALLOW_DEPRECATED_SKLEARN_PACKAGE_INSTALL: True | |
defaults: | |
run: | |
working-directory: ./ | |
on: | |
pull_request: | |
branches: [ "master", "main" ] | |
paths-ignore: [ "docs/**" ] | |
push: | |
branches: [ "master", "main" ] | |
paths-ignore: [ "docs/**" ] | |
concurrency: | |
group: ${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
jobs: | |
linter: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Free Disk Space (Ubuntu) | |
uses: jlumbroso/free-disk-space@main | |
with: | |
# this might remove tools that are actually needed, | |
# if set to "true" but frees about 6 GB | |
tool-cache: false | |
# all of these default to true, but feel free to set to | |
# "false" if necessary for your workflow | |
android: false | |
dotnet: false | |
haskell: false | |
large-packages: true | |
docker-images: true | |
swap-storage: true | |
- name: Checkout Code Repository | |
uses: actions/[email protected] | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
cache: pip | |
cache-dependency-path: | | |
requirements/base.txt | |
requirements/local.txt | |
- name: Run pre-commit | |
uses: pre-commit/[email protected] | |
# With no caching at all the entire ci process takes 4m 30s to complete! | |
pytest: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Free Disk Space (Ubuntu) | |
uses: jlumbroso/free-disk-space@main | |
with: | |
# this might remove tools that are actually needed, | |
# if set to "true" but frees about 6 GB | |
tool-cache: false | |
# all of these default to true, but feel free to set to | |
# "false" if necessary for your workflow | |
android: false | |
dotnet: false | |
haskell: false | |
large-packages: true | |
docker-images: true | |
swap-storage: true | |
- name: Checkout Code Repository | |
uses: actions/[email protected] | |
- name: Store Codecov Env Flags | |
run: | | |
# use bash variable expression to get the substring | |
ci_env=`bash <(curl -s https://codecov.io/env)` | |
echo "$ci_env" | |
- name: Build the Stack | |
run: docker-compose -f test.yml build | |
- name: Run DB Migrations | |
run: docker-compose -f test.yml run --rm django python manage.py migrate | |
- name: Collect Static Files | |
run: docker-compose -f test.yml run --rm django python manage.py collectstatic | |
- name: Verify Docker Containers | |
run: | | |
docker-compose -f test.yml ps | |
- name: Inspect Docker Network | |
run: | | |
docker network inspect $(docker-compose -f test.yml ps -q | xargs docker inspect --format='{{range .NetworkSettings.Networks}}{{.NetworkID}}{{end}}' | uniq) | |
- name: Capture Docker Compose Logs | |
if: failure() | |
run: | | |
docker-compose -f test.yml logs --no-color > docker-compose-logs.txt | |
- name: Upload Docker Compose Logs | |
if: failure() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: docker-compose-logs | |
path: docker-compose-logs.txt | |
- name: Build Pytest Coverage File | |
run: | | |
docker-compose -f test.yml run django coverage run -m pytest --cov-report=xml --cov | |
- name: Upload Coverage Reports to Codecov | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
COMMIT_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || env.GITHUB_SHA }} | |
run: | | |
# use bash variable expression to get the substring | |
ci_env=`bash <(curl -s https://codecov.io/env)` | |
docker-compose -f test.yml run $ci_env django /bin/codecov -v -t ${CODECOV_TOKEN} -R . -f coverage.xml -C ${COMMIT_SHA} | |
- name: Tear down the Stack | |
run: docker-compose -f test.yml down |