diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 93c803f55..000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,136 +0,0 @@ -version: 2 -jobs: - test: - docker: - - image: circleci/python:3.8-buster-node - environment: - SECRET_KEY: testingsecretkey - SECURE_SSL_REDIRECT: false - ALLOWED_HOSTS: localhost - DATABASE_URL: postgresql://root@localhost/circle_test?sslmode=disable - BIRDBATH_REQUIRED: false - - image: cimg/postgres:15.5 # Latest patch version at the time of writing - environment: - POSTGRES_USER: root - POSTGRES_DB: circle_test - POSTGRES_HOST_AUTH_METHOD: trust - working_directory: ~/repo - steps: - - checkout - - restore_cache: - keys: - - dependencies-{{checksum "poetry.lock"}} - - run: - name: install python dependencies - command: | - curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.8.2 python3 - - python -m venv venv - . ./venv/bin/activate - poetry install --no-ansi - - save_cache: - paths: - - ./venv - key: dependencies-{{checksum "poetry.lock"}} - - run: - name: install node dependencies - command: | - npm ci - - run: - name: Linting js - command: | - npm run lint:js - - run: - name: Linting css - command: | - npm run lint:css - - run: - name: Linting format - command: | - npm run lint:format - - run: - name: Front end tests - command: | - npm run test:coverage - - run: - name: compile static assets - command: | - npm run build:prod - - run: - name: Run Django tests - command: | - . venv/bin/activate - pip install coverage - isort --check-only --diff ./rca --skip-glob '**/migrations/*' - ./manage.py collectstatic --verbosity 0 --noinput --clear - ./manage.py makemigrations --check --noinput - ./manage.py check - coverage run ./manage.py test --settings=rca.settings.test - coverage report - coverage xml - bash <(curl -s https://codecov.io/bash) -t $COVERAGE_TOKEN - - run: - name: Run Black - command: | - . venv/bin/activate - black --check --diff ./rca --exclude migrations/ - deploy_dev: - docker: - - image: buildpack-deps:trusty - steps: - - checkout - - run: - name: deploy dev to heroku - command: | - echo "Deploying to Heroku. To see progress, go to: https://dashboard.heroku.com/apps/$HEROKU_APP_NAME_DEV/activity" - curl -sf -X POST -m 900 https://heroku-deploy.torchbox.com/$HEROKU_APP_NAME_DEV/$CIRCLE_SHA1?key=$DEPLOYMENT_KEY -d "Content-Length: 0" - deploy_staging: - docker: - - image: buildpack-deps:trusty - steps: - - checkout - - run: - name: deploy staging to heroku - command: | - echo "Deploying to Heroku. To see progress, go to: https://dashboard.heroku.com/apps/$HEROKU_APP_NAME_STAGING/activity" - curl -sf -X POST -m 900 https://heroku-deploy.torchbox.com/$HEROKU_APP_NAME_STAGING/$CIRCLE_SHA1?key=$DEPLOYMENT_KEY -d "Content-Length: 0" - deploy_production: - docker: - - image: buildpack-deps:trusty - steps: - - checkout - - run: - name: deploy master to heroku - command: | - echo "Deploying to Heroku. To see progress, go to: https://dashboard.heroku.com/apps/$HEROKU_APP_NAME_PRODUCTION/activity" - curl -sf -X POST -m 900 https://heroku-deploy.torchbox.com/$HEROKU_APP_NAME_PRODUCTION/$CIRCLE_SHA1?key=$DEPLOYMENT_KEY -d "Content-Length: 0" -workflows: - version: 2 - build-deploy: - jobs: - - test - - deploy_dev: - requires: - - test - filters: - branches: - only: dev - - deploy_staging: - requires: - - test - filters: - branches: - only: staging - - confirm_deploy_production: - type: approval - requires: - - test - filters: - branches: - only: master - - deploy_production: - requires: - - test - - confirm_deploy_production - filters: - branches: - only: master diff --git a/.env b/.env index f7515d09b..5b71bba89 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ # Uncomment this to disable running the front-end tooling in Docker. -# FRONTEND=local \ No newline at end of file +# FRONTEND=local diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 000000000..75d28802a --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,31 @@ +name: CI + +on: + pull_request: + push: + branches: [dev, staging, master] + +jobs: + lint: + uses: ./.github/workflows/lint.yaml + + test: + uses: ./.github/workflows/test.yaml + + deploy_production: + if: contains(github.ref, 'master') + needs: [lint, test] + uses: ./.github/workflows/deploy-production.yaml + secrets: inherit + + deploy_dev: + if: contains(github.ref, 'dev') + needs: [lint, test] + uses: ./.github/workflows/deploy-dev.yaml + secrets: inherit + + deploy_staging: + if: contains(github.ref, 'staging') + needs: [lint, test] + uses: ./.github/workflows/deploy-staging.yaml + secrets: inherit diff --git a/.github/workflows/deploy-dev.yaml b/.github/workflows/deploy-dev.yaml new file mode 100644 index 000000000..a9468901b --- /dev/null +++ b/.github/workflows/deploy-dev.yaml @@ -0,0 +1,19 @@ +name: dev_deployment + +on: workflow_call + +jobs: + deploy_dev: + runs-on: ubuntu-latest + + env: + DEPLOYMENT_KEY: ${{ secrets.DEPLOYMENT_KEY_DEV }} + HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME_DEV }} + SHA: ${{ github.sha }} + + steps: + - uses: actions/checkout@v4 + - name: 'deploy dev to heroku' + run: | + echo "Deploying to Heroku. To see progress, go to: https://dashboard.heroku.com/apps/$HEROKU_APP_NAME/activity" + curl -sf -X POST -m 900 https://heroku-deploy.torchbox.com/$HEROKU_APP_NAME/$SHA?key=$DEPLOYMENT_KEY -d "Content-Length: 0" diff --git a/.github/workflows/deploy-production.yaml b/.github/workflows/deploy-production.yaml new file mode 100644 index 000000000..4e98dab5b --- /dev/null +++ b/.github/workflows/deploy-production.yaml @@ -0,0 +1,19 @@ +name: production_deployment + +on: workflow_call + +jobs: + deploy_production: + runs-on: ubuntu-latest + + env: + DEPLOYMENT_KEY: ${{ secrets.DEPLOYMENT_KEY_PRODUCTION }} + HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME_PRODUCTION }} + SHA: ${{ github.sha }} + + steps: + - uses: actions/checkout@v4 + - name: 'deploy master to heroku' + run: | + echo "Deploying to Heroku. To see progress, go to: https://dashboard.heroku.com/apps/$HEROKU_APP_NAME/activity" + curl -sf -X POST -m 900 https://heroku-deploy.torchbox.com/$HEROKU_APP_NAME/$SHA?key=$DEPLOYMENT_KEY -d "Content-Length: 0" diff --git a/.github/workflows/deploy-staging.yaml b/.github/workflows/deploy-staging.yaml new file mode 100644 index 000000000..8d5ae37cd --- /dev/null +++ b/.github/workflows/deploy-staging.yaml @@ -0,0 +1,19 @@ +name: staging_deployment + +on: workflow_call + +jobs: + deploy_staging: + runs-on: ubuntu-latest + + env: + DEPLOYMENT_KEY: ${{ secrets.DEPLOYMENT_KEY_STAGING }} + HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME_STAGING }} + SHA: ${{ github.sha }} + + steps: + - uses: actions/checkout@v4 + - name: 'deploy staging to heroku' + run: | + echo "Deploying to Heroku. To see progress, go to: https://dashboard.heroku.com/apps/$HEROKU_APP_NAME/activity" + curl -sf -X POST -m 900 https://heroku-deploy.torchbox.com/$HEROKU_APP_NAME/$SHA?key=$DEPLOYMENT_KEY -d "Content-Length: 0" diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 000000000..21eb69730 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,44 @@ +name: lint + +on: workflow_call + +jobs: + lint-front-end: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version: '16' + - name: Install npm dependencies + run: npm install + - name: CSS linting + run: npm run lint:css + - name: JS linting + run: npm run lint:js + - name: Prettier + run: npm run format + - name: JS tests + run: npm run test + + lint-python: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.8 + - uses: Gr1N/setup-poetry@v8 + with: + poetry-version: 1.8.2 + - name: Install Poetry + run: | + poetry config virtualenvs.create false && + poetry install + - name: Flake8 + run: flake8 ./rca fabfile.py + - name: isort + run: isort --check-only --diff ./rca --skip-glob '**/migrations/*' + - name: black + run: black --check --diff ./rca fabfile.py --exclude migrations/ diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 000000000..8b7b4ad5d --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,59 @@ +name: test + +on: workflow_call + +jobs: + python-tests: + runs-on: ubuntu-latest + + env: + DJANGO_SETTINGS_MODULE: rca.settings.test + SECRET_KEY: testingsecretkey + SECURE_SSL_REDIRECT: false + ALLOWED_HOSTS: localhost + DATABASE_URL: postgres://postgres:postgres@localhost/postgres + BIRDBATH_REQUIRED: false + + services: + postgres: + image: postgres:12.3 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.8 + - uses: Gr1N/setup-poetry@v8 + with: + poetry-version: 1.5.0 + - name: Install Poetry + run: | + poetry config virtualenvs.create false && + poetry install + - uses: actions/setup-node@v3 + with: + node-version: '16' + - name: Install npm dependencies + run: npm install + - name: Compile static files + run: npm run build:prod + - name: collectstatic + run: python manage.py collectstatic --verbosity 0 --noinput --clear + - name: System checks + run: python manage.py check + - name: Missing migrations + run: python manage.py makemigrations --check --noinput + - name: Test and Coverage + run: | + coverage run ./manage.py test --settings=rca.settings.test + coverage report + coverage xml + bash <(curl -s https://codecov.io/bash) -t $COVERAGE_TOKEN diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 90aa52b42..000000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,247 +0,0 @@ -# vim:set sw=2 ts=2 et: -# This is a sample .gitlab-ci.yml created by wagtail-kit. You should review -# it for any necessary changes. - -# Stages are groups that jobs can be groupped into. -# Jobs within each stage run in parallel and if one of them fails, the next -# stage won't be run. -# This will set up the following: -# -# - Build stage: build of static assets. -# - Test stage: code style, migration, basic configuration checks and unit -# tests. -# - Deploy stage: deploy to Heroku. -stages: - - build - - test - - deploy - -# Test if static assets can be built succesfully. -static: - image: node:12-alpine - stage: build - before_script: - - apk add --no-cache rsync - script: - # Make sure your project has a package-lock.json lockfile, otherwise this install will fail. - - npm ci - - npm run build:prod - # Saving the job result as an artifact means that the files can be used by - # other jobs. - artifacts: - name: 'static-$CI_JOB_ID' - paths: - - ./node_modules - - ./rca/static_compiled - expire_in: 1 week - -# Check python code style. -flake8: - image: python:3.6 - stage: test - script: - # Remember to update a version in requirements-dev.txt - - pip install flake8==3.7.7 - - flake8 rca - -# Check imports sort order, i.e. check whether they are in an alphabetical -# order and grouped properly. -isort: - image: python:3.6 - stage: test - before_script: - # Remember to update a version in requirements-dev.txt - - pip install isort==4.3.15 - script: - - isort --check-only --diff rca - -lint_js: - image: node:12-alpine - stage: test - dependencies: - - static - script: - - npm run lint:js - -lint_css: - image: node:12-alpine - stage: test - dependencies: - - static - script: - - npm run lint:css - -lint_format: - image: node:12-alpine - stage: test - dependencies: - - static - script: - - npm run lint:format - -# Run black and check for changes -black: - image: python:3.7 - stage: test - before_script: - # Remember to update a version in requirements-dev.txt - - pip install black==19.3b0 - script: - - black --check ./ - -# Check settings, migrations and run tests. -test_python: - # Make sure this Python version matches the version in your Dockerfile. - image: python:3.6.6 - stage: test - services: - # Make sure this matches the Postgres version you run on your servers. - - postgres:15 - dependencies: - - static - variables: - # Run tests with the production settings. - DJANGO_SETTINGS_MODULE: rca.settings.production - - # SECRET_KEY is required by Django to start. - SECRET_KEY: fake_secret_key_to_run_tests - - # Silence RECAPTCHA - RECAPTCHA_PUBLIC_KEY: 'dummy-key-value' - RECAPTCHA_PRIVATE_KEY: 'dummy-key-value' - - # This is the URL used by databases on our CI. - DATABASE_URL: postgres://postgres@postgres/postgres - - # Don't redirect to HTTPS in tests. - SECURE_SSL_REDIRECT: 'false' - before_script: - # Install requirements - - pip install wheel - - pip install -r requirements.txt - script: - # We need to run the collectstatic command, because we use ManifestStaticFilesStorage. - # Otherwise the check command will fail - - python manage.py collectstatic --verbosity 0 --noinput --clear - - # Run system checks - - python manage.py check - - # Check for missing migrations - - python manage.py makemigrations --check --noinput - - # Create cache table. - - python manage.py createcachetable - - # Run back-end tests - - python manage.py test - -test_js: - image: node:12-alpine - stage: test - dependencies: - - static - script: - # Run front-end tests - - npm run test:coverage - -.heroku_deploy_job_template: &heroku_deploy_job_definition - before_script: - # Install cURL and GnuPG to install Heroku CLI. - # Install Git to push the code to Heroku. It uses HTTP to push the code. - - apt-get update -y - - apt-get install -y curl git gnupg - - # Install Heroku CLI. - - curl https://cli-assets.heroku.com/install-ubuntu.sh | sh - - # Use Heroku credentials that you can add in your project settings on - # GitLab. They can be obtained from sysadmin or pwman. - - | - cat >~/.netrc <~/.netrc <