-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.java
More file actions
111 lines (97 loc) · 3.92 KB
/
Copy pathrelease.java
File metadata and controls
111 lines (97 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* SPDX-FileCopyrightText: 2026 Leitwolf <support@xsharp-lang.xyz>
* SPDX-License-Identifier: MPL-2.0
*/
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
class Release
{
static final int USAGE_ERROR = 2;
record Check(String name, boolean ok, String detail)
{
}
static void help()
{
System.out.println("""
usage:
java --source=21 release.java check <version>
java --source=21 release.java help
commands:
check Validate release metadata for the requested version.
help Show this help.
examples:
java --source=21 release.java check 0.3.0
""");
}
static String read(Path path) throws IOException
{
return Files.readString(path, StandardCharsets.UTF_8);
}
static Check contains(Path path, String needle, String name) throws IOException
{
boolean ok = read(path).contains(needle);
return new Check(name, ok, ok ? path + " contains expected text" : path + " is missing: " + needle);
}
static Check containsOnce(Path path, String needle, String name) throws IOException
{
String text = read(path);
int first = text.indexOf(needle);
int last = text.lastIndexOf(needle);
boolean ok = first >= 0 && first == last;
return new Check(name, ok,
ok ? path + " contains one expected entry" : path + " should contain exactly one: " + needle);
}
static Check xsVersion(String version) throws IOException, InterruptedException
{
Path binary = Path.of("build/clangcl-debug/vxs.exe");
if(!Files.isExecutable(binary))
{
return new Check("vxs --version", true, "build/clangcl-debug/vxs.exe is not built; skipped runtime version check");
}
Process process = new ProcessBuilder(binary.toString(), "--version")
.redirectError(ProcessBuilder.Redirect.INHERIT).start();
String output = new String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8).trim();
int code = process.waitFor();
boolean ok = code == 0 && output.equals("vxs " + version);
return new Check("vxs --version", ok, ok ? output : "expected 'vxs " + version + "', got '" + output + "'");
}
static int check(String version) throws IOException, InterruptedException
{
List<Check> checks = new ArrayList<>();
checks.add(contains(Path.of("CMakeLists.txt"), "project(xs_project VERSION " + version + " LANGUAGES C CXX)",
"CMake project version"));
checks.add(containsOnce(Path.of("CHANGELOG.md"), "## " + version + " - ", "CHANGELOG heading"));
checks.add(contains(Path.of("xs/haskell/visual-xsharp-compiler/visual-xsharp-compiler.cabal"),
"version: " + version, "Haskell compiler version"));
checks.add(contains(Path.of("xs_kts/build.gradle.kts"), "version = \"" + version + "\"",
"Kotlin project runtime version"));
checks.add(contains(Path.of("xslang/Cargo.toml"), "version = \"" + version + "\"",
"Rust compiler core version"));
checks.add(xsVersion(version));
boolean ok = true;
for(Check check : checks)
{
System.out.println((check.ok ? "ok: " : "error: ") + check.name + " - " + check.detail);
ok = ok && check.ok;
}
return ok ? 0 : 1;
}
public static void main(String[] args) throws Exception
{
if(args.length == 1 && args[0].equals("help"))
{
help();
return;
}
if(args.length == 2 && args[0].equals("check"))
{
System.exit(check(args[1]));
}
help();
System.exit(USAGE_ERROR);
}
}