SubwayTooter-Android-App/makeVersionTag.pl

63 lines
1.5 KiB
Perl
Raw Normal View History

2019-08-31 17:16:54 +02:00
#!/usr/bin/perl --
use strict;
use warnings;
sub cmd($){
print "+ ",$_[0],"\n";
my $rv=system $_[0];
if ($? == -1) {
die "failed to execute: $!\n";
}elsif ($? & 127) {
die sprintf "child died with signal %d\n", ($? & 127);
2023-02-08 20:53:09 +01:00
}elsif($?){
$rv = $? >> 8;
die "child exited with value $rv\n";
2019-08-31 17:16:54 +02:00
}
}
# ワーキングツリーに変更がないことを確認
open(my $fh,"-|","git status --porcelain --branch")
or die "can't check git status. $!";
my @untrackedFiles;
while(<$fh>){
chomp;
if(/^\?\?\s*(\S+)/){
my $path =$1;
next if $path =~ /\.idea|_Emoji|makeVersionTag.pl/;
push @untrackedFiles,$path
}elsif( /^##\s*(\S+?)(?:\.\.|$)/ ){
my $branch=$1;
print "# branch=$branch\n";
2021-10-31 07:42:55 +01:00
$branch eq 'main'
or die "current branch is not main.\n";
2019-08-31 17:16:54 +02:00
}else{
warn "working tree is not clean.\n";
cmd "git status";
exit 1;
}
}
close($fh)
or die "can't check git status. $!";
@untrackedFiles and die "forgot git add?\n",map{ "- $_\n"} @untrackedFiles;
# 現在のバージョン番号を取得
2019-09-29 19:40:12 +02:00
my $buildFile = 'app/build.gradle';
2019-08-31 17:16:54 +02:00
`cat $buildFile` =~ /versionName\s+["']([\d\.]+)["']/
or die "missing versionName in $buildFile\n";
my($tag)="v$1";
print "# version=$tag\n";
# すでにタグがあるなら何もしない
2019-08-31 17:18:00 +02:00
if( `git tag -l $tag` =~ /$tag/ ){
print "# tag $tag is already exists.\n";
}else{
2019-08-31 17:16:54 +02:00
cmd "git tag -a $tag -m $tag";
}
cmd "git push";
cmd "git push --tags";