forked from clan/clan-core
Merge pull request 'Removed unused ui-assets workflow file.' (#665) from Qubasa-main into main
This commit is contained in:
commit
2db632f1d2
@ -1,68 +0,0 @@
|
||||
name: assets1
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
jobs:
|
||||
test:
|
||||
if: ${{ github.actor != 'ui-asset-bot' }}
|
||||
runs-on: nix
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Get changed files using defaults
|
||||
id: changed-files
|
||||
uses: tj-actions/changed-files@v32
|
||||
with:
|
||||
fetch-depth: 2
|
||||
|
||||
- name: Check if UI files are in the list of modified files
|
||||
run: |
|
||||
set -xeuo pipefail
|
||||
echo "Modified files: $MODIFIED_FILES"
|
||||
if echo "$MODIFIED_FILES" | grep -q "pkgs/ui/" \
|
||||
|| echo "$MODIFIED_FILES" | grep -q ".gitea/workflows/ui_assets.yaml"; then
|
||||
|
||||
echo "UI files have changed"
|
||||
./pkgs/ui/nix/update-ui-assets.sh
|
||||
|
||||
|
||||
# git push if we have a diff
|
||||
if [[ -n $(git diff) ]]; then
|
||||
|
||||
DEPS=$(nix shell --inputs-from '.#' "nixpkgs#coreutils-full" -c bash -c "echo \$PATH")
|
||||
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"
|
||||
|
||||
################################################
|
||||
# #
|
||||
# WARNING: SECRETS ARE BEING PROCESSED HERE. #
|
||||
# !DO NOT LOG THIS! #
|
||||
# #
|
||||
################################################
|
||||
set +x
|
||||
AUTH_TOKEN=$(echo -n "x-access-token:$GITEA_TOKEN" | base64)
|
||||
git config http."$GITHUB_SERVER_URL/".extraheader "AUTHORIZATION: basic $AUTH_TOKEN"
|
||||
set -x
|
||||
################################################
|
||||
# #
|
||||
# END OF SECRETS AREA #
|
||||
# #
|
||||
################################################
|
||||
|
||||
# Commit and push
|
||||
git commit -am "update ui-assets.nix"
|
||||
|
||||
echo "Current branch: $GITHUB_REF_NAME"
|
||||
git push origin HEAD:$GITHUB_REF_NAME
|
||||
fi
|
||||
else
|
||||
echo "No UI files changed. Skipping asset build and push"
|
||||
fi
|
||||
env:
|
||||
MODIFIED_FILES: ${{ steps.changed-files.outputs.modified_files }}
|
||||
GITEA_TOKEN: ${{ secrets.BOT_ACCESS_TOKEN }}
|
@ -1,3 +1,4 @@
|
||||
import base64
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
@ -35,6 +36,23 @@ def user_config_dir() -> Path:
|
||||
return Path(os.getenv("XDG_CONFIG_HOME", os.path.expanduser("~/.config")))
|
||||
|
||||
|
||||
def user_gcroot_dir() -> Path:
|
||||
p = user_config_dir() / "clan" / "gcroots"
|
||||
p.mkdir(parents=True, exist_ok=True)
|
||||
return p
|
||||
|
||||
|
||||
def specific_groot_dir(*, clan_name: str, flake_url: str) -> Path:
|
||||
# Always build icon so that we can symlink it to the gcroot
|
||||
gcroot_dir = user_gcroot_dir()
|
||||
burl = base64.urlsafe_b64encode(flake_url.encode()).decode()
|
||||
# Create the directory if it already exists append a number to it till it doesn't exist and then create it
|
||||
clan_gcroot = gcroot_dir / f"{clan_name}-{burl}"
|
||||
|
||||
clan_gcroot.mkdir(parents=True, exist_ok=True)
|
||||
return clan_gcroot
|
||||
|
||||
|
||||
def user_history_file() -> Path:
|
||||
return user_config_dir() / "clan" / "history"
|
||||
|
||||
|
@ -4,6 +4,7 @@ import subprocess
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from ..dirs import specific_groot_dir
|
||||
from ..errors import ClanError
|
||||
from ..machines.list import list_machines
|
||||
from ..nix import nix_build, nix_config, nix_eval, nix_metadata
|
||||
@ -22,22 +23,7 @@ class FlakeConfig:
|
||||
revision: str | None
|
||||
|
||||
|
||||
def inspect_flake(flake_url: str | Path, flake_attr: str) -> FlakeConfig:
|
||||
config = nix_config()
|
||||
system = config["system"]
|
||||
|
||||
machines = list_machines(flake_url)
|
||||
if flake_attr not in machines:
|
||||
raise ClanError(
|
||||
f"Machine {flake_attr} not found in {flake_url}. Available machines: {', '.join(machines)}"
|
||||
)
|
||||
|
||||
cmd = nix_eval(
|
||||
[
|
||||
f'{flake_url}#clanInternals.machines."{system}"."{flake_attr}".config.clanCore.clanIcon'
|
||||
]
|
||||
)
|
||||
|
||||
def run_cmd(cmd: list[str]) -> str:
|
||||
proc = subprocess.run(cmd, text=True, stdout=subprocess.PIPE)
|
||||
assert proc.stdout is not None
|
||||
if proc.returncode != 0:
|
||||
@ -49,53 +35,54 @@ stdout:
|
||||
{proc.stdout}
|
||||
"""
|
||||
)
|
||||
res = proc.stdout.strip()
|
||||
if res == "null":
|
||||
icon_path = None
|
||||
else:
|
||||
icon_path = res.strip('"')
|
||||
|
||||
if not Path(icon_path).exists():
|
||||
cmd = nix_build(
|
||||
[
|
||||
f'{flake_url}#clanInternals.machines."{system}"."{flake_attr}".config.clanCore.clanIcon'
|
||||
]
|
||||
)
|
||||
proc = subprocess.run(cmd, text=True, capture_output=True)
|
||||
assert proc.stdout is not None
|
||||
if proc.returncode != 0:
|
||||
raise ClanError(
|
||||
f"""
|
||||
command: {shlex.join(cmd)}
|
||||
exit code: {proc.returncode}
|
||||
stdout:
|
||||
{proc.stdout}
|
||||
stderr:
|
||||
{proc.stderr}
|
||||
"""
|
||||
)
|
||||
return proc.stdout.strip()
|
||||
|
||||
|
||||
def inspect_flake(flake_url: str | Path, flake_attr: str) -> FlakeConfig:
|
||||
config = nix_config()
|
||||
system = config["system"]
|
||||
|
||||
# Check if the machine exists
|
||||
machines = list_machines(flake_url)
|
||||
if flake_attr not in machines:
|
||||
raise ClanError(
|
||||
f"Machine {flake_attr} not found in {flake_url}. Available machines: {', '.join(machines)}"
|
||||
)
|
||||
|
||||
# Get the cLAN name
|
||||
cmd = nix_eval(
|
||||
[
|
||||
f'{flake_url}#clanInternals.machines."{system}"."{flake_attr}".config.clanCore.clanName'
|
||||
]
|
||||
)
|
||||
res = run_cmd(cmd)
|
||||
clan_name = res.strip('"')
|
||||
|
||||
proc = subprocess.run(cmd, text=True, capture_output=True)
|
||||
assert proc.stdout is not None
|
||||
if proc.returncode != 0:
|
||||
raise ClanError(
|
||||
f"""
|
||||
command: {shlex.join(cmd)}
|
||||
exit code: {proc.returncode}
|
||||
stdout:
|
||||
{proc.stdout}
|
||||
stderr:
|
||||
{proc.stderr}
|
||||
"""
|
||||
# Get the clan icon path
|
||||
cmd = nix_eval(
|
||||
[
|
||||
f'{flake_url}#clanInternals.machines."{system}"."{flake_attr}".config.clanCore.clanIcon'
|
||||
]
|
||||
)
|
||||
res = run_cmd(cmd)
|
||||
|
||||
# If the icon is null, no icon is set for this cLAN
|
||||
if res == "null":
|
||||
icon_path = None
|
||||
else:
|
||||
icon_path = res.strip('"')
|
||||
|
||||
cmd = nix_build(
|
||||
[
|
||||
f'{flake_url}#clanInternals.machines."{system}"."{flake_attr}".config.clanCore.clanIcon'
|
||||
],
|
||||
specific_groot_dir(clan_name=clan_name, flake_url=str(flake_url))
|
||||
/ "clanIcon",
|
||||
)
|
||||
clan_name = proc.stdout.strip().strip('"')
|
||||
run_cmd(cmd)
|
||||
|
||||
# Get the flake metadata
|
||||
meta = nix_metadata(flake_url)
|
||||
|
||||
return FlakeConfig(
|
||||
|
@ -25,20 +25,32 @@ def nix_flake_show(flake_url: str | Path) -> list[str]:
|
||||
)
|
||||
|
||||
|
||||
def nix_build(
|
||||
flags: list[str],
|
||||
) -> list[str]:
|
||||
return (
|
||||
nix_command(
|
||||
[
|
||||
"build",
|
||||
"--no-link",
|
||||
"--print-out-paths",
|
||||
"--no-write-lock-file",
|
||||
]
|
||||
def nix_build(flags: list[str], gcroot: Path | None = None) -> list[str]:
|
||||
if gcroot is not None:
|
||||
return (
|
||||
nix_command(
|
||||
[
|
||||
"build",
|
||||
"--out-link",
|
||||
str(gcroot),
|
||||
"--print-out-paths",
|
||||
"--no-write-lock-file",
|
||||
]
|
||||
)
|
||||
+ flags
|
||||
)
|
||||
else:
|
||||
return (
|
||||
nix_command(
|
||||
[
|
||||
"build",
|
||||
"--no-link",
|
||||
"--print-out-paths",
|
||||
"--no-write-lock-file",
|
||||
]
|
||||
)
|
||||
+ flags
|
||||
)
|
||||
+ flags
|
||||
)
|
||||
|
||||
|
||||
def nix_config() -> dict[str, Any]:
|
||||
|
@ -10,7 +10,7 @@ from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import IO
|
||||
|
||||
from ..dirs import module_root
|
||||
from ..dirs import module_root, specific_groot_dir
|
||||
from ..errors import ClanError
|
||||
from ..nix import nix_build, nix_config, nix_shell
|
||||
from .inspect import VmConfig, inspect_vm
|
||||
@ -131,7 +131,9 @@ def get_vm_create_info(vm: VmConfig, nix_options: list[str]) -> dict[str, str]:
|
||||
[
|
||||
f'{clan_dir}#clanInternals.machines."{system}"."{machine}".config.system.clan.vm.create',
|
||||
*nix_options,
|
||||
]
|
||||
],
|
||||
specific_groot_dir(clan_name=vm.clan_name, flake_url=str(vm.flake_url))
|
||||
/ f"vm-{machine}",
|
||||
)
|
||||
proc = subprocess.run(
|
||||
cmd,
|
||||
|
@ -19,15 +19,18 @@
|
||||
"**/.mypy_cache": true,
|
||||
"**/.reports": true,
|
||||
"**/.ruff_cache": true,
|
||||
"**/result": true
|
||||
"**/result": true,
|
||||
"/nix/store/**": true
|
||||
},
|
||||
"search.exclude": {
|
||||
"**/.direnv": true,
|
||||
"**/.mypy_cache": true,
|
||||
"**/.ruff_cache": true,
|
||||
"**/.hypothesis": true,
|
||||
"**/__pycache__": true,
|
||||
"**/.reports": true
|
||||
}
|
||||
"**/.direnv": true,
|
||||
"**/.hypothesis": true,
|
||||
"**/.mypy_cache": true,
|
||||
"**/.reports": true,
|
||||
"**/.ruff_cache": true,
|
||||
"/nix/store/**": true
|
||||
},
|
||||
"files.autoSave": "off"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user