Compare commits

...

15 Commits

Author SHA1 Message Date
242dbeb253 nix fmt 2023-10-30 17:14:15 +01:00
1eff969fbf Improved README
Some checks failed
checks / test (pull_request) Failing after 1m29s
checks-impure / test (pull_request) Successful in 26s
2023-10-30 17:08:41 +01:00
84c5b0477e Improved README and ui-asset workflow
All checks were successful
checks-impure / test (pull_request) Successful in 25s
checks / test (pull_request) Successful in 1m24s
2023-10-30 16:51:39 +01:00
5273eee89f Merge pull request 'Added Getting Started to README' (#5) from Luis-main into main
Some checks failed
checks / test (push) Failing after 3m15s
assets1 / test (push) Successful in 22s
checks-impure / test (push) Successful in 26s
Reviewed-on: Luis/consulting-website#5
2023-10-30 16:00:49 +01:00
f714682948 update ui-assets.nix
All checks were successful
checks-impure / test (push) Has been skipped
checks / test (push) Has been skipped
assets1 / test (push) Has been skipped
2023-10-30 14:59:42 +00:00
51754676bc Merge pull request 'Added Getting Started to README' (#4) from Luis-main into main
All checks were successful
checks-impure / test (push) Successful in 25s
checks / test (push) Successful in 1m50s
assets1 / test (push) Successful in 51s
Reviewed-on: Luis/consulting-website#4
2023-10-30 15:56:46 +01:00
627fd5e76d Added Getting Started to README
Some checks failed
checks-impure / test (pull_request) Successful in 24s
checks / test (pull_request) Failing after 1m40s
2023-10-30 13:37:03 +01:00
7a54c87fde Added Getting Started to README
All checks were successful
checks-impure / test (pull_request) Successful in 26s
checks / test (pull_request) Successful in 1m52s
2023-10-30 13:26:09 +01:00
ui-asset-bot
217f465dc7 update ui-assets.nix
All checks were successful
checks-impure / test (push) Has been skipped
checks / test (push) Has been skipped
assets1 / test (push) Has been skipped
2023-10-27 22:52:40 +00:00
81cf1e2f81 Merge pull request 'Added correct owner to update-ui-assets.sh' (#3) from Luis-main into main
All checks were successful
checks-impure / test (push) Successful in 25s
checks / test (push) Successful in 1m59s
assets1 / test (push) Successful in 48s
Reviewed-on: Luis/consulting-website#3
2023-10-28 00:48:34 +02:00
27c9146ef6 Merge branch 'main' into Luis-main
All checks were successful
checks-impure / test (pull_request) Successful in 25s
checks / test (pull_request) Successful in 2m2s
2023-10-28 00:47:10 +02:00
16d7947701 Added correct owner to update-ui-assets.sh
All checks were successful
checks-impure / test (pull_request) Successful in 24s
checks / test (pull_request) Successful in 2m2s
2023-10-28 00:29:27 +02:00
778130d00d Merge pull request 'Fully working ui and cli' (#1) from Luis-main into main
Some checks failed
checks-impure / test (push) Successful in 24s
checks / test (push) Successful in 1m24s
assets1 / test (push) Failing after 51s
Reviewed-on: Luis/consulting-website#1
2023-10-23 22:37:35 +02:00
d053d4fba4 Fixing broken CI
All checks were successful
checks-impure / test (pull_request) Successful in 35s
checks / test (pull_request) Successful in 6m23s
2023-10-23 03:23:57 +02:00
a659800cb8 Fixing broken CI
Some checks failed
checks-impure / test (pull_request) Successful in 41s
checks / test (pull_request) Failing after 7m10s
2023-10-23 03:17:57 +02:00
9 changed files with 157 additions and 21 deletions

2
.envrc
View File

@@ -3,3 +3,5 @@ if ! has nix_direnv_version || ! nix_direnv_version 2.3.0; then
fi
use flake

View File

@@ -15,7 +15,7 @@ jobs:
id: changed-files
uses: tj-actions/changed-files@v32
with:
fetch-depth: 2
fetch-depth: 0
- name: Check if UI files are in the list of modified files
run: |
@@ -35,8 +35,8 @@ jobs:
export PATH=$PATH:$DEPS
# Setup git config
git config --global user.email "ui-asset-bot@clan.lol"
git config --global user.name "ui-asset-bot"
git config --global user.email "$BOT_EMAIL"
git config --global user.name "$BOT_NAME"
################################################
# #
@@ -66,3 +66,5 @@ jobs:
env:
MODIFIED_FILES: ${{ steps.changed-files.outputs.modified_files }}
GITEA_TOKEN: ${{ secrets.BOT_ACCESS_TOKEN }}
BOT_NAME: "ui-asset-bot"
BOT_EMAIL: "ui-asset-bot@gchq.icu"

123
README.md
View File

@@ -1,9 +1,120 @@
# clan.lol core
# Website Template
This is the monorepo of the clan.lol project
In here are all the packages we use, all the nixosModules we use/expose, the CLI and tests for everything.
This repository is a template to build high quality websites as a team.
The frontend uses [React NextJS
](https://nextjs.org/) and the backend uses Python with the [Fastapi framework](https://fastapi.tiangolo.com/). To ensure API compatibility between frontend and backend an `openapi.json` file is generated from the Python backend code, which defines the REST API. This `openapi.json` file is then fed into [Orval](https://orval.dev/), which generates Typescript bindings for the Rest API. To ensure code correctness, we use [mypy](https://mypy-lang.org/) to ensure the Python code is correctly statically typed, and [pytest](https://docs.pytest.org/en/7.4.x/) for backend tests. A Continuos Integration (CI) Bot, verifies the code with previously mentioned Quality Assurance (QA) tools and blocks Pull requests if any errors arise.
For dependency management we use the [Nix package manager](https://nixos.org/) to ensure reproducibility.
## cLAN config tool
## Getting Started: Development Environment
- The quickstart guide can be found here: [here](/clan/clan-core/src/branch/main/docs/quickstart.md)
- Find the docs [here](/clan/clan-core/src/branch/main/docs/clan-config.md)
1. Install the Nix package manager by [downloading the nix installer](https://github.com/DeterminateSystems/nix-installer/releases) or executing this command:
```bash
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
```
2. Install direnv by [downloading the direnv package](https://direnv.net/docs/installation.html) or executing this command:
```bash
curl -sfL https://direnv.net/install.sh | bash
```
3. Clone the repository and cd into it
4. You should see an error message reading like this:
```bash
direnv: error .envrc is blocked. Run `direnv allow` to approve its content
```
5. Execute `direnv allow` to allow automatically executing the shell script `.envrc` on entering the directory
6. Go to `pkgs/clan-cli` and execute
```bash
direnv allow
```
Then wait for the backend to build
7. To start the backend server then execute:
```
clan webui --reload --no-open --log-level debug
```
The server will automatically restart if any Python file changes.
8. In a different shell go to `pkgs/ui` and execute
```bash
direnv allow
```
Then wait for the frontend to build.
9. To start the frontend, execute:
```bash
npm run dev
```
Visit the website by going to [http://localhost:3000](http://localhost:3000)
## Getting started: Setup Git Workflow
1. Register your Gitea account locally by executing
```bash
tea login add
```
You will then see a prompt, please fill it out like outlined below:
```
? URL of Gitea instance: https://gitea.gchq.icu
? Name of new Login [gitea.gchq.icu]: gitea.gchq.icu:7171
? Do you have an access token? No
? Username: MyUserName
? Password: **********
? Set Optional settings: No
```
2. First add your changes to git:
1. `git add <file1> <file2>` your changes
2. Execute `nix fmt` to lint your files
3. `git commit -a -m "My descriptive commit message"`
4. Make sure your branch has the latest changes from upstream by executing:
```bash
git fetch && git rebase origin/main --autostash
```
5. Execute `git status` to see if you have a merge conflict.
6. If so edit the file and fix the conflict. Here is a tutorial how to do so in [vscode](https://code.visualstudio.com/docs/sourcecontrol/overview#_merge-conflicts)
7. Execute `git merge --continue` and repeat step 5 till there are no conflicts anymore
3. To automatically open up a pull request, that gets merged if all tests pass execute:
```bash
merge-after-ci
```
4. Go to https://gitea.gchq.icu to the project page, and look under "Pull Requests" if there are any issues with it.
5. If there are issues, fix them and redo step 2. Afterwards execute
```
git push origin HEAD:MyUserName-main
```
to directly push to your open pull request
## Using this template
Setup two new gitea accounts.
One named `ui-asset-bot`, generate an access token for it with all access permissions and set under `settings/actions/secrets` a secret called `BOT_ACCESS_TOKEN` with the token.
Also edit the file `.gitea/workflows/ui_assets.yaml` and change the `BOT_EMAIL` variable to the email you set for that account.
The second account is called `merge-bot` edit the file `pkgs/merge-after-ci/default.nix`
if the name should be different.
Under Branches set the main branch to protected and add `merge-bot` to whitelisted users for pushing.
Also set an unprotected file pattern to `**/ui-assets.nix`.
Also set the option `Enable Status Check` to `build / test (pull_request)`
Add `merge-bot` and `ui-asset-bot` as collaborators.
Also set the option `Delete pull request branch after merge by default`
Also the the default merge style to `Rebase then create merge commit`

View File

@@ -56,15 +56,15 @@ Add this `launch.json` to your .vscode directory to have working breakpoints in
## Run locally single-threaded for debugging
By default tests run in parallel using pytest-parallel.
pytest-parallel however breaks `breakpoint()`. To disable it, use this:
By default tests run in parallel using pytest-xdist.
pytest-xdist however breaks `breakpoint()`. To disable it, use this:
```console
pytest --workers "" -s
pytest -n0 -s
```
You can also run a single test like this:
```console
pytest --workers "" -s tests/test_secrets_cli.py::test_users
pytest -n0 -s tests/test_secrets_cli.py::test_users
```

View File

@@ -9,6 +9,11 @@ import pytest
from ports import PortFunction
@pytest.mark.impure
def test_nothing_much() -> None:
pass
@pytest.mark.timeout(10)
def test_start_server(unused_tcp_port: PortFunction, temporary_home: Path) -> None:
port = unused_tcp_port()

View File

@@ -21,6 +21,6 @@ writeShellApplication {
remoteName="''${1:-origin}"
targetBranch="''${2:-main}"
shift && shift
tea-create-pr "$remoteName" "$targetBranch" --assignees consulting-bot "$@"
tea-create-pr "$remoteName" "$targetBranch" --assignees merge-bot "$@"
'';
}

5
pkgs/ui/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"search.exclude": {
"**/.direnv": true
}
}

View File

@@ -1,5 +1,5 @@
{ fetchzip }:
fetchzip {
url = "https://git.clan.lol/api/packages/clan/generic/ui/1xk9if1sykv2kcv3zn0dxn7gd7hlqjbhzz6hrsw0yiksf03skg9r/assets.tar.gz";
sha256 = "1xk9if1sykv2kcv3zn0dxn7gd7hlqjbhzz6hrsw0yiksf03skg9r";
url = "https://gitea.gchq.icu/api/packages/ui-asset-bot/generic/ui/1inlxk1i9q87bw00zwqyvpm3m0hdgdffhxlymzgi5wvqn9syd0cm/assets.tar.gz";
sha256 = "1inlxk1i9q87bw00zwqyvpm3m0hdgdffhxlymzgi5wvqn9syd0cm";
}

View File

@@ -3,8 +3,17 @@ set -xeuo pipefail
# GITEA_TOKEN
if [[ -z "${GITEA_TOKEN:-}" ]]; then
echo "GITEA_TOKEN is not set"
echo "Go to https://gitea.gchq.icu/user/settings/applications and generate a token"
echo "GITEA_TOKEN is not set. Check if the secret BOT_ACCESS_TOKEN is set in the repository settings."
exit 1
fi
if [[ -z "${BOT_NAME:-}" ]]; then
echo "Env var BOT_NAME is not set. Use the name of the bot user here."
exit 1
fi
if [[ -z "${GITHUB_SERVER_URL:-}" ]]; then
echo "Env var GITHUB_SERVER_URL is not set. Please use the Gitea base URL here."
exit 1
fi
@@ -22,10 +31,12 @@ nix build '.#ui' --out-link "$tmpdir/result"
tar --transform 's,^\.,assets,' -czvf "$tmpdir/assets.tar.gz" -C "$tmpdir"/result/lib/node_modules/*/out .
NAR_HASH=$(nix-prefetch-url --unpack file://<(cat "$tmpdir/assets.tar.gz"))
owner=Luis
package_name=consulting-website
owner=$BOT_NAME
package_name=ui
package_version=$NAR_HASH
url="https://gitea.gchq.icu/api/packages/$owner/generic/$package_name/$package_version/assets.tar.gz"
baseurl=$GITHUB_SERVER_URL
url="$baseurl/api/packages/$owner/generic/$package_name/$package_version/assets.tar.gz"
set +x
curl --upload-file "$tmpdir/assets.tar.gz" -X PUT "$url?token=$GITEA_TOKEN"
set -x