From 50b912e229b4d56f8bf4ea2c0960e09f1f208d0f Mon Sep 17 00:00:00 2001 From: catbref Date: Wed, 3 Jun 2020 11:49:49 +0100 Subject: [PATCH] Improved tools/publish-auto-update.pl --- tools/publish-auto-update.pl | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/tools/publish-auto-update.pl b/tools/publish-auto-update.pl index e9092e83..3493f964 100755 --- a/tools/publish-auto-update.pl +++ b/tools/publish-auto-update.pl @@ -6,16 +6,17 @@ use POSIX; use Getopt::Std; sub usage() { - die("usage: $0 [-p api-port] dev-private-key\n"); + die("usage: $0 [-p api-port] dev-private-key [short-commit-hash]\n"); } my %opt; getopts('p:', \%opt); -usage() unless @ARGV == 1; +usage() if @ARGV < 1 || @ARGV > 2; my $port = $opt{p} || 12391; my $privkey = shift @ARGV; +my $commit_hash = shift @ARGV; my $git_dir = `git rev-parse --show-toplevel`; die("Cannot determine git top level dir\n") unless $git_dir; @@ -33,18 +34,24 @@ while () { } close(POM); -# determine git branch -my $branch_name = ` git symbolic-ref -q HEAD ` -$branch_name =~ s|^refs/heads/||; # ${branch_name##refs/heads/} +# Do we need to determine commit hash? +unless ($commit_hash) { + # determine git branch + my $branch_name = ` git symbolic-ref -q HEAD `; + chomp $branch_name; + $branch_name =~ s|^refs/heads/||; # ${branch_name##refs/heads/} -# short-form commit hash on base branch (non-auto-update) -my $commit_hash = `git show --no-patch --format=%h`; -die("Can't find commit hash\n") if ! defined $commit_hash; -chomp $commit_hash; -printf "Commit hash on '%s' branch: %s\n", $branch_name, $commit_hash; + # short-form commit hash on base branch (non-auto-update) + $commit_hash ||= `git show --no-patch --format=%h`; + die("Can't find commit hash\n") if ! defined $commit_hash; + chomp $commit_hash; + printf "Commit hash on '%s' branch: %s\n", $branch_name, $commit_hash; +} else { + printf "Using given commit hash: %s\n", $commit_hash; +} # build timestamp / commit timestamp on base branch -my $timestamp = `git show --no-patch --format=%ct`; +my $timestamp = `git show --no-patch --format=%ct ${commit_hash}`; die("Can't determine commit timestamp\n") if ! defined $timestamp; $timestamp *= 1000; # Convert to milliseconds