Refactor our artifact builder

pull/1086/head
Jesse Vincent 3 years ago
parent 3aabbc8f29
commit 6b9b6c388a
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -16,32 +16,99 @@ use Cwd qw/abs_path cwd/;
use JSON::PP;
use Getopt::Long;
my $avr_platform_template = {
'archiveFileName' => $filename,
'toolsDependencies' => [
{
"packager" => "arduino",
"name" => "avr-gcc",
"version" => "7.3.0-atmel3.6.1-arduino7"
},
{
"packager" => "arduino",
"name" => "avrdude",
"version" => "6.3.0-arduino17"
}
],
'url' => $build_base_url . '/' . $filename,
'name' => "Kaleidoscope keyboards",
'version' => $version,
'checksum' => 'SHA-256:' . $sha256,
'size' => $size,
'boards' => [
{ 'name' => 'Keyboardio Model 01' }, { 'name' => 'Keyboardio Atreus' }
],
'architecture' => 'avr',
'category' => 'Contributed',
'help' => {
'online' => 'https://community.keyboard.io'
}
};
my $gd32_platform_template = {
'archiveFileName' => $filename,
'url' => $build_base_url . '/' . $filename,
'name' => "Kaleidoscope keyboards (GD32)",
'version' => $version,
'checksum' => 'SHA-256:' . $sha256,
'size' => $size,
'architecture' => 'gd32',
'toolsDependencies' => [
{
'name' => 'xpack-arm-none-eabi-gcc',
'packager' => 'GD32Community',
'version' => '9.3.1-1.3'
},
{
'packager' => 'GD32Community',
'version' => '0.11.0-1',
'name' => 'xpack-openocd'
},
{
'name' => 'dfu-util',
'version' => '0.10.0-arduino1',
'packager' => 'GD32Community'
}
],
'version' => '0.0.1',
'name' => 'Kaleidoscope Keyboards (GD32)',
'boards' => [
{
'name' => 'Keyboardio Model 100'
}
],
'category' => 'Contributed',
'help' => {
'online' => 'https://community.keyboard.io'
}
};
my $sha256 = 0;
my $size = 0;
my $version = '';
my $tag = 'master';
my $kaleidoscope_tag = 'master';
my $temp_dir = tempdir( CLEANUP => 0 );
my $working_dir = tempdir( CLEANUP => 0 );
my $index_filename_slug = 'keyboardio';
my $only_latest_platform = 0;
my $bundle_repo = 'https://github.com/keyboardio/Kaleidoscope-Bundle-Keyboardio';
my $bundle_repo =
'https://github.com/keyboardio/Kaleidoscope-Bundle-Keyboardio';
my $boards_repo = 'https://github.com/keyboardio/boardsmanager';
my $push_package_repo = 0;
GetOptions ("bundle-tag=s" => \$tag,
GetOptions(
"bundle-tag=s" => \$tag,
"kaleidoscope-tag=s" => \$kaleidoscope_tag,
"bundle-repo=s" => \$bundle_repo,
"output-repo=s" => \$boards_repo,
"index-filename-slug=s" => \$index_filename_slug,
"version=s" => \$version,
"only-one-platform-revision" => \$only_latest_platform,
"push" => \$push_package_repo)
or die("Error in command line arguments\n");
"push" => \$push_package_repo
) or die("Error in command line arguments\n");
my $index_filename = 'package_' . $index_filename_slug . '_index.json';
@ -56,34 +123,29 @@ my $build_base_url = $boards_repo."/master/builds/";
$build_base_url =~ s|^ssh://git\@github.com|https://raw.githubusercontent.com|;
$build_base_url =~ s|^https?://github.com|https://raw.githubusercontent.com|;
my @bundle_dirs_to_remove = qw|toolchain etc doc avr/build-tools avr/bootloaders/*/lufa avr/libraries/Kaleidoscope/testing avr/libraries/Kaleidoscope/tests avr/libraries/Kaleidoscope/docs|;
chdir($temp_dir);
`git clone --depth=1 --quiet --recurse-submodules --branch $tag $bundle_repo $checkout_dir`;
`git clone $boards_repo boardsmanager`;
print "Working directory: $working_dir\n";
chdir($working_dir);
clone_repos();
print "cd $checkout_dir\n";
chdir($checkout_dir);
my @bundle_dirs_to_remove =
qw|toolchain etc doc avr/build-tools avr/bootloaders/*/lufa avr/libraries/Kaleidoscope/testing avr/libraries/Kaleidoscope/tests avr/libraries/Kaleidoscope/docs|;
foreach my $dir_to_remove (@bundle_dirs_to_remove) {
print "rm -rf $dir_to_remove\n";
`rm -rf $dir_to_remove`;
}
chdir("avr/libraries/Kaleidoscope");
`git checkout --quiet $kaleidoscope_tag`;
if ( -d 'plugins') {
chdir("plugins");
# move the plugins to where they should live
`mv * ../../`;
}
checkout_kaleidoscope($kaleidoscope_tag);
lift_plugins_to_arduino_libs();
set_plugin_versions();
chdir($temp_dir);
chdir($working_dir);
`mv $checkout_dir/avr $checkout_dir/$checkout_dir`
; # A hack to get consistent naming with the old setup
`find $checkout_dir -name .git |xargs rm -rf`;
@ -100,63 +162,74 @@ if ($only_latest_platform) {
}
`cp $filename boardsmanager/builds/`;
my $platform_template = {
'archiveFileName' => $filename,
'toolsDependencies' => [
{
"packager" => "arduino",
"name" => "avr-gcc",
"version" => "7.3.0-atmel3.6.1-arduino7"
},
{
"packager" => "arduino",
"name" => "avrdude",
"version" => "6.3.0-arduino17"
update_index_file();
chdir('boardsmanager');
commit_results();
if ($push_package_repo) {
`git push`;
}
],
'url' => $build_base_url . '/' . $filename,
'name' => "Kaleidoscope keyboards",
'version' => $version,
'checksum' => 'SHA-256:' . $sha256,
'size' => $size,
'boards' => [
{ 'name' => 'Keyboardio Model 01' }, { 'name' => 'Keyboardio Atreus' }
],
'architecture' => 'avr',
'category' => 'Contributed',
'help' => {
'online' => 'https://community.keyboard.io'
else {
print
"Now, you need to cd to $working_dir/boardsmanager check the content and push it\n";
}
};
exit 0;
sub set_plugin_versions {
chdir("$working_dir/$checkout_dir/avr/libraries");
`perl -pi -e's/version=0.0.0/version=$version/' */library.properties`;
}
sub clone_repos {
`git clone --depth=1 --quiet --recurse-submodules --branch $tag $bundle_repo $checkout_dir`;
`git clone $boards_repo boardsmanager`;
}
sub checkout_kaleidoscope {
my $tag = shift;
`git checkout --quiet $tag`;
}
sub lift_plugins_to_arduino_libs {
if ( -d 'plugins' ) {
chdir("plugins");
# move the plugins to be fullfledged arduino libraries
`mv * ../../`;
}
}
sub update_index_file {
my $json = JSON::PP->new->allow_nonref;
local $/;
open( my $fh, '<', 'boardsmanager/'.$index_filename) || die "Could not open boardsmanager/$index_filename $!";
open( my $fh, '<', 'boardsmanager/' . $index_filename )
|| die "Could not open boardsmanager/$index_filename $!";
my $json_text = <$fh>;
my $data = decode_json($json_text);
if ($only_latest_platform) {
@{ $data->{'packages'}->[0]->{'platforms'} } = ( $platform_template);
} else {
push @{ $data->{'packages'}->[0]->{'platforms'} }, $platform_template;
@{ $data->{'packages'}->[0]->{'platforms'} } =
( $avr_platform_template, $gd32_platform_template );
}
else {
push @{ $data->{'packages'}->[0]->{'platforms'} },
$avr_platform_template,
$gd32_platform_template;
}
my $json_out = $json->canonical->pretty->encode($data);
open( my $out_fh, '>', 'boardsmanager/' . $index_filename );
print $out_fh $json_out;
close($out_fh);
chdir('boardsmanager');
`git add $index_filename`;
`git add builds`;
`git commit -a -m 'Built by $executed_as'`;
if ($push_package_repo) {
`git push`;
} else {
print
"Now, you need to cd to $temp_dir/boardsmanager check the content and push it\n";
}
sub commit_results {
sub set_plugin_versions {
chdir("$temp_dir/$checkout_dir/avr/libraries");
`perl -pi -e's/version=0.0.0/version=$version/' */library.properties`
`git add $index_filename`;
`git add builds`;
`git commit -a -m 'Built by $executed_as'`;
}

Loading…
Cancel
Save