Skip to content

Commit

Permalink
Add workflow to check alignment with copier template (#307)
Browse files Browse the repository at this point in the history
* Add workflow to check alignment with copier template

* Use default name for cookiecutter

* Improve alignment test

* Don't print identical

* Don't print in 2 columns

* Fix alignment by bringing improve over

* Fix description

* Fix copier configuration
  • Loading branch information
fcollonval authored Apr 20, 2023
1 parent f220223 commit 3853e17
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 25 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/alignment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Check alignment with copier template

on:
push:
branches: ["*.0"]
pull_request:
branches: ["*"]
schedule:
- cron: "0 0 * * *"

jobs:
template-alignment:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
kind: ["frontend", "server", "theme"]

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v4
- name: Install dependencies
run: |
python -m pip install cookiecutter copier jinja2-time
- name: Create from template
env:
KIND: ${{ matrix.kind }}
run: |
set -eux
# Create template from cookiecutter
python -c "from cookiecutter.main import cookiecutter; import json, os; f=open('cookiecutter.json'); d=json.load(f); f.close(); d['kind']=os.getenv('KIND'); d['labextension_name']='myextension'; cookiecutter('.', extra_context=d, no_input=True)"
# Create template from copier
mkdir copierext
pushd copierext
copier -l -d kind=${KIND} -d labextension_name=myextension -d author_name="My Name" -d author_email="me@test.com" -d repository="https://github.com/github_username/myextension" gh:jupyterlab/extension-template .
rm .copier-answers.yml
popd
diff -r myextension copierext
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1

{% raw %}
- name: Prep Release
id: prep-release
Expand All @@ -40,5 +39,4 @@ jobs:

- name: "** Next Step **"
run: |
echo "Optional): Review Draft Release: ${{ steps.prep-release.outputs.release_url }}"
{% endraw %}
echo "Optional): Review Draft Release: ${{ steps.prep-release.outputs.release_url }}"{% endraw %}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1

{% raw %}
- name: Populate Release
id: populate-release
Expand Down Expand Up @@ -52,5 +51,4 @@ jobs:
if: ${{ failure() }}
run: |
echo "Failed to Publish the Draft Release Url:"
echo ${{ steps.populate-release.outputs.release_url }}
{% endraw %}
echo ${{ steps.populate-release.outputs.release_url }}{% endraw %}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ permissions:
contents: write
pull-requests: write

jobs:
{# Escape double curly brace #}
{% raw %}
jobs:{# Escape double curly brace #}{% raw %}
update-snapshots:
if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, 'please update playwright snapshots') }}
runs-on: ubuntu-latest
Expand Down Expand Up @@ -46,5 +44,4 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
# Playwright knows how to start JupyterLab server
start_server_script: 'null'
test_folder: ui-tests
{% endraw %}
test_folder: ui-tests{% endraw %}
3 changes: 2 additions & 1 deletion {{cookiecutter.python_name}}/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { requestAPI } from './handler';{% endif %}
*/
const plugin: JupyterFrontEndPlugin<void> = {
id: '{{ cookiecutter.labextension_name }}:plugin',
description: '{{ cookiecutter.project_short_description }}',
autoStart: true,{% if cookiecutter.kind.lower() == 'theme' %}
requires: [IThemeManager],{% endif %}{% if cookiecutter.has_settings.lower().startswith('y') %}
optional: [ISettingRegistry],{% endif %}
Expand All @@ -39,7 +40,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
});
}{% endif %}{% if cookiecutter.kind.lower() == 'server' %}

requestAPI<any>('get_example')
requestAPI<any>('get-example')
.then(data => {
console.log(data);
})
Expand Down
23 changes: 21 additions & 2 deletions {{cookiecutter.python_name}}/ui-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ in [jupyter_server_test_config.py](./jupyter_server_test_config.py).

The default configuration will produce video for failing tests and an HTML report.

> There is a new experimental UI mode that you may fall in love with; see [that video](https://www.youtube.com/watch?v=jF0yA-JLQW0).
## Run the tests

> All commands are assumed to be executed from the root directory
Expand Down Expand Up @@ -109,7 +111,14 @@ jlpm playwright install
cd ..
```

3. Execute the [Playwright code generator](https://playwright.dev/docs/codegen):
3. Start the server:

```sh
cd ./ui-tests
jlpm start
```

4. Execute the [Playwright code generator](https://playwright.dev/docs/codegen) in **another terminal**:

```sh
cd ./ui-tests
Expand Down Expand Up @@ -144,5 +153,15 @@ cd ..

```sh
cd ./ui-tests
PWDEBUG=1 jlpm playwright test
jlpm playwright test --debug
```

## Upgrade Playwright and the browsers

To update the web browser versions, you must update the package `@playwright/test`:

```sh
cd ./ui-tests
jlpm up "@playwright/test"
jlpm playwright install
```
2 changes: 1 addition & 1 deletion {{cookiecutter.python_name}}/ui-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
},
"devDependencies": {
"@jupyterlab/galata": "^5.0.0-beta.0",
"@playwright/test": "^1.31.0"
"@playwright/test": "^1.32.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from ._version import __version__{% if cookiecutter.kind.lower() == 'server' %}
from .handlers import setup_handlers
{% endif %}
from .handlers import setup_handlers{% endif %}


def _jupyter_labextension_paths():
return [{
"src": "labextension",
"dest": "{{ cookiecutter.labextension_name }}"
}]
{% if cookiecutter.kind.lower() == 'server' %}
}]{% if cookiecutter.kind.lower() == 'server' %}


def _jupyter_server_extension_points():
Expand All @@ -31,5 +29,4 @@ def _load_jupyter_server_extension(server_app):


# For backward compatibility with notebook server - useful for Binder/JupyterHub
load_jupyter_server_extension = _load_jupyter_server_extension
{% endif %}
load_jupyter_server_extension = _load_jupyter_server_extension{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class RouteHandler(APIHandler):
@tornado.web.authenticated
def get(self):
self.finish(json.dumps({
"data": "This is /{{ cookiecutter.python_name | replace('_', '-') }}/get_example endpoint!"
"data": "This is /{{ cookiecutter.python_name | replace('_', '-') }}/get-example endpoint!"
}))


def setup_handlers(web_app):
host_pattern = ".*$"

base_url = web_app.settings["base_url"]
route_pattern = url_path_join(base_url, "{{ cookiecutter.python_name | replace('_', '-') }}", "get_example")
route_pattern = url_path_join(base_url, "{{ cookiecutter.python_name | replace('_', '-') }}", "get-example")
handlers = [(route_pattern, RouteHandler)]
web_app.add_handlers(host_pattern, handlers)
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

async def test_get_example(jp_fetch):
# When
response = await jp_fetch("{{ cookiecutter.python_name | replace('_', '-') }}", "get_example")
response = await jp_fetch("{{ cookiecutter.python_name | replace('_', '-') }}", "get-example")

# Then
assert response.code == 200
payload = json.loads(response.body)
assert payload == {
"data": "This is /{{ cookiecutter.python_name | replace('_', '-') }}/get_example endpoint!"
"data": "This is /{{ cookiecutter.python_name | replace('_', '-') }}/get-example endpoint!"
}

0 comments on commit 3853e17

Please sign in to comment.