install: default jj setup in one-click flow
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
param(
|
||||
[string]$RepoUrl = "https://fun-md.com/Fun_MD/devops-skills.git",
|
||||
[string]$CodexHome = "$HOME\.codex"
|
||||
[string]$CodexHome = "$HOME\.codex",
|
||||
[switch]$SkipJj,
|
||||
[ValidateSet("auto", "winget", "scoop", "cargo")]
|
||||
[string]$JjInstallMethod = $(if ($env:JJ_INSTALL_METHOD) { $env:JJ_INSTALL_METHOD } else { "auto" }),
|
||||
[ValidateSet("release", "prerelease")]
|
||||
[string]$JjChannel = $(if ($env:JJ_CHANNEL) { $env:JJ_CHANNEL } else { "release" })
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
@@ -8,13 +13,136 @@ $ErrorActionPreference = "Stop"
|
||||
$skillName = "gitea-issue-devops-agent"
|
||||
$targetDir = Join-Path $CodexHome "skills\$skillName"
|
||||
$tmpRoot = Join-Path $env:TEMP ("devops-skills-" + [Guid]::NewGuid().ToString("N"))
|
||||
$installJj = $true
|
||||
if ($SkipJj.IsPresent) {
|
||||
$installJj = $false
|
||||
}
|
||||
if ($env:INSTALL_JJ -and $env:INSTALL_JJ -eq "0") {
|
||||
$installJj = $false
|
||||
}
|
||||
|
||||
function Write-InstallLog {
|
||||
param([string]$Message)
|
||||
Write-Host "[install] $Message"
|
||||
}
|
||||
|
||||
function Write-InstallWarn {
|
||||
param([string]$Message)
|
||||
Write-Warning "[install] $Message"
|
||||
}
|
||||
|
||||
function Test-CommandAvailable {
|
||||
param([string]$Name)
|
||||
return $null -ne (Get-Command $Name -ErrorAction SilentlyContinue)
|
||||
}
|
||||
|
||||
function Show-JjManualHelp {
|
||||
Write-InstallWarn "jj was not installed automatically."
|
||||
Write-InstallWarn "Manual options:"
|
||||
Write-InstallWarn " - winget install jj-vcs.jj"
|
||||
Write-InstallWarn " - scoop install main/jj"
|
||||
if ($JjChannel -eq "prerelease") {
|
||||
Write-InstallWarn " - cargo install --git https://github.com/jj-vcs/jj.git --locked --bin jj jj-cli"
|
||||
}
|
||||
else {
|
||||
Write-InstallWarn " - cargo install --locked --bin jj jj-cli"
|
||||
}
|
||||
Write-InstallWarn "After installation, verify with: jj --version"
|
||||
}
|
||||
|
||||
function Install-JjWithWinget {
|
||||
if (-not (Test-CommandAvailable winget)) {
|
||||
return $false
|
||||
}
|
||||
if ($JjChannel -ne "release") {
|
||||
Write-InstallWarn "winget path skipped because prerelease jj is requested."
|
||||
return $false
|
||||
}
|
||||
|
||||
Write-InstallLog "attempting jj installation via winget"
|
||||
& winget install --id jj-vcs.jj -e --accept-source-agreements --accept-package-agreements
|
||||
return $LASTEXITCODE -eq 0
|
||||
}
|
||||
|
||||
function Install-JjWithScoop {
|
||||
if (-not (Test-CommandAvailable scoop)) {
|
||||
return $false
|
||||
}
|
||||
if ($JjChannel -ne "release") {
|
||||
Write-InstallWarn "scoop path skipped because prerelease jj is requested."
|
||||
return $false
|
||||
}
|
||||
|
||||
Write-InstallLog "attempting jj installation via scoop"
|
||||
& scoop install main/jj
|
||||
return $LASTEXITCODE -eq 0
|
||||
}
|
||||
|
||||
function Install-JjWithCargo {
|
||||
if (-not (Test-CommandAvailable cargo)) {
|
||||
return $false
|
||||
}
|
||||
|
||||
Write-InstallLog "attempting jj installation via cargo"
|
||||
if ($JjChannel -eq "prerelease") {
|
||||
& cargo install --git https://github.com/jj-vcs/jj.git --locked --bin jj jj-cli
|
||||
}
|
||||
else {
|
||||
& cargo install --locked --bin jj jj-cli
|
||||
}
|
||||
return $LASTEXITCODE -eq 0
|
||||
}
|
||||
|
||||
function Invoke-JjInstall {
|
||||
if (-not $installJj) {
|
||||
Write-InstallLog "skipping jj installation because INSTALL_JJ=0 or -SkipJj was provided"
|
||||
return
|
||||
}
|
||||
|
||||
if (Test-CommandAvailable jj) {
|
||||
Write-InstallLog "jj already installed: $(& jj --version)"
|
||||
return
|
||||
}
|
||||
|
||||
$installed = $false
|
||||
switch ($JjInstallMethod) {
|
||||
"auto" {
|
||||
$installed = (Install-JjWithWinget) -or (Install-JjWithScoop) -or (Install-JjWithCargo)
|
||||
break
|
||||
}
|
||||
"winget" {
|
||||
$installed = Install-JjWithWinget
|
||||
break
|
||||
}
|
||||
"scoop" {
|
||||
$installed = Install-JjWithScoop
|
||||
break
|
||||
}
|
||||
"cargo" {
|
||||
$installed = Install-JjWithCargo
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $installed) {
|
||||
Show-JjManualHelp
|
||||
return
|
||||
}
|
||||
|
||||
if (Test-CommandAvailable jj) {
|
||||
Write-InstallLog "jj installation succeeded: $(& jj --version)"
|
||||
}
|
||||
else {
|
||||
Show-JjManualHelp
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
|
||||
if (-not (Test-CommandAvailable git)) {
|
||||
throw "[install] git is required but not found."
|
||||
}
|
||||
|
||||
Write-Host "[install] downloading $skillName from $RepoUrl"
|
||||
Write-InstallLog "downloading $skillName from $RepoUrl"
|
||||
git clone --depth 1 $RepoUrl $tmpRoot | Out-Null
|
||||
|
||||
$sourceDir = Join-Path $tmpRoot "skills\$skillName"
|
||||
@@ -28,8 +156,10 @@ try {
|
||||
}
|
||||
Copy-Item -Path $sourceDir -Destination $targetDir -Recurse -Force
|
||||
|
||||
Write-Host "[install] done"
|
||||
Write-Host "[install] installed path: $targetDir"
|
||||
Write-InstallLog "skill installed"
|
||||
Write-InstallLog "installed path: $targetDir"
|
||||
Invoke-JjInstall
|
||||
Write-InstallLog "done"
|
||||
}
|
||||
finally {
|
||||
if (Test-Path $tmpRoot) {
|
||||
|
||||
@@ -6,6 +6,119 @@ SKILL_NAME="gitea-issue-devops-agent"
|
||||
CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
|
||||
TARGET_DIR="${CODEX_HOME}/skills/${SKILL_NAME}"
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
INSTALL_JJ="${INSTALL_JJ:-1}"
|
||||
JJ_INSTALL_METHOD="${JJ_INSTALL_METHOD:-auto}"
|
||||
JJ_CHANNEL="${JJ_CHANNEL:-release}"
|
||||
|
||||
log() {
|
||||
echo "[install] $*"
|
||||
}
|
||||
|
||||
warn() {
|
||||
echo "[install] warning: $*" >&2
|
||||
}
|
||||
|
||||
manual_jj_help() {
|
||||
warn "jj was not installed automatically."
|
||||
warn "Manual options:"
|
||||
warn " - Homebrew: brew install jj"
|
||||
warn " - cargo-binstall: cargo binstall --strategies crate-meta-data jj-cli"
|
||||
if [ "$JJ_CHANNEL" = "prerelease" ]; then
|
||||
warn " - cargo prerelease: cargo install --git https://github.com/jj-vcs/jj.git --locked --bin jj jj-cli"
|
||||
else
|
||||
warn " - cargo release: cargo install --locked --bin jj jj-cli"
|
||||
fi
|
||||
warn "After installation, verify with: jj --version"
|
||||
}
|
||||
|
||||
install_jj_with_brew() {
|
||||
if ! command -v brew >/dev/null 2>&1; then
|
||||
return 1
|
||||
fi
|
||||
if [ "$JJ_CHANNEL" != "release" ]; then
|
||||
warn "brew path skipped because prerelease jj is requested."
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "attempting jj installation via Homebrew"
|
||||
brew install jj
|
||||
}
|
||||
|
||||
install_jj_with_binstall() {
|
||||
if ! command -v cargo >/dev/null 2>&1 || ! command -v cargo-binstall >/dev/null 2>&1; then
|
||||
return 1
|
||||
fi
|
||||
if [ "$JJ_CHANNEL" != "release" ]; then
|
||||
warn "cargo-binstall path skipped because prerelease jj is requested."
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "attempting jj installation via cargo-binstall"
|
||||
cargo binstall --strategies crate-meta-data jj-cli
|
||||
}
|
||||
|
||||
install_jj_with_cargo() {
|
||||
if ! command -v cargo >/dev/null 2>&1; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "attempting jj installation via cargo"
|
||||
if [ "$JJ_CHANNEL" = "prerelease" ]; then
|
||||
cargo install --git https://github.com/jj-vcs/jj.git --locked --bin jj jj-cli
|
||||
else
|
||||
cargo install --locked --bin jj jj-cli
|
||||
fi
|
||||
}
|
||||
|
||||
attempt_jj_install() {
|
||||
if [ "$INSTALL_JJ" = "0" ]; then
|
||||
log "skipping jj installation because INSTALL_JJ=0"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if command -v jj >/dev/null 2>&1; then
|
||||
log "jj already installed: $(jj --version)"
|
||||
return 0
|
||||
fi
|
||||
|
||||
case "$JJ_INSTALL_METHOD" in
|
||||
auto)
|
||||
install_jj_with_brew || install_jj_with_binstall || install_jj_with_cargo || {
|
||||
manual_jj_help
|
||||
return 0
|
||||
}
|
||||
;;
|
||||
brew)
|
||||
install_jj_with_brew || {
|
||||
manual_jj_help
|
||||
return 0
|
||||
}
|
||||
;;
|
||||
binstall)
|
||||
install_jj_with_binstall || {
|
||||
manual_jj_help
|
||||
return 0
|
||||
}
|
||||
;;
|
||||
cargo)
|
||||
install_jj_with_cargo || {
|
||||
manual_jj_help
|
||||
return 0
|
||||
}
|
||||
;;
|
||||
*)
|
||||
warn "unsupported JJ_INSTALL_METHOD='$JJ_INSTALL_METHOD'; skipping jj install."
|
||||
manual_jj_help
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
if command -v jj >/dev/null 2>&1; then
|
||||
log "jj installation succeeded: $(jj --version)"
|
||||
else
|
||||
manual_jj_help
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
rm -rf "$TMP_DIR"
|
||||
@@ -13,15 +126,15 @@ cleanup() {
|
||||
trap cleanup EXIT
|
||||
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
echo "[install] git is required but not found."
|
||||
log "git is required but not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[install] downloading ${SKILL_NAME} from ${REPO_URL}"
|
||||
log "downloading ${SKILL_NAME} from ${REPO_URL}"
|
||||
git clone --depth 1 "$REPO_URL" "$TMP_DIR/repo" >/dev/null 2>&1
|
||||
|
||||
if [ ! -d "$TMP_DIR/repo/skills/${SKILL_NAME}" ]; then
|
||||
echo "[install] skill directory not found in repository."
|
||||
log "skill directory not found in repository."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -29,5 +142,7 @@ mkdir -p "${CODEX_HOME}/skills"
|
||||
rm -rf "$TARGET_DIR"
|
||||
cp -R "$TMP_DIR/repo/skills/${SKILL_NAME}" "$TARGET_DIR"
|
||||
|
||||
echo "[install] done"
|
||||
echo "[install] installed path: ${TARGET_DIR}"
|
||||
log "skill installed"
|
||||
log "installed path: ${TARGET_DIR}"
|
||||
attempt_jj_install
|
||||
log "done"
|
||||
|
||||
Reference in New Issue
Block a user