Created
November 24, 2021 03:14
-
-
Save marioroy/aee9303f2c31556fb1cbbc7507d00b2e to your computer and use it in GitHub Desktop.
Author script for updating mce-perl and mce-shared versions.
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/env perl | |
# cd $HOME/git/mce-perl or mce-shared | |
# ../update_version.pl README.md `find lib -name "*.p*"` | |
use strict; | |
use warnings; | |
use File::Inplace; | |
my $old = '1.874'; | |
my $new = '1.875'; | |
unless ( -f 'Changes' && -f 'Makefile.PL' && -f 'META.json' && -f 'META.yml' ) { | |
die "ERROR: not inside repo dir mce-perl or mce-shared\n"; | |
} | |
# lib | |
{ | |
for my $file ( @ARGV ) { | |
next if ( $file !~ /\.md$/ && $file !~ /\.pm$/ && $file !~ /\.pod$/ ); | |
my $editor = File::Inplace->new( file => $file, chomp => 0 ); | |
my $flag = 0; | |
while ( my ($line) = $editor->next_line ) { | |
if ( $line =~ /^our \$VERSION = '${old}'/ || | |
$line =~ /^This document describes .* version ${old}/ ) { | |
$line =~ s/${old}/${new}/; | |
$editor->replace_line( $line ); | |
$flag = 1; | |
} | |
} | |
$editor->commit(), print "Updated $file\n" if $flag; | |
} | |
} | |
# Makefile.PL | |
{ | |
my $editor = File::Inplace->new( file => 'Makefile.PL', chomp => 0 ); | |
my $flag = 0; | |
while ( my ($line) = $editor->next_line ) { | |
if ( $line =~ /\sVERSION\s+=>\s+'${old}'/ || | |
$line =~ /\s'version'\s+=>\s+'${old}'/ ) { | |
$line =~ s/${old}/${new}/; | |
$editor->replace_line( $line ); | |
$flag = 1; | |
} | |
} | |
$editor->commit(), print "Updated Makefile.PL\n" if $flag; | |
} | |
# META.json | |
{ | |
my $editor = File::Inplace->new( file => 'META.json', chomp => 0 ); | |
my $flag = 0; | |
while ( my ($line) = $editor->next_line ) { | |
if ( $line =~ /\s"version"\s:\s"${old}"/ ) { | |
$line =~ s/${old}/${new}/; | |
$editor->replace_line( $line ); | |
$flag = 1; | |
} | |
} | |
$editor->commit(), print "Updated META.json\n" if $flag; | |
} | |
# META.yml | |
{ | |
my $editor = File::Inplace->new( file => 'META.yml', chomp => 0 ); | |
my $flag = 0; | |
while ( my ($line) = $editor->next_line ) { | |
if ( $line =~ /\s?version:\s'${old}'/ ) { | |
$line =~ s/${old}/${new}/; | |
$editor->replace_line( $line ); | |
$flag = 1; | |
} | |
} | |
$editor->commit(), print "Updated META.yml\n" if $flag; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment