Skip to content

Commit

Permalink
Handle situation (in CI/CD pipeline, for instance) when tag informati…
Browse files Browse the repository at this point in the history
…on is not available
  • Loading branch information
sebastianbergmann committed Apr 20, 2024
1 parent 85f0d38 commit 20cf543
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion build/scripts/phar-set-timestamps/run.php
Expand Up @@ -10,8 +10,40 @@

if (is_string(getenv('SOURCE_DATE_EPOCH'))) {
$epoch = (int) getenv('SOURCE_DATE_EPOCH');

printf(
'Setting timestamp of files in PHAR to %d (based on environment variable SOURCE_DATE_EPOCH)' . PHP_EOL,
$epoch
);
} else {
$epoch = (int) trim(shell_exec('git log -1 --format=%at ' . trim(shell_exec('git describe --abbrev=0'))));
$tag = shell_exec('git describe --abbrev=0');

if (is_string($tag) && strpos($tag, 'fatal') === false) {
$tmp = shell_exec('git log -1 --format=%at ' . trim($tag));

if (is_string($tag) && is_numeric(trim($tmp))) {
$epoch = (int) trim($tmp);

printf(
'Setting timestamp of files in PHAR to %d (based on when tag %s was created)' . PHP_EOL,
$epoch,
trim($tag)
);
}

unset($tmp);
}

unset($tag);
}

if (!isset($epoch)) {
$epoch = time();

printf(
'Setting timestamp of files in PHAR to %d (based on current time)' . PHP_EOL,
$epoch
);
}

$timestamp = new DateTime;
Expand Down

0 comments on commit 20cf543

Please sign in to comment.