Merge branch 'develop' into djiffy-version #559
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: unit_tests | |
on: [push, pull_request] | |
env: | |
NODE_VERSION: 18 | |
DB_NAME: shxco | |
DB_USER: shxco | |
DB_PASSWORD: shxco | |
DJANGO_ENV: test | |
jobs: | |
build-static: | |
name: Build static files | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Cache node modules | |
uses: actions/cache@v4 | |
with: | |
path: ~/.npm | |
key: npm-${{ hashFiles('package-lock.json') }} | |
restore-keys: | | |
npm-${{ hashFiles('package-lock.json') }} | |
npm- | |
- name: Install dependencies | |
run: npm ci | |
- name: Run webpack build | |
run: npm run build:prod | |
- name: Upload built files | |
uses: actions/upload-artifact@v4 | |
with: | |
name: bundles | |
path: bundles/ | |
- name: Upload stats file | |
uses: actions/upload-artifact@v4 | |
with: | |
name: webpack-stats.json | |
path: webpack-stats.json | |
ts-unit: | |
name: TypeScript unit tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: Cache node modules | |
uses: actions/cache@v4 | |
with: | |
path: ~/.npm | |
key: npm-${{ hashFiles('package-lock.json') }} | |
restore-keys: | | |
npm-${{ hashFiles('package-lock.json') }} | |
npm- | |
- name: Install dependencies | |
run: npm ci | |
- name: Run Jest | |
run: npx jest --collectCoverage | |
- name: Upload test coverage to Codecov | |
uses: codecov/codecov-action@v4 | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
with: | |
flags: typescript | |
py-unit: | |
name: Python unit tests | |
runs-on: ubuntu-latest | |
needs: build-static | |
services: | |
postgres: | |
image: postgres:12 | |
env: | |
POSTGRES_DB: ${{ env.DB_NAME }} | |
POSTGRES_USER: ${{ env.DB_USER }} | |
POSTGRES_PASSWORD: ${{ env.DB_PASSWORD }} | |
ports: | |
- 5432:5432 | |
solr: | |
image: solr:8.6 | |
ports: | |
- 8983:8983 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# use docker cp to copy the configset, then bash to set ownership to solr | |
- name: Copy Solr configset to solr service | |
run: | | |
docker cp solr_conf ${{ job.services.solr.id }}:/opt/solr/server/solr/configsets/sandco | |
docker exec --user root ${{ job.services.solr.id }} /bin/bash -c "chown -R solr:solr /opt/solr/server/solr/configsets/sandco" | |
- name: Copy solr configsets to solr home directory (Solr 8 specific) | |
run: "docker exec -d ${{ job.services.solr.id }} cp -r /opt/solr/server/solr/configsets /var/solr/data" | |
# Python version to use is stored in the .python-version file, which is the | |
# convention for pyenv: https://github.com/pyenv/pyenv | |
- name: Get Python version | |
run: echo "PYTHON_VERSION=$(cat .python-version)" >> $GITHUB_ENV | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- name: Cache pip | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cache/pip | |
key: pip-${{ matrix.python }}-${{ hashFiles('pyproject.toml') }} | |
restore-keys: | | |
pip-${{ matrix.python }}-${{ hashFiles('pyproject.toml') }} | |
pip-${{ matrix.python }} | |
pip- | |
- name: Install python dependencies | |
run: pip install -e '.[dev]' | |
- name: Download webpack stats | |
uses: actions/download-artifact@v4 | |
with: | |
name: webpack-stats.json | |
- name: Setup local_settings.py | |
run: | | |
cp ci/testsettings.py mep/local_settings.py | |
python -c "import uuid; print('SECRET_KEY = \'%s\'' % uuid.uuid4())" >> mep/local_settings.py | |
- name: Run pytest | |
run: py.test --cov=./ --cov-report=xml | |
- name: Upload test coverage to Codecov | |
uses: codecov/codecov-action@v4 | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
with: | |
flags: python | |
# Set the color of the slack message used in the next step based on the | |
# status of the build: "warning" for failure and "good" for success | |
- name: Set Slack message color based on build status | |
if: ${{ always() }} | |
env: | |
JOB_STATUS: ${{ job.status }} | |
run: echo "SLACK_COLOR=$(if [ "$JOB_STATUS" == "success" ]; then echo "good"; elif [ "$JOB_STATUS" == "failure" ]; then echo "danger"; else echo "warning"; fi)" >> $GITHUB_ENV | |
# Send a message to slack to report the build status. The webhook is stored | |
# at the organization level and available to all repositories. Only run on | |
# scheduled builds & pushes, since PRs automatically report to Slack. | |
- name: Report status to Slack | |
uses: rtCamp/action-slack-notify@v2 | |
if: ${{ always() && (github.event_name == 'schedule' || github.event_name == 'push') }} | |
continue-on-error: true | |
env: | |
SLACK_COLOR: ${{ env.SLACK_COLOR }} | |
SLACK_WEBHOOK: ${{ secrets.ACTIONS_SLACK_WEBHOOK }} | |
SLACK_TITLE: "Run #${{ github.run_number }} for workflow `${{ github.workflow }}`: ${{ job.status }}" | |
SLACK_MESSAGE: "Run <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|#${{ github.run_number }}> on <https://github.com/${{ github.repository }}/|${{ github.repository }}@${{ github.ref }}>" | |
SLACK_FOOTER: "<https://github.com/${{ github.repository }}/commit/${{ github.sha }}|View commit>" | |
MSG_MINIMAL: true # use compact slack message format | |