Skip to content

Commit

Permalink
Add version tag injection in the build pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Akkadius committed Jan 23, 2023
1 parent 35b6240 commit 2fdee25
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions utils/scripts/build/linux-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ sudo chown eqemu:eqemu /home/eqemu/.ccache/ * -R

git submodule init && git submodule update

perl utils/scripts/build/tag-version.pl

mkdir -p build && cd build && cmake -DEQEMU_BUILD_TESTS=ON -DEQEMU_BUILD_LOGIN=ON -DEQEMU_BUILD_LUA=ON -DCMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING="-Os" -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -G 'Unix Makefiles' .. && make -j$((`nproc`-4))

curl https://raw.githubusercontent.com/Akkadius/eqemu-install-v2/master/eqemu_config.json --output eqemu_config.json
Expand Down
61 changes: 61 additions & 0 deletions utils/scripts/build/tag-version.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';

open my $fh, '<', './package.json' or die "Can't open file $!";
my $package_json = do {
local $/;
<$fh>
};

my $version = "";
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}

# manually parse because we can't guarantee json module is available
# it's jank but it's quick and dirty
# this is only used in the build pipeline
foreach my $line (split("\n", $package_json)) {
if ($line =~ /version/i) {
$version = $line;
$version =~ s/version//g;
$version =~ s/://g;
$version =~ s/"//g;
$version =~ s/,//g;
$version = trim($version);
}
}

print "Version is [" . $version . "]\n";

# server version file
my $version_file_name = "./common/version.h";
open my $vfh, '<', $version_file_name or die "Can't open file $!";
my $version_file = do {
local $/;
<$vfh>
};

# write new version
my $new_version_file = "";
foreach my $line (split("\n", $version_file)) {
if ($line =~ /CURRENT_VERSION/i) {
my @s = split("\"", $line);
if ($#s == 2) {
$line =~ s/$s[1]/$version/g;
}
}

$new_version_file .= $line . "\n";
}

open(my $wfh, '>', $version_file_name) or die "Could not open file '$version_file_name' $!";
print $wfh $new_version_file;
close $wfh;

print $new_version_file;
2 changes: 2 additions & 0 deletions utils/scripts/build/windows-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ try
New-Item -Path "$cwd\win-build-x64" -ItemType Directory
}

perl .\utils\scripts\build\tag-version.pl

Write-Information -MessageData "Creating build x64" -InformationAction Continue
Set-Location -Path "$cwd\win-build-x64"
cmake -Wno-dev -G "Visual Studio 17 2022" -A x64 -DEQEMU_BUILD_TESTS=ON -DEQEMU_BUILD_LOGIN=ON -DEQEMU_BUILD_ZLIB=ON "$cwd"
Expand Down

0 comments on commit 2fdee25

Please sign in to comment.