Skip to content

Commit

Permalink
Merge pull request #119 from jazzband/feature/isolate-js
Browse files Browse the repository at this point in the history
Isolate cookiebar module JS
  • Loading branch information
sergei-maertens authored May 9, 2024
2 parents c0db980 + 0191b88 commit bdc3452
Show file tree
Hide file tree
Showing 15 changed files with 991 additions and 208 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ indent_size = 2
[*.{yml,yaml}]
indent_size = 2

[*.js]
[*.{js,ts}]
indent_size = 2

[*.json]
indent_size = 2

[Makefile]
Expand Down
46 changes: 46 additions & 0 deletions .github/actions/build-js/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---

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
# Blocked by https://github.com/jazzband/django-cookie-consent/issues/120
# registry-url: 'https://registry.npmjs.org'
# scope: '@jazzband'

- 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
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ on:
workflow_dispatch:

jobs:
build-js:
runs-on: ubuntu-latest
name: Compile the frontend code

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

tests:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -54,6 +65,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
21 changes: 19 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ on:

jobs:
build:
name: Publish package to Jazzband private PyPI
name: Publish packages
runs-on: ubuntu-latest
if: github.repository == 'jazzband/django-cookie-consent'

permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v3
with:
Expand All @@ -26,16 +30,29 @@ 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
python setup.py sdist --format=gztar bdist_wheel
twine check dist/*
- name: Upload packages to Jazzband
- name: Upload packages to Jazzband private PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: jazzband
password: ${{ secrets.JAZZBAND_RELEASE_KEY }}
repository_url: https://jazzband.co/projects/django-cookie-consent/upload

# Blocked on https://github.com/jazzband/django-cookie-consent/issues/120
# - name: Publish NPM package to Github
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
# run: npm publish
# working-directory: js
# env:
# NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ dist/
htmlcov/
reports/
testapp/*.db

# frontend tooling / builds
js/node_modules/
js/lib/
cookie_consent/static/cookie_consent/cookiebar.module.*
17 changes: 17 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 Expand Up @@ -127,6 +139,11 @@ After updating changelogs etc.
.. code-block:: bash
tbump {new-version} --only-patch
cd js
npm version major|minor|patch --no-git-tag-version
cd ..
git commit -am ":bookmark: Bump to version <X.Y.Z>"
git tag -s X.Y.Z
git push origin master --tags
203 changes: 0 additions & 203 deletions cookie_consent/static/cookie_consent/cookiebar.module.js

This file was deleted.

Loading

0 comments on commit bdc3452

Please sign in to comment.