Skip to content
Draft
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
21 changes: 21 additions & 0 deletions .github/scripts/generate-package-manifests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail
version=${1:?version required}
directory=${2:?verified release directory required}
destination=${3:?destination required}
[[ "$version" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]
linux="scouterctl-$version-linux-x64.zip"
windows="scouterctl-$version-windows-x64.zip"
expected=$(cd "$directory" && sha256sum "$linux" "$windows")
[[ "$(cat "$directory/SHA256SUMS")" == "$expected" ]]
for name in "$linux" "$windows"; do
[[ "$(unzip -p "$directory/$name" "scouterctl-$version/version.txt")" == "$version" ]]
done
linux_hash=$(printf '%s\n' "$expected" | head -1 | cut -d' ' -f1)
windows_hash=$(printf '%s\n' "$expected" | tail -1 | cut -d' ' -f1)
mkdir -p "$destination/Formula" "$destination/bucket"
sed -e "s/@VERSION@/$version/g" -e "s/@LINUX_SHA256@/$linux_hash/g" \
packaging/homebrew.rb.in > "$destination/Formula/scouterctl.rb"
sed -e "s/@VERSION@/$version/g" -e "s/@WINDOWS_SHA256@/$windows_hash/g" \
packaging/scoop.json.in > "$destination/bucket/scouterctl.json"
printf 'Generated Homebrew and Scoop definitions for %s\n' "$version"
46 changes: 46 additions & 0 deletions .github/scripts/update-package-index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
set -euo pipefail
: "${GH_REPO:?}" "${RELEASE_TAG:?}" "${PACKAGE_VERSION:?}"
[[ "$GH_REPO" == "oxspan/scouterctl" ]]
[[ "$RELEASE_TAG" == "v$PACKAGE_VERSION" ]]
[[ "$PACKAGE_VERSION" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]
bash .github/scripts/generate-package-manifests.sh "$PACKAGE_VERSION" build/release build/package-index
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
base=$(gh api "repos/$GH_REPO" --jq .default_branch)
sha=$(gh api "repos/$GH_REPO/git/ref/heads/$base" --jq .object.sha)
gh api "repos/$GH_REPO/contents/bucket/scouterctl.json?ref=$sha" --jq .content | base64 --decode > "$work/current.json"
current=$(jq -r .version "$work/current.json")
if [[ "$(printf '%s\n' "$current" "$PACKAGE_VERSION" | sort -V | tail -1)" != "$PACKAGE_VERSION" ]]; then
printf 'Skipping older package index %s (current %s)\n' "$PACKAGE_VERSION" "$current"
exit 0
fi
gh api "repos/$GH_REPO/contents/Formula/scouterctl.rb?ref=$sha" --jq .content | base64 --decode > "$work/current.rb"
if cmp -s "$work/current.json" build/package-index/bucket/scouterctl.json && cmp -s "$work/current.rb" build/package-index/Formula/scouterctl.rb; then
printf 'Package index already current\n'
exit 0
fi
branch="automation/packages-v$PACKAGE_VERSION"
if [[ -n "$(gh pr list --repo "$GH_REPO" --head "$branch" --state open --json number --jq '.[].number')" ]]; then
printf 'Package index pull request already open\n'
exit 0
fi
if gh api "repos/$GH_REPO/git/ref/heads/$branch" > /dev/null 2>&1; then
gh api "repos/$GH_REPO/contents/bucket/scouterctl.json?ref=$branch" --jq .content | base64 --decode > "$work/branch.json"
gh api "repos/$GH_REPO/contents/Formula/scouterctl.rb?ref=$branch" --jq .content | base64 --decode > "$work/branch.rb"
cmp "$work/branch.json" build/package-index/bucket/scouterctl.json
cmp "$work/branch.rb" build/package-index/Formula/scouterctl.rb
else
base_tree=$(gh api "repos/$GH_REPO/git/commits/$sha" --jq .tree.sha)
jq -n --arg base "$base_tree" --rawfile formula build/package-index/Formula/scouterctl.rb \
--rawfile scoop build/package-index/bucket/scouterctl.json \
'{base_tree:$base,tree:[{path:"Formula/scouterctl.rb",mode:"100644",type:"blob",content:$formula},{path:"bucket/scouterctl.json",mode:"100644",type:"blob",content:$scoop}]}' > "$work/tree.json"
tree=$(gh api --method POST "repos/$GH_REPO/git/trees" --input "$work/tree.json" --jq .sha)
jq -n --arg tree "$tree" --arg parent "$sha" --arg version "$PACKAGE_VERSION" \
'{message:("chore: update package managers to " + $version),tree:$tree,parents:[$parent]}' > "$work/commit.json"
commit=$(gh api --method POST "repos/$GH_REPO/git/commits" --input "$work/commit.json" --jq .sha)
gh api --method POST "repos/$GH_REPO/git/refs" -f ref="refs/heads/$branch" -f sha="$commit" > /dev/null
fi
printf 'Update Homebrew and Scoop to %s using the verified release checksums. Run CI and release manually on this branch before merging; pull requests created with GITHUB_TOKEN do not trigger pull_request workflows.\n' "$PACKAGE_VERSION" > "$work/body.md"
gh pr create --repo "$GH_REPO" --base "$base" --head "$branch" \
--title "chore: update package managers to $PACKAGE_VERSION" --body-file "$work/body.md"
100 changes: 100 additions & 0 deletions .github/scripts/verify-scoop-installation.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
param(
[Parameter(Mandatory)][string]$Archive,
[Parameter(Mandatory)][string]$Version
)

$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
if ($env:GITHUB_ACTIONS -ne 'true' -or $env:RUNNER_ENVIRONMENT -ne 'github-hosted' -or $env:RUNNER_OS -ne 'Windows') {
throw 'Run this installation check on a disposable GitHub-hosted Windows runner.'
}
$archivePath = (Resolve-Path $Archive).Path
$work = Join-Path $env:GITHUB_WORKSPACE 'build/scoop-qa'
if (Test-Path $work) { throw 'Scoop verification requires a fresh directory.' }
New-Item -ItemType Directory -Path $work | Out-Null
Start-Transcript -Path "$work/scoop.log" | Out-Null
$userPath = [Environment]::GetEnvironmentVariable('PATH', 'User')
$userJava = [Environment]::GetEnvironmentVariable('JAVA_HOME', 'User')

function Save-VerifiedArchive([string]$Url, [string]$Hash, [string]$Destination) {
Invoke-WebRequest $Url -OutFile $Destination
if ((Get-FileHash $Destination -Algorithm SHA256).Hash.ToLowerInvariant() -cne $Hash) {
throw "Archive checksum mismatch: $Url"
}
}

function Invoke-Scoop([string[]]$Arguments) {
& $script:scoopCommand @Arguments
if ($LASTEXITCODE -ne 0) { throw "Scoop failed: $Arguments" }
}

try {
$env:SCOOP = "$work/scoop"
$env:SCOOP_GLOBAL = "$work/global"
$env:SCOOP_CACHE = "$work/cache"
$env:XDG_CONFIG_HOME = "$work/config"
$env:SCOUTERCTL_CONFIG = "$work/user-data/연결 설정.json"
$env:PATH = "$env:SystemRoot\System32;$env:SystemRoot\System32\WindowsPowerShell\v1.0;$env:SCOOP\shims"
Remove-Item Env:JAVA_HOME -ErrorAction SilentlyContinue
foreach ($name in @('JAVA_OPTS', 'SCOUTERCTL_OPTS', 'JAVA_TOOL_OPTIONS', 'JDK_JAVA_OPTIONS', 'SCOUTERCTL_PASSWORD')) {
Remove-Item "Env:$name" -ErrorAction SilentlyContinue
}
if (Get-Command java -ErrorAction SilentlyContinue) { throw 'Java must be absent from the initial PATH.' }

Save-VerifiedArchive 'https://codeload.github.com/ScoopInstaller/Scoop/zip/e6aa3b366bdee8ed138c1e0f7b85192ebdd35d0f' 'fa96b15950f3726d2c9a35493e192eefe56d2eddba718e8121c32f7a19257a0a' "$work/scoop.zip"
Save-VerifiedArchive 'https://codeload.github.com/ScoopInstaller/Java/zip/c2fcb00219a54d701791b1022f3b7b0b857dd5af' 'cfc8ac6b46b60eb5a78dd6a3d3541d4431435b2fc8b93ccf5cb69103af40e3ed' "$work/java.zip"
Save-VerifiedArchive 'https://github.com/oxspan/scouterctl/releases/download/v1.0.0/scouterctl-1.0.0-windows-x64.zip' 'ede20898d4d936c87932d9cf1efa9d28571311c18ef741c53ce7de0b698aaac6' "$work/previous.zip"
Expand-Archive "$work/scoop.zip" "$work/source"
Expand-Archive "$work/java.zip" "$work/java-source"
New-Item -ItemType Directory -Path "$env:SCOOP/apps/scoop", "$env:SCOOP/buckets", "$env:SCOOP/shims", "$env:XDG_CONFIG_HOME/scoop" | Out-Null
Move-Item "$work/source/Scoop-e6aa3b366bdee8ed138c1e0f7b85192ebdd35d0f" "$env:SCOOP/apps/scoop/current"
Move-Item "$work/java-source/Java-c2fcb00219a54d701791b1022f3b7b0b857dd5af" "$env:SCOOP/buckets/java"
$bucket = New-Item -ItemType Directory -Path "$env:SCOOP/buckets/scouterctl/bucket"
@{last_update = (Get-Date).ToString('o'); show_update_log = $false; use_sqlite_cache = $false} |
ConvertTo-Json | Set-Content "$env:XDG_CONFIG_HOME/scoop/config.json" -Encoding utf8
$script:scoopCommand = "$env:SCOOP/apps/scoop/current/bin/scoop.ps1"

$manifest = Get-Content 'bucket/scouterctl.json' -Raw | ConvertFrom-Json
$manifest.version = '1.0.0'
$manifest.extract_dir = 'scouterctl-1.0.0'
$manifest.architecture.'64bit'.url = ([uri]"$work/previous.zip").AbsoluteUri
$manifest.architecture.'64bit'.hash = (Get-FileHash "$work/previous.zip" -Algorithm SHA256).Hash.ToLowerInvariant()
$manifest | ConvertTo-Json -Depth 10 | Set-Content "$bucket/scouterctl.json" -Encoding utf8
Invoke-Scoop -Arguments @('install', 'scouterctl/scouterctl', '--no-update-scoop')
$expectedJava = (Resolve-Path "$env:SCOOP/apps/temurin21-jre/current").Path
if ([IO.Path]::GetFullPath($env:JAVA_HOME) -ine $expectedJava) { throw 'Scoop did not select its Java dependency.' }
foreach ($app in @('scouterctl', 'temurin21-jre')) {
if ((Get-Item "$env:SCOOP/apps/$app/current").LinkType -ne 'Junction') { throw "Missing default junction: $app" }
}
$cli = "$env:SCOOP/shims/scouterctl.exe"
if ((& $cli --version) -cne 'scouterctl 1.0.0' -or $LASTEXITCODE -ne 0) { throw 'Previous Scoop package did not execute.' }
& $cli context add --name '운영_서울' --user '관측 사용자'
if ($LASTEXITCODE -ne 0) { throw 'Scoop package could not write configuration.' }
& $cli context use --name '운영_서울'
if ($LASTEXITCODE -ne 0) { throw 'Scoop package could not select a context.' }
$saved = (Get-FileHash $env:SCOUTERCTL_CONFIG -Algorithm SHA256).Hash

$manifest.version = $Version
$manifest.extract_dir = "scouterctl-$Version"
$manifest.architecture.'64bit'.url = ([uri]$archivePath).AbsoluteUri
$manifest.architecture.'64bit'.hash = (Get-FileHash $archivePath -Algorithm SHA256).Hash.ToLowerInvariant()
$manifest | ConvertTo-Json -Depth 10 | Set-Content "$bucket/scouterctl.json" -Encoding utf8
Invoke-Scoop -Arguments @('update', 'scouterctl')
if ((& $cli --version) -cne "scouterctl $Version" -or $LASTEXITCODE -ne 0) { throw 'Scoop upgrade did not execute the candidate.' }
$junction = Get-Item "$env:SCOOP/apps/scouterctl/current"
if ($junction.LinkType -ne 'Junction' -or (Split-Path $junction.Target -Leaf) -cne $Version) { throw 'Scoop current junction did not advance.' }
$contexts = (& $cli context list) | ConvertFrom-Json
if ($LASTEXITCODE -ne 0 -or $contexts.data.current -cne '운영_서울' -or $contexts.data.contexts.'운영_서울'.user -cne '관측 사용자') {
throw 'Scoop upgrade lost the saved Unicode context.'
}
Invoke-Scoop -Arguments @('uninstall', 'scouterctl')
if ((Test-Path $cli) -or (Get-FileHash $env:SCOUTERCTL_CONFIG -Algorithm SHA256).Hash -cne $saved) {
throw 'Scoop uninstall left the command installed or changed user configuration.'
}
Invoke-Scoop -Arguments @('uninstall', 'temurin21-jre')
'PASS: Scoop automatic Java dependency, default junctions, previous release -> candidate upgrade, Unicode configuration and uninstall'
} finally {
[Environment]::SetEnvironmentVariable('PATH', $userPath, 'User')
[Environment]::SetEnvironmentVariable('JAVA_HOME', $userJava, 'User')
Stop-Transcript | Out-Null
}
Loading
Loading