mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-11 19:59:50 +08:00
Ignore tunnel release tags for app build version
This commit is contained in:
@@ -11,19 +11,18 @@ fn main() {
|
|||||||
let package_version = env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "unknown".to_string());
|
let package_version = env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "unknown".to_string());
|
||||||
let version = env::var("AETHER_BUILD_VERSION")
|
let version = env::var("AETHER_BUILD_VERSION")
|
||||||
.ok()
|
.ok()
|
||||||
.filter(|value| !value.trim().is_empty())
|
.and_then(|value| normalize_gateway_version_source(&value))
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
env::var("AETHER_VERSION")
|
env::var("AETHER_VERSION")
|
||||||
.ok()
|
.ok()
|
||||||
.filter(|value| !value.trim().is_empty())
|
.and_then(|value| normalize_gateway_version_source(&value))
|
||||||
})
|
})
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
env::var("GITHUB_REF_NAME")
|
env::var("GITHUB_REF_NAME")
|
||||||
.ok()
|
.ok()
|
||||||
.filter(|value| value.trim().starts_with('v'))
|
.and_then(|value| normalize_gateway_version_source(&value))
|
||||||
})
|
})
|
||||||
.or_else(git_describe_version)
|
.or_else(git_describe_version)
|
||||||
.map(|value| normalize_version(&value))
|
|
||||||
.filter(|value| !value.is_empty())
|
.filter(|value| !value.is_empty())
|
||||||
.unwrap_or(package_version);
|
.unwrap_or(package_version);
|
||||||
|
|
||||||
@@ -38,7 +37,9 @@ fn main() {
|
|||||||
|
|
||||||
fn git_describe_version() -> Option<String> {
|
fn git_describe_version() -> Option<String> {
|
||||||
let output = Command::new("git")
|
let output = Command::new("git")
|
||||||
.args(["describe", "--tags", "--always", "--dirty"])
|
.args([
|
||||||
|
"describe", "--tags", "--match", "v[0-9]*", "--always", "--dirty",
|
||||||
|
])
|
||||||
.output()
|
.output()
|
||||||
.ok()?;
|
.ok()?;
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
@@ -46,17 +47,13 @@ fn git_describe_version() -> Option<String> {
|
|||||||
}
|
}
|
||||||
let version = String::from_utf8(output.stdout).ok()?;
|
let version = String::from_utf8(output.stdout).ok()?;
|
||||||
let version = version.trim();
|
let version = version.trim();
|
||||||
if version.is_empty() {
|
normalize_gateway_version_source(version)
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(version.to_string())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn normalize_version(value: &str) -> String {
|
fn normalize_gateway_version_source(value: &str) -> Option<String> {
|
||||||
value
|
let trimmed = value.trim();
|
||||||
.trim()
|
if trimmed.is_empty() || trimmed.starts_with("tunnel-v") {
|
||||||
.strip_prefix('v')
|
return None;
|
||||||
.unwrap_or(value.trim())
|
}
|
||||||
.to_string()
|
Some(trimmed.strip_prefix('v').unwrap_or(trimmed).to_string())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ fn admin_system_build_version_contract_uses_explicit_local_build_arg() {
|
|||||||
let deploy = read_workspace_file("deploy.sh");
|
let deploy = read_workspace_file("deploy.sh");
|
||||||
for pattern in [
|
for pattern in [
|
||||||
"detect_build_version()",
|
"detect_build_version()",
|
||||||
"git describe --tags --always --dirty",
|
"git describe --tags --match 'v[0-9]*' --always --dirty",
|
||||||
"AETHER_BUILD_VERSION=\"${AETHER_BUILD_VERSION:-$(detect_build_version)}\"",
|
"AETHER_BUILD_VERSION=\"${AETHER_BUILD_VERSION:-$(detect_build_version)}\"",
|
||||||
"--build-arg \"AETHER_BUILD_VERSION=$AETHER_BUILD_VERSION\"",
|
"--build-arg \"AETHER_BUILD_VERSION=$AETHER_BUILD_VERSION\"",
|
||||||
">>> AETHER_BUILD_VERSION",
|
">>> AETHER_BUILD_VERSION",
|
||||||
@@ -43,6 +43,8 @@ fn admin_system_build_version_contract_uses_explicit_local_build_arg() {
|
|||||||
for pattern in [
|
for pattern in [
|
||||||
"process.env.AETHER_BUILD_VERSION",
|
"process.env.AETHER_BUILD_VERSION",
|
||||||
"process.env.AETHER_VERSION",
|
"process.env.AETHER_VERSION",
|
||||||
|
"git describe --tags --match \"v[0-9]*\" --always --dirty",
|
||||||
|
"trimmed.startsWith('tunnel-v')",
|
||||||
] {
|
] {
|
||||||
assert!(
|
assert!(
|
||||||
vite_config.contains(pattern),
|
vite_config.contains(pattern),
|
||||||
@@ -60,6 +62,18 @@ fn admin_system_build_version_contract_uses_explicit_local_build_arg() {
|
|||||||
"api/core.rs should expose build version pattern {pattern}"
|
"api/core.rs should expose build version pattern {pattern}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let build_rs = read_workspace_file("apps/aether-gateway/build.rs");
|
||||||
|
for pattern in [
|
||||||
|
"\"--match\"",
|
||||||
|
"\"v[0-9]*\"",
|
||||||
|
"trimmed.starts_with(\"tunnel-v\")",
|
||||||
|
] {
|
||||||
|
assert!(
|
||||||
|
build_rs.contains(pattern),
|
||||||
|
"apps/aether-gateway/build.rs should ignore tunnel release tags for gateway version pattern {pattern}"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export LOCAL_APP_IMAGE
|
|||||||
detect_build_version() {
|
detect_build_version() {
|
||||||
if command -v git >/dev/null 2>&1; then
|
if command -v git >/dev/null 2>&1; then
|
||||||
local version
|
local version
|
||||||
if version=$(git describe --tags --always --dirty 2>/dev/null); then
|
if version=$(git describe --tags --match 'v[0-9]*' --always --dirty 2>/dev/null); then
|
||||||
if [ -n "$version" ]; then
|
if [ -n "$version" ]; then
|
||||||
printf '%s\n' "$version"
|
printf '%s\n' "$version"
|
||||||
return 0
|
return 0
|
||||||
@@ -58,7 +58,7 @@ Options:
|
|||||||
|
|
||||||
Environment:
|
Environment:
|
||||||
LOCAL_APP_IMAGE 本地构建镜像名,默认 aether-app:latest
|
LOCAL_APP_IMAGE 本地构建镜像名,默认 aether-app:latest
|
||||||
AETHER_BUILD_VERSION 应用显示版本,默认 git describe --tags --always --dirty
|
AETHER_BUILD_VERSION 应用显示版本,默认 git describe --tags --match 'v[0-9]*' --always --dirty
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,17 +5,24 @@ import { execSync } from 'child_process'
|
|||||||
|
|
||||||
function normalizeVersion(version: string): string {
|
function normalizeVersion(version: string): string {
|
||||||
const trimmed = version.trim()
|
const trimmed = version.trim()
|
||||||
|
if (!trimmed || trimmed.startsWith('tunnel-v')) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
return trimmed.startsWith('v') || trimmed.startsWith('V') ? trimmed.slice(1) : trimmed
|
return trimmed.startsWith('v') || trimmed.startsWith('V') ? trimmed.slice(1) : trimmed
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGitVersion(): string {
|
function getGitVersion(): string {
|
||||||
const envVersion = process.env.AETHER_BUILD_VERSION || process.env.AETHER_VERSION
|
const envVersion = process.env.AETHER_BUILD_VERSION || process.env.AETHER_VERSION
|
||||||
if (envVersion?.trim()) {
|
if (envVersion?.trim()) {
|
||||||
return normalizeVersion(envVersion)
|
const version = normalizeVersion(envVersion)
|
||||||
|
if (version) {
|
||||||
|
return version
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return normalizeVersion(execSync('git describe --tags --always --dirty').toString())
|
const version = normalizeVersion(execSync('git describe --tags --match "v[0-9]*" --always --dirty').toString())
|
||||||
|
return version || '0.0.0.dev0'
|
||||||
} catch {
|
} catch {
|
||||||
return '0.0.0.dev0'
|
return '0.0.0.dev0'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user