diff --git a/.gitea/workflows/ui_assets.yaml b/.gitea/workflows/ui_assets.yaml index f0475d0..3c7f527 100644 --- a/.gitea/workflows/ui_assets.yaml +++ b/.gitea/workflows/ui_assets.yaml @@ -35,8 +35,8 @@ jobs: export PATH=$PATH:$DEPS # Setup git config - git config --global user.email "ui-asset-bot@gchq.icu" - 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" diff --git a/README.md b/README.md index 49560bf..f444d98 100644 --- a/README.md +++ b/README.md @@ -76,16 +76,19 @@ You will then see a prompt, please fill it out like outlined below: ``` 2. First add your changes to git: + 1. `git add ` 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 + 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: @@ -101,3 +104,13 @@ 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. +Then 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`. +Add both `ui-asset-bot` and `merge-bot` as collaborators. diff --git a/pkgs/clan-cli/README.md b/pkgs/clan-cli/README.md index 3358327..a85fdd0 100644 --- a/pkgs/clan-cli/README.md +++ b/pkgs/clan-cli/README.md @@ -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 ``` diff --git a/pkgs/ui/nix/update-ui-assets.sh b/pkgs/ui/nix/update-ui-assets.sh index 80c70f2..7f95bf8 100755 --- a/pkgs/ui/nix/update-ui-assets.sh +++ b/pkgs/ui/nix/update-ui-assets.sh @@ -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,11 +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=ui-asset-bot +owner=$BOT_NAME package_name=ui package_version=$NAR_HASH +baseurl=$GITHUB_SERVER_URL -url="https://gitea.gchq.icu/api/packages/$owner/generic/$package_name/$package_version/assets.tar.gz" +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