Last active
July 31, 2016 13:13
-
-
Save ukautz/db2711003ae448dcabdab2d523fbb81a to your computer and use it in GitHub Desktop.
Perl script to insert all versions from glide.lock into glide.yaml for app unversioned packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
# Freezes all versions found in glide.lock by setting commiot as version in glide.yaml | |
# for each package which does not explicitly has a version | |
# | |
use strict; | |
use warnings; | |
use YAML::Syck qw/ LoadFile DumpFile Dump /; | |
use Data::Dumper; | |
my $yaml = LoadFile("glide.yaml"); | |
my $lock = LoadFile("glide.lock"); | |
my $updated = 0; | |
print "Checking all packages\n"; | |
foreach my $import(@{$yaml->{"import"}}) { | |
#print Dumper($import); | |
if (!defined $import->{version} || !$import->{version}) { | |
$updated++; | |
$import->{version} = get_version($import->{"package"}); | |
print " * New version for ". $import->{"package"}. ": ". $import->{version}. "\n"; | |
} | |
} | |
print "\n-----------------\n\n"; | |
if ($updated) { | |
open my $fh, ">", "glide.yaml.new" or die "Could not open glide.yaml.new for write: $!\n"; | |
print DumpFile($fh, $yaml); | |
close $fh; | |
print "New YAML in glide.yaml.new generated\n"; | |
} else { | |
print "All have versions, doing nothing\n"; | |
} | |
sub get_version { | |
my ($name) = @_; | |
foreach my $package(@{$lock->{imports}}) { | |
if ($package->{name} eq $name) { | |
return $package->{version}; | |
} | |
} | |
die("Did not find version for \"$name\"!!\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment