launcher: automatic releases, the version built in from the tag
launcher.yml releases the launcher by itself: after a push to main that changes launcher/, crates/horizon-prepare or crates/horizon-theme, hourly, and by hand, with the game's rules (tools/release_train.py decide --kind launcher: player-facing pull requests and a 3-hour cooldown, release-now, skip-release, RELEASES_PAUSED). launcher-vX.Y.Z is the next patch, or the next minor after a pull request labelled feature. Linux on ubuntu-22.04, Windows on GitHub, macOS on the Mac mini's runner; published with --latest=false. No version-bump commits: VERSION reads HORIZON_LAUNCHER_VERSION with option_env!, falling back to Cargo.toml's, and --version, the User-Agent and the self-update comparison use it; each build checks --version says the release's version. With several game releases a day, the newest launcher release soon falls out of the newest 100 (launcher) or 30 (website) releases: both now look the newest launcher-v tags up one by one when the list has none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+131
-27
@@ -1,64 +1,147 @@
|
||||
name: launcher
|
||||
# Builds the launcher on Linux, macOS and Windows. A pushed `launcher-vX.Y.Z` tag also puts the
|
||||
# three archives on a draft GitHub release of that tag, to publish by hand. Horizon's own
|
||||
# releases are tagged `vYYYY.MM.DD`; the launcher reads only `launcher-v*` releases for itself.
|
||||
# Builds the launcher on Linux, macOS and Windows, and releases it by itself (docs/release-flow.md): after a
|
||||
# push to main that changes the launcher or what it builds in (crates/horizon-prepare, crates/horizon-theme),
|
||||
# every hour (a release the cooldown held goes out) and by hand, tools/release_train.py decides as for the game.
|
||||
# A release is launcher-vX.Y.Z: the patch after the last launcher tag, or the next minor when a merged pull
|
||||
# request is labelled feature. The version is given to the build (HORIZON_LAUNCHER_VERSION): no bump commits.
|
||||
# Never marked latest. Pushes to launcher branches only build. RELEASES_PAUSED=1 stops releases.
|
||||
# gh workflow run launcher --ref <branch> # dry run: builds everything, publishes nothing
|
||||
# gh workflow run launcher --ref main -f dry_run=false -f force=true
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [launcher, 'launcher-*']
|
||||
tags: ['launcher-v*']
|
||||
branches: [main, launcher, 'launcher-*']
|
||||
paths:
|
||||
- 'launcher/**'
|
||||
- 'crates/horizon-prepare/**'
|
||||
- 'crates/horizon-theme/**'
|
||||
- '.github/workflows/launcher.yml'
|
||||
schedule:
|
||||
- cron: '47 * * * *'
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
dry_run:
|
||||
description: Build everything and write the notes, but publish nothing
|
||||
type: boolean
|
||||
default: true
|
||||
force:
|
||||
description: Release even without launcher changes, within the cooldown or while paused
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: launcher-${{ github.ref == 'refs/heads/main' && 'release' || github.ref }}
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
decide:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
outputs:
|
||||
release: ${{ steps.decide.outputs.release }}
|
||||
tag: ${{ steps.decide.outputs.tag }}
|
||||
head: ${{ steps.decide.outputs.head }}
|
||||
version: ${{ steps.decide.outputs.version }}
|
||||
dry_run: ${{ steps.mode.outputs.dry_run }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- id: mode
|
||||
# Off main every run is a dry run (a launcher branch's push only builds).
|
||||
run: echo "dry_run=${{ github.ref != 'refs/heads/main' || (github.event_name == 'workflow_dispatch' && inputs.dry_run) }}" >> "$GITHUB_OUTPUT"
|
||||
- id: decide
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
RELEASES_PAUSED: ${{ vars.RELEASES_PAUSED }}
|
||||
# A push or a run off main builds its own commit; otherwise main's newest commit with green checks.
|
||||
HEAD_SHA: ${{ (github.event_name == 'push' || steps.mode.outputs.dry_run == 'true') && github.sha || '' }}
|
||||
FORCE: ${{ inputs.force && 'yes' || '' }}
|
||||
run: |
|
||||
python3 tools/release_train.py decide --kind launcher ${HEAD_SHA:+--head "$HEAD_SHA"} ${FORCE:+--force} | tee decision.json
|
||||
echo "### $(jq -r '.reason' decision.json)" >> "$GITHUB_STEP_SUMMARY"
|
||||
tag=$(jq -r '.tag' decision.json)
|
||||
echo "version=${tag#launcher-v}" >> "$GITHUB_OUTPUT"
|
||||
# A dry run (and a launcher branch's push) builds whatever the decision.
|
||||
if [[ "${{ steps.mode.outputs.dry_run }}" == true ]]; then
|
||||
echo "release=true" >> "$GITHUB_OUTPUT"
|
||||
echo "head=$GITHUB_SHA" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
build:
|
||||
needs: decide
|
||||
if: needs.decide.outputs.release == 'true'
|
||||
name: build ${{ matrix.name }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
- name: linux
|
||||
os: ubuntu-22.04
|
||||
asset: horizon-launcher-linux-x86_64.tar.gz
|
||||
binary: horizon-launcher
|
||||
- os: macos-latest
|
||||
- name: macos
|
||||
mac: true
|
||||
asset: horizon-launcher-macos-arm64.zip
|
||||
binary: horizon-launcher
|
||||
- os: windows-latest
|
||||
- name: windows
|
||||
os: windows-latest
|
||||
asset: horizon-launcher-windows-x64.zip
|
||||
binary: horizon-launcher.exe
|
||||
# The C runtime linked in: without it the launcher asks for VCRUNTIME140.dll,
|
||||
# which only the Visual C++ redistributable installs.
|
||||
rustflags: -C target-feature=+crt-static
|
||||
runs-on: ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.mac && (vars.MAC_RUNNER || 'ludovics-mac-mini') || matrix.os }}
|
||||
timeout-minutes: 40
|
||||
env:
|
||||
RUSTFLAGS: ${{ matrix.rustflags }}
|
||||
# Horizon's Azure app for Microsoft sign-in (docs/microsoft-account.md): a repository
|
||||
# variable, not a secret. Unset, the launcher says sign-in is not configured.
|
||||
HORIZON_MSA_CLIENT_ID: ${{ vars.HORIZON_MSA_CLIENT_ID }}
|
||||
# The release's version, built in (launcher/src/backend.rs VERSION); a launcher branch's build keeps
|
||||
# Cargo.toml's.
|
||||
HORIZON_LAUNCHER_VERSION: ${{ (github.event_name != 'push' || github.ref == 'refs/heads/main') && needs.decide.outputs.version || '' }}
|
||||
defaults:
|
||||
run:
|
||||
working-directory: launcher
|
||||
shell: bash
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ needs.decide.outputs.head }}
|
||||
persist-credentials: false
|
||||
# The Mac mini's runner keeps its target/ between runs.
|
||||
clean: ${{ runner.environment == 'github-hosted' }}
|
||||
- uses: dtolnay/rust-toolchain@stable
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
if: runner.environment == 'github-hosted'
|
||||
with:
|
||||
workspaces: launcher
|
||||
shared-key: launcher-${{ matrix.name }}
|
||||
- name: Linux libraries GPUI links to
|
||||
if: runner.os == 'Linux'
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libxkbcommon-x11-dev libwayland-dev libx11-xcb-dev libfontconfig-dev libvulkan-dev libasound2-dev
|
||||
- name: The tag matches Cargo.toml
|
||||
if: startsWith(github.ref, 'refs/tags/launcher-v')
|
||||
run: grep -qx "version = \"${GITHUB_REF_NAME#launcher-v}\"" Cargo.toml
|
||||
- run: cargo test --release --locked --lib
|
||||
- run: cargo build --release --locked
|
||||
- name: The version is the release's
|
||||
run: |
|
||||
out=$(target/release/${{ matrix.binary }} --version)
|
||||
echo "$out"
|
||||
expected="${HORIZON_LAUNCHER_VERSION:-$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)}"
|
||||
[[ "$out" == "horizon-launcher $expected" ]] || { echo "::error::expected horizon-launcher $expected"; exit 1; }
|
||||
- name: Only system libraries
|
||||
if: runner.os == 'Windows'
|
||||
run: python ../tools/check_imports.py target/release/${{ matrix.binary }}
|
||||
run: |
|
||||
file=target/release/${{ matrix.binary }}
|
||||
case "$RUNNER_OS" in
|
||||
Windows) python ../tools/check_imports.py "$file" ;;
|
||||
macOS) others=$(otool -L "$file" | tail -n +2 | awk '{print $1}' | grep -v -E '^(/usr/lib/|/System/Library/)' || true)
|
||||
[[ -z "$others" ]] || { echo "::error::links $others"; exit 1; } ;;
|
||||
esac
|
||||
- name: Smoke test
|
||||
env:
|
||||
HORIZON_LAUNCHER_NO_SELF_UPDATE: '1'
|
||||
@@ -67,10 +150,10 @@ jobs:
|
||||
set -euo pipefail
|
||||
export HORIZON_LAUNCHER_HOME="${RUNNER_TEMP//\\//}/horizon-launcher-smoke"
|
||||
export HORIZON_HOME="$HORIZON_LAUNCHER_HOME/game"
|
||||
rm -rf "$HORIZON_LAUNCHER_HOME"
|
||||
launcher="$PWD/target/release/${{ matrix.binary }}"
|
||||
# GitHub's API rate-limits shared runner addresses now and then: try a few times.
|
||||
retry() { for i in 1 2 3 4; do "$@" && return 0; sleep $((i * 15)); done; return 1; }
|
||||
"$launcher" --version
|
||||
retry "$launcher" versions
|
||||
retry "$launcher" install latest
|
||||
"$launcher" versions --installed
|
||||
@@ -86,16 +169,16 @@ jobs:
|
||||
soft() { if [[ "$RUNNER_OS" == "Linux" ]]; then "$@" || echo "::warning::$* failed"; else "$@"; fi; }
|
||||
if [[ "$RUNNER_OS" == "Windows" ]]; then
|
||||
python ../tools/check_imports.py "$client"
|
||||
python ../tools/check_imports.py "$launcher"
|
||||
elif [[ "$RUNNER_OS" == "Linux" ]]; then
|
||||
soft python3 ../tools/check_imports.py "$client"
|
||||
fi
|
||||
# The client starts: --help prints before any window or GPU is needed.
|
||||
help() { "$client" --help > "$RUNNER_TEMP/help.txt" 2>&1 && head -3 "$RUNNER_TEMP/help.txt" && grep -q -- '--resources' "$RUNNER_TEMP/help.txt"; }
|
||||
soft help
|
||||
rm -rf "$HORIZON_LAUNCHER_HOME"
|
||||
- name: Package
|
||||
run: |
|
||||
mkdir -p dist
|
||||
rm -rf dist ${{ matrix.asset }} && mkdir -p dist
|
||||
cp target/release/${{ matrix.binary }} dist/
|
||||
cd dist
|
||||
if [[ "${{ matrix.asset }}" == *.tar.gz ]]; then
|
||||
@@ -109,23 +192,44 @@ jobs:
|
||||
with:
|
||||
name: ${{ matrix.asset }}
|
||||
path: launcher/${{ matrix.asset }}
|
||||
retention-days: 7
|
||||
|
||||
release:
|
||||
if: startsWith(github.ref, 'refs/tags/launcher-v')
|
||||
needs: build
|
||||
needs: [decide, build]
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Notes
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
python3 tools/release_train.py notes --kind launcher --tag "${{ needs.decide.outputs.tag }}" \
|
||||
--head "${{ needs.decide.outputs.head }}" --out notes > /dev/null
|
||||
{ echo "## $(cat notes/title.txt)"; echo; cat notes/body.md; } >> "$GITHUB_STEP_SUMMARY"
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: dist
|
||||
merge-multiple: true
|
||||
# A draft, and never marked latest: Horizon's own releases stay the repository's latest.
|
||||
- uses: softprops/action-gh-release@v2
|
||||
# Never marked latest: Horizon's own releases stay the repository's latest.
|
||||
- name: Publish ${{ needs.decide.outputs.tag }}
|
||||
if: needs.decide.outputs.dry_run != 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TAG: ${{ needs.decide.outputs.tag }}
|
||||
run: |
|
||||
gh release create "$TAG" --target "${{ needs.decide.outputs.head }}" --title "$(cat notes/title.txt)" \
|
||||
--notes-file notes/body.md --latest=false dist/horizon-launcher-*
|
||||
- name: Dry run, the release that would be published
|
||||
if: needs.decide.outputs.dry_run == 'true'
|
||||
run: |
|
||||
echo "Would publish ${{ needs.decide.outputs.tag }} at ${{ needs.decide.outputs.head }}: $(cat notes/title.txt)"
|
||||
ls -l dist
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
tag_name: ${{ github.ref_name }}
|
||||
name: Horizon launcher ${{ github.ref_name }}
|
||||
draft: true
|
||||
make_latest: false
|
||||
files: dist/*
|
||||
name: launcher-release-notes
|
||||
path: notes/
|
||||
|
||||
@@ -184,3 +184,30 @@ list (`launcher/src/backend.rs` tests `withdrawn_release_is_never_offered`). The
|
||||
that day takes the next number, and its notes start from the last *published* release, so they list the
|
||||
withdrawn release's changes again with the fix. Usually the better way out is forward: revert the pull request,
|
||||
label the revert `release-now`, and a fixed release is out as soon as main's checks pass.
|
||||
|
||||
## Launcher releases
|
||||
|
||||
`.github/workflows/launcher.yml` releases the launcher the same way. It starts on a push to main that changes
|
||||
`launcher/`, `crates/horizon-prepare/` or `crates/horizon-theme/` (what the launcher builds in), every hour at :47,
|
||||
and by hand; pushes to `launcher` and `launcher-*` branches only build.
|
||||
|
||||
- `tools/release_train.py decide --kind launcher` counts the pull requests merged since the last published
|
||||
launcher release that changed those paths (not `launcher/links.json`, which the launcher reads from main, nor
|
||||
tests or Markdown), with the same 3-hour cooldown, `release-now`, `skip-release` and `RELEASES_PAUSED`.
|
||||
- The tag is `launcher-vX.Y.Z`: the patch after the last launcher tag, or the next minor (`X.Y+1.0`) when one of
|
||||
those pull requests is labelled `feature`.
|
||||
- No version-bump commits: the build gets the version in `HORIZON_LAUNCHER_VERSION`, which
|
||||
`launcher/src/backend.rs` reads with `option_env!` (falling back to `Cargo.toml`'s), so `--version`, the window,
|
||||
the User-Agent and the self-update comparison all use it. Each build checks `--version` says it.
|
||||
- Linux on GitHub `ubuntu-22.04`, Windows on `windows-latest`, macOS on the Mac mini's runner; each runs the
|
||||
launcher's tests, checks its libraries, and installs the latest game release with the new launcher.
|
||||
- Published with `--latest=false`: the repository's latest release stays a game release. Notes list the pull
|
||||
requests under New and Fixed; Kira posts launcher releases without pinging.
|
||||
|
||||
Starting by hand, pausing and rolling back work as for the game (`gh workflow run launcher …`,
|
||||
`RELEASES_PAUSED`, `gh release edit launcher-vX.Y.Z --draft`). Launchers older than the withdrawn release then
|
||||
see the previous one as the newest; launchers that already updated keep running.
|
||||
|
||||
With several game releases a day, the newest launcher release soon falls out of the newest 100 releases the
|
||||
launcher and the website read: both then look the newest `launcher-v` tags up one by one
|
||||
(`git/matching-refs/tags/launcher-v`, then `releases/tags/<tag>`).
|
||||
|
||||
+6
-5
@@ -52,11 +52,12 @@ It also updates itself from GitHub releases tagged `launcher-vX.Y.Z` (Horizon's
|
||||
own binary, and offers "Restart to update" in the sidebar. Development builds and
|
||||
`HORIZON_LAUNCHER_NO_SELF_UPDATE=1` never replace themselves.
|
||||
|
||||
To release the launcher: set `version` in `Cargo.toml`, then push a tag `launcher-vX.Y.Z`. The
|
||||
`launcher` workflow builds Linux, macOS and Windows and attaches
|
||||
`horizon-launcher-linux-x86_64.tar.gz`, `horizon-launcher-macos-arm64.zip` and
|
||||
`horizon-launcher-windows-x64.zip` to a draft release of that tag, never marked latest. Publish
|
||||
it by hand.
|
||||
Launcher releases are automatic (docs/release-flow.md in the repository): when main changes the
|
||||
launcher, `horizon-prepare` or `horizon-theme`, the `launcher` workflow builds Linux, macOS and
|
||||
Windows and publishes `launcher-vX.Y.Z` (the next patch, or the next minor after a pull request
|
||||
labelled `feature`) with `horizon-launcher-linux-x86_64.tar.gz`, `horizon-launcher-macos-arm64.zip`
|
||||
and `horizon-launcher-windows-x64.zip`, never marked latest. The version is built in from the tag
|
||||
(`HORIZON_LAUNCHER_VERSION`); `Cargo.toml`'s version is only what local builds report.
|
||||
|
||||
## Command line
|
||||
|
||||
|
||||
+102
-9
@@ -10,10 +10,18 @@ use std::sync::{Arc, Mutex};
|
||||
|
||||
pub const REPO: &str = "ludovic111/horizon";
|
||||
pub const README_URL: &str = "https://github.com/ludovic111/horizon/blob/main/launcher/README.md";
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
/// This launcher's version: the release workflow sets `HORIZON_LAUNCHER_VERSION` from the
|
||||
/// `launcher-vX.Y.Z` tag it builds (no version-bump commits); other builds say Cargo.toml's.
|
||||
pub const VERSION: &str = version_or(option_env!("HORIZON_LAUNCHER_VERSION"));
|
||||
/// Launcher releases are tagged `launcher-vX.Y.Z`; Horizon's own are `vYYYY.MM.DD`.
|
||||
pub const LAUNCHER_TAG_PREFIX: &str = "launcher-v";
|
||||
const AGENT: &str = concat!("horizon-launcher/", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
const fn version_or(injected: Option<&'static str>) -> &'static str {
|
||||
match injected {
|
||||
Some(v) if !v.is_empty() => v,
|
||||
_ => env!("CARGO_PKG_VERSION"),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize)]
|
||||
pub struct Release {
|
||||
@@ -63,7 +71,9 @@ const CLIENT: &str = if cfg!(windows) {
|
||||
};
|
||||
|
||||
fn agent() -> ureq::Agent {
|
||||
ureq::AgentBuilder::new().user_agent(AGENT).build()
|
||||
ureq::AgentBuilder::new()
|
||||
.user_agent(&format!("horizon-launcher/{VERSION}"))
|
||||
.build()
|
||||
}
|
||||
|
||||
fn get(url: &str) -> Result<ureq::Response, String> {
|
||||
@@ -176,11 +186,53 @@ pub fn releases() -> Result<Vec<Release>, String> {
|
||||
|
||||
/// Published launcher releases (`launcher-v…`), newest first, with this platform's archive.
|
||||
pub fn launcher_releases() -> Result<Vec<Release>, String> {
|
||||
Ok(parse_releases(
|
||||
&release_list()?,
|
||||
LAUNCHER_ASSET,
|
||||
is_launcher_tag,
|
||||
))
|
||||
Ok(launcher_releases_in(&release_list()?))
|
||||
}
|
||||
|
||||
/// The launcher releases in `list` (the newest 100 releases). Game releases come out several times
|
||||
/// a day, so the newest launcher release can be older than all of those: then the newest
|
||||
/// `launcher-v` tags are looked up one by one (a draft's tag is skipped: it has no public release).
|
||||
fn launcher_releases_in(list: &serde_json::Value) -> Vec<Release> {
|
||||
let found = parse_releases(list, LAUNCHER_ASSET, is_launcher_tag);
|
||||
if found.iter().any(|r| r.asset.is_some()) {
|
||||
return found;
|
||||
}
|
||||
let json = |url: String| -> Result<serde_json::Value, String> {
|
||||
get(&url)?.into_json().map_err(|e| e.to_string())
|
||||
};
|
||||
let api = format!("https://api.github.com/repos/{REPO}");
|
||||
let Ok(refs) = json(format!(
|
||||
"{api}/git/matching-refs/tags/{LAUNCHER_TAG_PREFIX}"
|
||||
)) else {
|
||||
return found;
|
||||
};
|
||||
for tag in newest_launcher_tags(&refs).into_iter().take(3) {
|
||||
if let Ok(release) = json(format!("{api}/releases/tags/{tag}")) {
|
||||
let one = parse_releases(
|
||||
&serde_json::json!([release]),
|
||||
LAUNCHER_ASSET,
|
||||
is_launcher_tag,
|
||||
);
|
||||
if one.iter().any(|r| r.asset.is_some()) {
|
||||
return one;
|
||||
}
|
||||
}
|
||||
}
|
||||
found
|
||||
}
|
||||
|
||||
/// The `launcher-vX.Y.Z` tags in GitHub's matching-refs answer, newest first.
|
||||
fn newest_launcher_tags(refs: &serde_json::Value) -> Vec<String> {
|
||||
let mut tags: Vec<String> = refs
|
||||
.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|r| r["ref"].as_str()?.strip_prefix("refs/tags/"))
|
||||
.filter(|t| is_launcher_tag(t))
|
||||
.map(String::from)
|
||||
.collect();
|
||||
tags.sort_by(|a, b| compare_versions(b, a));
|
||||
tags
|
||||
}
|
||||
|
||||
/// The newest Horizon release that has a build for this platform.
|
||||
@@ -1125,7 +1177,7 @@ pub fn check_updates() -> Result<Updates, String> {
|
||||
let list = release_list()?;
|
||||
Ok(Updates {
|
||||
horizon: horizon_update(&parse_releases(&list, ASSET, is_game_tag), &installed()),
|
||||
launcher: launcher_update(&parse_releases(&list, LAUNCHER_ASSET, is_launcher_tag)),
|
||||
launcher: launcher_update(&launcher_releases_in(&list)),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1563,6 +1615,47 @@ mod tests {
|
||||
assert_eq!(offered(&["v2026.10.15.1", "v2026.10.14"]), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_version_is_the_one_the_release_workflow_injects() {
|
||||
assert_eq!(version_or(Some("0.4.2")), "0.4.2");
|
||||
assert_eq!(version_or(Some("")), env!("CARGO_PKG_VERSION"));
|
||||
assert_eq!(version_or(None), env!("CARGO_PKG_VERSION"));
|
||||
assert_eq!(
|
||||
VERSION,
|
||||
option_env!("HORIZON_LAUNCHER_VERSION")
|
||||
.filter(|v| !v.is_empty())
|
||||
.unwrap_or(env!("CARGO_PKG_VERSION"))
|
||||
);
|
||||
// Self-update compares releases with that version: this launcher's own release is no update.
|
||||
let r = |tag: String| Release {
|
||||
tag,
|
||||
name: String::new(),
|
||||
body: String::new(),
|
||||
date: String::new(),
|
||||
asset: Some(("u".into(), 1)),
|
||||
};
|
||||
assert!(launcher_update(&[r(format!("{LAUNCHER_TAG_PREFIX}{VERSION}"))]).is_none());
|
||||
assert_eq!(
|
||||
parse_version_output(&format!("horizon-launcher {VERSION}\n")),
|
||||
Some(VERSION)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn launcher_tags_from_matching_refs_newest_first() {
|
||||
let refs = serde_json::json!([
|
||||
{"ref": "refs/tags/launcher-v0.1.9"},
|
||||
{"ref": "refs/tags/launcher-v0.1.10"},
|
||||
{"ref": "refs/tags/launcher-vnext"},
|
||||
{"ref": "refs/tags/v2026.10.15"},
|
||||
{"ref": "refs/tags/launcher-v0.2.0"},
|
||||
]);
|
||||
assert_eq!(
|
||||
newest_launcher_tags(&refs),
|
||||
["launcher-v0.2.0", "launcher-v0.1.10", "launcher-v0.1.9"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn versions_compare_by_number() {
|
||||
assert_eq!(compare_versions("v2026.10.13", "v2026.10.12"), Greater);
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ use std::process::Command;
|
||||
#[derive(Parser)]
|
||||
#[command(
|
||||
name = "horizon-launcher",
|
||||
version,
|
||||
version = backend::VERSION,
|
||||
about = "Installs, prepares and starts Horizon. Without a subcommand, opens the window."
|
||||
)]
|
||||
struct Cli {
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ try {
|
||||
|
||||
let releases = [];
|
||||
try {
|
||||
const res = await fetch(`https://api.github.com/repos/${REPO}/releases?per_page=30`, {
|
||||
const res = await fetch(`https://api.github.com/repos/${REPO}/releases?per_page=100`, {
|
||||
// An optional token (a Railway variable, or `gh auth token` locally) lifts the rate limit.
|
||||
headers: { Accept: "application/vnd.github+json", ...(process.env.GITHUB_TOKEN ? { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` } : {}) },
|
||||
signal: AbortSignal.timeout(15000),
|
||||
|
||||
+28
-15
@@ -31,21 +31,34 @@ async function get(url, as = "json") {
|
||||
return as === "json" ? res.json() : res.text();
|
||||
}
|
||||
|
||||
const releases = cached("horizon:releases", () =>
|
||||
get(`https://api.github.com/repos/${REPO}/releases?per_page=30`).then((list) =>
|
||||
list
|
||||
.filter((r) => !r.draft)
|
||||
.map((r) => ({
|
||||
tag_name: r.tag_name,
|
||||
name: r.name,
|
||||
published_at: r.published_at,
|
||||
html_url: r.html_url,
|
||||
prerelease: r.prerelease,
|
||||
body: r.body || "",
|
||||
assets: r.assets.map((a) => ({ name: a.name, browser_download_url: a.browser_download_url, size: a.size })),
|
||||
})),
|
||||
),
|
||||
).catch(() => baked.releases);
|
||||
const slim = (r) => ({
|
||||
tag_name: r.tag_name,
|
||||
name: r.name,
|
||||
published_at: r.published_at,
|
||||
html_url: r.html_url,
|
||||
prerelease: r.prerelease,
|
||||
body: r.body || "",
|
||||
assets: r.assets.map((a) => ({ name: a.name, browser_download_url: a.browser_download_url, size: a.size })),
|
||||
});
|
||||
const isLauncher = (r) => r.tag_name.startsWith("launcher-v") && !r.prerelease;
|
||||
const versionKey = (tag) => tag.replace("launcher-v", "").split(".").map(Number);
|
||||
const newer = (a, b) => versionKey(b).reduce((d, n, i) => d || n - (versionKey(a)[i] || 0), 0);
|
||||
|
||||
// The newest 30 releases. Game releases come out several times a day, so the newest launcher release can be
|
||||
// older than all of them: then it is looked up by its tag (the newest launcher-v tag with a published release).
|
||||
async function loadReleases() {
|
||||
const list = (await get(`https://api.github.com/repos/${REPO}/releases?per_page=30`)).filter((r) => !r.draft).map(slim);
|
||||
if (list.some(isLauncher)) return list;
|
||||
const refs = await get(`https://api.github.com/repos/${REPO}/git/matching-refs/tags/launcher-v`).catch(() => []);
|
||||
const tags = refs.map((r) => r.ref.replace("refs/tags/", "")).filter((t) => /^launcher-v\d+\.\d+\.\d+$/.test(t)).sort(newer);
|
||||
for (const tag of tags.slice(0, 3)) {
|
||||
const release = await get(`https://api.github.com/repos/${REPO}/releases/tags/${tag}`).catch(() => null);
|
||||
if (release && !release.draft) return [...list, slim(release)];
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
const releases = cached("horizon:releases", loadReleases).catch(() => baked.releases);
|
||||
|
||||
async function setUpContributors() {
|
||||
let list = baked.contributors || [];
|
||||
|
||||
Reference in New Issue
Block a user