forked from KSP-RO/ProceduralParts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version-gen
executable file
·93 lines (75 loc) · 2.33 KB
/
version-gen
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
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
use autodie;
use FindBin qw($Bin);
use JSON::PP;
# Write various version things for ProceduralParts.
# Paul Fenwick, January 2015.
# This code is CC-0 licensed. You can use it for anything, without attribution.
# This requires JSON::PP to run, which comes with Perl since v5.14, or can be
# installed with `cpanm JSON::PP`.
my $VERSION_FILE = "ProceduralParts.version";
my $ASSEMBLY_TEMPLATE = "Source/Properties/AssemblyInfo.in";
my $ASSEMBLY_FILE = "Source/Properties/AssemblyInfo.cs";
# Here's our base metadata. We'll add VERSION info to this before outputting.
my $metadata = {
NAME => "Procedural Parts",
URL => "https://raw.githubusercontent.com/Swamp-Ig/ProceduralParts/master/ProceduralParts.version",
DOWNLOAD => "https://github.com/Swamp-Ig/ProceduralParts/releases",
GITHUB =>
{
USERNAME => "Swamp-Ig",
REPOSITORY => "ProceduralParts"
},
KSP_VERSION_MIN => {
MAJOR => 1,
MINOR => 3,
PATCH => 0
},
KSP_VERSION_MAX => {
MAJOR => 1,
MINOR => 3,
PATCH => 1
},
};
chdir($Bin);
my $version = `git describe --tags --long --match "v*"`;
chomp($version);
if ($version !~ m{
# Parse a version in the form v1.2.3-4
^v
(?<major>\d+)\.
(?<minor>\d+)\.
(?<patch>\d+)
(-pre)?-
(?<build>\d+)
}x) {
die "Cannot parse $version as a version!";
}
my $assembly_version = "$+{major}.$+{minor}.$+{patch}.$+{build}";
say "Writing metadata for version $assembly_version";
# Using `int` below forces Perl to internally represent these as numbers,
# even though they were the result of a string operation. This means no
# unsightly quotes in the output JSON.
$metadata->{VERSION} = {
MAJOR => int $+{major},
MINOR => int $+{minor},
PATCH => int $+{patch},
BUILD => 0 # If used, AVC could try to get the user to
# install git builds, which we don't want.
};
# Write our AVC metadata
open(my $version_fh, '>', $VERSION_FILE);
say {$version_fh} JSON::PP->new->pretty->encode( $metadata );
close $version_fh;
# Write our AssemblyInfo
open(my $template_fh, '<', $ASSEMBLY_TEMPLATE);
open(my $assembly_fh, '>', $ASSEMBLY_FILE);
while (<$template_fh>) {
s{\@VERSION\@}{$assembly_version};
print {$assembly_fh} $_;
}
close($template_fh);
close($assembly_fh);