This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
/
BuckGenerateDocsPhase.php-example
131 lines (118 loc) · 3.27 KB
/
BuckGenerateDocsPhase.php-example
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?hh // strict
/**
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
namespace Facebook\ShipIt;
/**
* Generate buck documentation from source repo into the destination repo.
*/
final class BuckGenerateDocsPhase extends ShipItPhase {
const GH_PAGES_BRANCH = 'gh-pages';
<<__Override>>
public function isProjectSpecific(): bool {
return true;
}
<<__Override>>
public function getReadableName(): string {
return 'Generate buck documentation';
}
<<__Override>>
protected function runImpl(
ShipItBaseConfig $config,
): void {
$sourcePath = $config->getSourcePath();
$docsPath = $config->getDestinationPath();
$branch = $config->getDestinationBranch();
$verbose =
$config->isVerboseEnabled()
? ShipItUtil::VERBOSE_SHELL_OUTPUT
: ShipItUtil::DONT_VERBOSE;
// Get out of our current branch so it can be deleted.
/* HH_FIXME[4128] Use ShipItShellCommand */
ShipItUtil::shellExec(
$docsPath,
/* stdin = */ null,
$verbose,
'git', 'checkout', '--detach',
);
// Delete the current branch.
/* HH_FIXME[4128] Use ShipItShellCommand */
ShipItUtil::shellExec(
$docsPath,
/* stdin = */ null,
$verbose,
'git', 'branch', '--delete', '--force', $branch,
);
// Create a historyless branch in its place.
/* HH_FIXME[4128] Use ShipItShellCommand */
ShipItUtil::shellExec(
$docsPath,
/* stdin = */ null,
$verbose,
'git', 'checkout', '--orphan', $branch,
);
// Erase all existing files.
/* HH_FIXME[4128] Use ShipItShellCommand */
ShipItUtil::shellExec(
$docsPath,
/* stdin = */ null,
$verbose,
'git', 'rm', '--force', '-r', '.',
);
$pipes = array();
$proc = proc_open(
'docs/soyweb-prod.sh',
array(
0 => array('pipe', 'r'),
1 => array('file', '/dev/null', 'w'),
2 => array('file', '/dev/null', 'w'),
),
&$pipes,
$sourcePath
);
fclose($pipes[0]);
try {
/* HH_FIXME[4128] Use ShipItShellCommand */
ShipItUtil::shellExec(
$sourcePath,
/* stdin = */ null,
$verbose,
'docs/soy2html.sh', $docsPath,
);
} finally {
$status = proc_get_status($proc);
if ($status !== null) {
// kill whole tree of docs/soyweb-prod.sh
exec('pstree -pl '.$status['pid'].
' | grep -o "([0-9]\+)" | sed "s/(\|)//g" | xargs kill');
}
}
/* HH_FIXME[4128] Use ShipItShellCommand */
ShipItUtil::shellExec(
$docsPath,
/* stdin = */ null,
$verbose,
'git', 'add', '.',
);
/* HH_FIXME[4128] Use ShipItShellCommand */
$sourceCommitHash = rtrim(ShipItUtil::shellExec(
$sourcePath,
/* stdin = */ null,
$verbose,
'git', 'log', '-1', '--format=%H',
));
/* HH_FIXME[4128] Use ShipItShellCommand */
ShipItUtil::shellExec(
$docsPath,
/* stdin = */ null,
$verbose,
'git', 'commit',
'-m', sprintf('Updated HTML documentation to %s.', $sourceCommitHash),
);
}
}