File: run.php

package info (click to toggle)
phpunit 12.3.5-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 50,160 kB
  • sloc: php: 101,772; xml: 2,084; makefile: 124; sh: 99
file content (54 lines) | stat: -rwxr-xr-x 1,320 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env php
<?php declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';

if (!isset($argv[1]) || !is_file($argv[1])) {
    exit(1);
}

use Seld\PharUtils\Timestamps;

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 {
    $tag = @shell_exec('git describe --abbrev=0 2>&1');

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

        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;
$timestamp->setTimestamp($epoch);

$util = new Timestamps($argv[1]);
$util->updateTimestamps($timestamp);
$util->save($argv[1], Phar::SHA512);