-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
makeVersionTag.pl
62 lines (53 loc) · 1.48 KB
/
makeVersionTag.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/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);
}elsif($?){
$rv = $? >> 8;
die "child exited with value $rv\n";
}
}
# ワーキングツリーに変更がないことを確認
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";
$branch eq 'main'
or die "current branch is not main.\n";
}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;
# 現在のバージョン番号を取得
my $buildFile = 'app/build.gradle.kts';
`cat $buildFile` =~ /versionName\s*=\s*["']([\d\.]+)["']/
or die "missing versionName in $buildFile\n";
my($tag)="v$1";
print "# version=$tag\n";
# すでにタグがあるなら何もしない
if( `git tag -l $tag` =~ /$tag/ ){
print "# tag $tag is already exists.\n";
}else{
cmd "git tag -a $tag -m $tag";
}
cmd "git push";
cmd "git push --tags";