Skip to content

Commit e0cfac8

Browse files
committed
move git-post-tasks action into Doit script
Script was generated with the help of ChatGPT.
1 parent 5a2d056 commit e0cfac8

File tree

2 files changed

+66
-29
lines changed

2 files changed

+66
-29
lines changed

Makefile.PL

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -143,39 +143,13 @@ fix-$type-cpantestersmatrix-permissions:
143143
EOF
144144
}
145145

146-
if (defined $ENV{USER} && $ENV{USER} eq 'eserte') {
147-
if ($^O =~ /bsd/i) { # assume BSD make
148-
$postamble .= <<'EOF';
149-
GIT_TAG_DATE= $(shell date +%Y%m%d)
150-
EOF
151-
} else { # assume GNU make
152-
$postamble .= <<'EOF';
153-
GIT_TAG_DATE!= date +%Y%m%d
154-
EOF
155-
}
156-
$postamble .= <<'EOF';
157-
GIT_TAG= deployment/bbbikede/${GIT_TAG_DATE}
158-
146+
$postamble .= <<'EOF';
159147
git-post-tasks:
160-
git diff-index --quiet --cached HEAD
161-
git diff-files --quiet || (\
162-
echo "There are uncommitted changes"; \
163-
git diff-files; \
164-
false; \
165-
)
166-
test -z "$$(git ls-files --exclude-standard --others)" || (\
167-
echo "There are untracked files"; \
168-
git ls-files --exclude-standard --others; \
169-
false; \
170-
)
171-
$(NOECHO) echo -n "This will tag version $(GIT_TAG) and push the default branch and the current tag. OK? "
148+
$(NOECHO) echo -n "This will tag and push. OK? "
172149
$(NOECHO) read yn
173-
git tag -a -m "* $(GIT_TAG)" $(GIT_TAG) || (echo "If setting this tag fails, then try using a suffix e.g. _2"; false)
174-
git push
175-
git push origin $(GIT_TAG)
150+
bin/git-post-tasks-doit.pl
176151
177152
EOF
178-
}
179153

180154
$postamble;
181155
}

bin/git-post-tasks-doit.pl

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env perl
2+
# -*- perl -*-
3+
4+
use if !$ENV{DOIT_IN_REMOTE}, lib => "$ENV{HOME}/src/Doit/lib";
5+
use Doit;
6+
use Doit::Log;
7+
use Getopt::Long;
8+
use POSIX qw(strftime);
9+
10+
sub generate_git_tag {
11+
my $base = "deployment/bbbikede/" . strftime("%Y%m%d", localtime);
12+
my $tag = $base;
13+
my $doit = shift;
14+
15+
for my $i (0..9) {
16+
my $try = $i == 0 ? $tag : "${tag}_$i";
17+
my $exists = eval {
18+
$doit->info_system(qw(git rev-parse --verify), $try);
19+
1;
20+
};
21+
if (!$exists) {
22+
return $try;
23+
}
24+
}
25+
26+
error("Too many tags exist with base $tag (_0 to _9)");
27+
}
28+
29+
return 1 if caller;
30+
31+
my $doit = Doit->init;
32+
GetOptions("ignore-dirty-workdir" => \my $ignore_dirty_workdir)
33+
or error "usage: $0 [--ignore-dirty-workdir] [--dry-run]";
34+
35+
# Ensure working tree is clean
36+
$doit->system(qw(git diff-index --quiet --cached HEAD));
37+
38+
my $dirty_git_error = $ignore_dirty_workdir ? sub { warning @_ } : sub { error @_ };
39+
40+
my $changed = eval {
41+
$doit->system(qw(git diff-files --quiet));
42+
0;
43+
};
44+
if ($changed) {
45+
my @diff = split /\n/, $doit->info_qx(qw(git diff-files));
46+
$dirty_git_error->("There are uncommitted changes:\n" . join("\n", @diff) . "\nPlease commit or stash your changes first.");
47+
}
48+
49+
my @untracked = split /\n/, $doit->info_qx(qw(git ls-files --exclude-standard --others));
50+
if (@untracked) {
51+
$dirty_git_error->("There are untracked files:\n" . join("\n", @untracked) . "\nPlease clean up untracked files first.");
52+
}
53+
54+
# Generate tag
55+
my $tag = generate_git_tag($doit);
56+
info("Using tag: $tag");
57+
58+
# Create and push tag
59+
$doit->system(qw(git tag -a -m), "* $tag", $tag);
60+
$doit->system(qw(git push));
61+
$doit->system(qw(git push origin), $tag);
62+
63+
__END__

0 commit comments

Comments
 (0)