Skip to content

Commit

Permalink
📦 Build JS assets in CI and gitignore them
Browse files Browse the repository at this point in the history
The npm 'package' and the django staticfiles assets are exclusively
to be built in the CI pipeline, and not kept in version control.

This keeps a single source of truth and prevents us from forgetting to
update the artifacts, at the cost of a little extra step for local
development.
  • Loading branch information
sergei-maertens committed May 2, 2024
1 parent 7bdfc78 commit f401189
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 182 deletions.
43 changes: 43 additions & 0 deletions .github/actions/build-js/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---

name: 'Build JS'
description: 'Compile the TS source code'

inputs:
npm-package:
description: Build NPM package
required: false
default: 'false'

django-staticfiles:
description: Bundle Django staticfiles
required: false
default: 'false'

runs:
using: 'composite'

steps:

- uses: actions/setup-node@v4
with:
node-version-file: 'js/.nvmrc'
cache: npm
cache-dependency-path: js/package-lock.json

- name: Install dependencies
run: npm ci
shell: bash
working-directory: js

- name: Build NPM package
if: ${{ inputs.npm-package == 'true' }}
run: npm run build
shell: bash
working-directory: js

- name: Build Django assets package
if: ${{ inputs.django-staticfiles == 'true' }}
run: npm run build:django-static
shell: bash
working-directory: js
19 changes: 8 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: ./.github/actions/build-js
with:
node-version-file: 'js/.nvmrc'
cache: npm
cache-dependency-path: js/package-lock.json

- name: Build TS
run: |
npm ci
npm run build
npm run build:django-static
working-directory: js
npm-package: 'true'
django-staticfiles: 'false'

tests:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -77,6 +69,11 @@ jobs:
with:
python-version: '3.10'

- uses: ./.github/actions/build-js
with:
npm-package: 'false'
django-staticfiles: 'true'

- name: Install dependencies
run: |
pip install tox tox-gh-actions pytest-playwright
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ jobs:
python -m pip install -U pip
python -m pip install -U setuptools twine wheel
- uses: ./.github/actions/build-js
with:
npm-package: 'true'
django-staticfiles: 'true'

- name: Build package
run: |
python setup.py --version
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ reports/
testapp/*.db

# frontend tooling / builds
js/lib/
js/node_modules/
js/lib/
cookie_consent/static/cookie_consent/cookiebar.module.*
12 changes: 12 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ You can then install the project with all the dev-tools:
pip install -e .[tests,pep8,coverage,docs,release]
Some frontend tooling is needed to:

* NodeJS (for the version, see ``.nvmrc``, you can use ``nvm``)

.. code-block:: bash
cd js
nvm use
npm install
npm run build:django-static
npm run build # optional, but a nice check
**Running the testapp as dev environment**

In Django project's, you are typically expecting a ``manage.py`` file. This is less
Expand Down
163 changes: 0 additions & 163 deletions cookie_consent/static/cookie_consent/cookiebar.module.js

This file was deleted.

Loading

0 comments on commit f401189

Please sign in to comment.