Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ DEVEL=true
SECRET_KEY=insecure_dev_key
CONTRACTS_API_URL=https://contracts.staging.canonical.com/
SECURITY_API_URL=https://ubuntu.com/security/
SEARCH_API_KEY=fake-key
STRIPE_PUBLISHABLE_KEY=pk_test_yndN9H0GcJffPe0W58Nm64cM00riYG4N46
STORE_MAINTENANCE=false
BADGR_URL=https://api.test.badgr.com
Expand All @@ -17,7 +18,6 @@ CONFIDENTIALITY_AGREEMENT_WEBHOOK_USERNAME="local"
CONFIDENTIALITY_AGREEMENT_WEBHOOK_PASSWORD="password"
MARKETO_API_URL=https://066-EOV-335.mktorest.com


CAPTCHA_TESTING_API_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
CRED_MAINTENANCE=true
CRED_MAINTENANCE_START=2024-09-28T11:00:00Z
Expand Down
86 changes: 86 additions & 0 deletions .github/workflows/pr-with-task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: PR checks with taskfile
on:
push:
pull_request:

jobs:
start:
name: "Start Project"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Taskfile
uses: arduino/setup-task@v2
with:
version: 3.40.0

- name: Start server
run: |
stdbuf -oL -eL task start > server.log 2>&1 &
echo $! > server.pid

- name: Wait for server to start
run: |
timeout 120 bash -c 'tail -n0 -F server.log | grep -m1 "Listening at"'

- name: Print server logs
if: always()
run: |
cat server.log || true

- name: Check server is returning 200
run: |
export PORT=$(grep '^\s*PORT:' taskfile.yaml | awk '{print $2}')
curl --head --fail --retry-delay 1 --retry 30 --retry-connrefused http://localhost:${PORT}

- name: Stop server
run: |
if [ -f server.pid ]; then
kill $(cat server.pid) || true
fi

build:
name: "Build Project"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Taskfile
uses: arduino/setup-task@v2
with:
version: 3.40.0

- name: Build project
run: task build

test:
name: "Test Project"
runs-on: ubuntu-latest
steps:
# TODO: Add codecov integration when this replaces the original PR.yaml workflow
- uses: actions/checkout@v4

- name: Setup Taskfile
uses: arduino/setup-task@v2
with:
version: 3.40.0

- name: Test project
run: task test

lint:
name: "Lint Project"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Taskfile
uses: arduino/setup-task@v2
with:
version: 3.40.0

- name: Lint project
run: task lint

# TODO: Include inclusive naming check, which is currently in the original PR.yaml workflow
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# [generated] Bracketed sections updated by Yeoman generator
# [email protected]
.task/
coverage/

# [os] OS & editor files
Desktop.ini
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@ If you have found a bug in the Ubuntu OS itself, please file it [here](https://b

## Local development

The simplest way to run the site locally is using the [`dotrun`](https://github.com/canonical-web-and-design/dotrun/) snap. Please use the installation scripts [mentioned in the README](https://github.com/canonical-web-and-design/dotrun/blob/main/README.md#installation) to install `dotrun`.
Recommended: use Taskfile

Once it's installed, run the project with:
Install Taskfile by following the official installation docs: [taskfile.dev/docs/installation](https://taskfile.dev/docs/installation).

Run the project with:

```bash
dotrun
task
# or
# task start
```

For Mac users, in case running `dotrun` returns an error related to Chromium, add the following line to your local `.env.local` file (create one if you don't have it):
> [!WARNING]
> Deprecated: dotrun

Using the [`dotrun`](https://github.com/canonical-web-and-design/dotrun/) snap to run this project is now deprecated and will be removed in the future. If you still rely on it, please see the installation instructions in the dotrun README and run `dotrun` as before. On macOS, if `dotrun` errors due to Chromium, add the following to your local `.env.local` file:

```
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ djlint==1.34.1
pycountry==24.6.1
markdown==3.7
markupsafe==2.1.5
coverage==7.10.6
flake8==7.3.0
black==25.1.0
153 changes: 153 additions & 0 deletions taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
version: "3"

vars:
VENV_DIR: .venv
VENV_BIN: "{{ .VENV_DIR }}/bin"
PYTHON_BIN: "{{ .VENV_BIN }}/python3"
PIP_BIN: "{{ .VENV_BIN }}/pip3"

env:
PORT: 8001
PYTHON_VERSION: "3.10"
NODE_VERSION: "20"
PATH: "{{ .VENV_BIN }}:$PATH"

dotenv: [".env.local", ".env"]

# Available tasks:
# - start (default)
# - install
# - shell
# - clean
# - test
# - lint
# - format
# - build
tasks:
default:
cmds:
- task: start

start:
desc: "Start the project"
deps:
- install
cmds:
- PATH="{{ .VENV_BIN }}:$PATH" yarn start

install:
desc: "Install Python and Node.js binaries and their packages"
deps:
- install-python
- install-yarn
cmds:
- echo "Installation complete"

shell:
desc: "Open a shell with the virtual environment activated"
deps:
- install
cmds:
- PATH="{{ .VENV_BIN }}:$PATH" $SHELL

clean:
cmds:
- rm -rf static/css static/js/dist node_modules {{ .VENV_DIR }} .task

test:
desc: "Run all project tests"
deps:
- install
cmds:
- PATH="{{ .VENV_BIN }}:$PATH" coverage run --source=. -m unittest discover tests
- PATH="{{ .VENV_BIN }}:$PATH" yarn test-js --coverage

lint:
desc: "Run all project linting"
deps:
- install
cmds:
- PATH="{{ .VENV_BIN }}:$PATH" yarn lint-python
- PATH="{{ .VENV_BIN }}:$PATH" yarn lint-ts
- PATH="{{ .VENV_BIN }}:$PATH" yarn lint-js
- PATH="{{ .VENV_BIN }}:$PATH" yarn lint-scss

format:
desc: "Run all project formatting"
deps:
- install
cmds:
- PATH="{{ .VENV_BIN }}:$PATH" yarn format-python
- PATH="{{ .VENV_BIN }}:$PATH" yarn format-prettier
- npx stylelint --fix static/**/*.scss

build:
desc: "Build the project static files"
deps:
- install
cmds:
- PATH="{{ .VENV_BIN }}:$PATH" yarn build

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, should have mentioned in the first comment:
It might be helpful to also have an option for clean

# Custom tools versioning setup (mise, python, node, etc.)
setup-mise:
internal: true
desc: "Setup mise"
preconditions:
- which curl
status:
- ! which mise
cmds:
- curl https://mise.run | sh

setup-python:
deps:
- setup-mise
cmds:
- mise install python@{{ .PYTHON_VERSION }}

setup-node:
deps:
- setup-mise
cmds:
- mise install node@{{ .NODE_VERSION }}

# Python virtual environment
venv:
internal: true
desc: "Setup python virtual environment"
deps:
- setup-python
status:
- ! -f {{ .PYTHON_BIN }}
cmds:
- mise exec python@{{ .PYTHON_VERSION }} -- python3 -m venv .venv
- echo "Using Python $({{ .PYTHON_BIN }} --version)"

install-python:
internal: true
desc: "Install python packages"
deps:
- venv
sources:
- requirements.txt
generates:
- "{{ .VENV_DIR }}/*"
cmds:
- "{{ .PIP_BIN }} install -r requirements.txt"

# Node.js package manager
install-yarn:
internal: true
desc: "Install yarn packages"
deps:
- setup-node
status:
- which yarn
- which node
sources:
- yarn.lock
- package.json
generates:
- "node_modules/**"
cmds:
- yarn install
Loading