Skip to content

Commit

Permalink
use makefile to run tests (#772)
Browse files Browse the repository at this point in the history
* use makefile to run tests

Signed-off-by: Helder Ribeiro <helder.ribeiro@digital.justice.gov.uk>
  • Loading branch information
hjribeiro-moj committed Sep 4, 2024
1 parent c3c4203 commit 96f9ec3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
29 changes: 12 additions & 17 deletions .github/workflows/reusable-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ jobs:
cache-dependency-path: ./poetry.lock

- name: Install project
run: poetry install --no-interaction --no-root

- name: Install compilemessages prereqs
run: sudo apt-get install gettext
run: |
make install_python_deps
make install_npm_deps
poetry install --no-interaction --no-root
sudo apt-get install gettext
- name: Make compilemessages
run: make compilemessages
Expand All @@ -88,22 +89,18 @@ jobs:

- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
run: make export_npm_cache_dir

- uses: actions/cache@v4
- name: Load cached npm
uses: actions/cache@v4
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
path: $(cat .npm_cache_dir)
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install npm dependencies
id: install_dependencies
run: npm install

- name: Collect static files
run: poetry run python manage.py collectstatic --no-input
run: make collect_static

- name: Run unit tests with coverage
id: fast-tests
Expand Down Expand Up @@ -132,14 +129,12 @@ jobs:

- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
run: make export_npm_cache_dir

- name: Load cached npm
uses: actions/cache@v4
id: npm-cache
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
path: $(cat .npm_cache_dir)
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
Expand Down
33 changes: 23 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,32 @@ all: build
# Setup the application
build: install_deps set_env $(ENV_FILE) collect_static migrate setup_waffle_switches messages

# Install dependencies
install_deps:
if ! command -v op >/dev/null 2>&1; then \
echo "1password CLI is not installed. Please install it from https://1password.com/downloads/"; \
# Install Python dependencies
install_python_deps:
if ! command -v poetry >/dev/null 2>&1; then \
echo "Poetry is not installed. Please install it from https://python-poetry.org/docs/#installation"; \
exit 1; \
fi
poetry install

# Install Node.js dependencies
install_npm_deps:
if ! command -v npm >/dev/null 2>&1; then \
echo "npm is not installed. Please install it from https://nodejs.org/"; \
exit 1; \
fi
if ! command -v chromedriver >/dev/null 2>&1; then \
echo "Chromedriver is not installed. Please install it from https://sites.google.com/a/chromium.org/chromedriver/downloads"; \
npm install

# Install dependencies
install_deps: install_npm_deps install_python_deps
if ! command -v op >/dev/null 2>&1; then \
echo "1password CLI is not installed. Please install it from https://1password.com/downloads/"; \
exit 1; \
fi
if ! command -v poetry >/dev/null 2>&1; then \
echo "Poetry is not installed. Please install it from https://python-poetry.org/docs/#installation"; \
if ! command -v chromedriver >/dev/null 2>&1; then \
echo "Chromedriver is not installed. Please install it from https://sites.google.com/a/chromium.org/chromedriver/downloads"; \
exit 1; \
fi
poetry install
npm install

# Generate .env file
$(ENV_FILE): .env.tpl
Expand Down Expand Up @@ -72,6 +78,13 @@ unit:
integration:
poetry run pytest tests/integration --axe-version 4.9.1 --chromedriver-path $$(which chromedriver)


# Get npm cache directory and store it in a file
export_npm_cache_dir:
@echo "Fetching npm cache directory..."
@npm config get cache > .npm_cache_dir
@echo "NPM cache directory stored in .npm_cache_dir"

# Clean up (optional)
clean:
rm -rf staticfiles
Expand Down

0 comments on commit 96f9ec3

Please sign in to comment.