@@ -92,91 +92,6 @@ public static function log($message)
92
92
}
93
93
}
94
94
95
- /**
96
- * Class for auto-deploy code through git
97
- *
98
- * Example for using:
99
- *
100
- * ```php
101
- * // Prepare config
102
- * $config = [
103
- * 'log_file' => 'log.txt',
104
- * 'project_root' => '../..',
105
- * 'key' => 'zo9t9wcuwfi6wbqvu78z9biks3l39rue',
106
- * ];
107
- *
108
- * // Run App
109
- * GitHelper::init($config);
110
- * ```
111
- */
112
- class GitHelper
113
- {
114
- /**
115
- * @var array
116
- */
117
- static $ config ;
118
-
119
- /**
120
- * @param string $key unique key for protect deploying
121
- * @param string $project_root path to the project of git
122
- * @param string $log_file path to log-file
123
- */
124
- public static function run ($ key , $ project_root = '. ' , $ log_file = 'git-deploy-log.txt ' )
125
- {
126
- static ::init ([
127
- 'key ' => $ key ,
128
- 'project_root ' => $ project_root ,
129
- 'log_file ' => $ log_file ,
130
- ]);
131
-
132
- if (file_exists ($ log_file )) {
133
- echo '<h1>LOG </h1><pre> ' ;
134
- echo file_get_contents ($ log_file );
135
- echo '</pre> ' ;
136
- } else {
137
- echo 'log not found ' ;
138
- }
139
- }
140
-
141
- public static function init ($ config )
142
- {
143
- // Conf
144
- static ::$ config = $ config ;
145
- LogHelper::init (static ::$ config ['log_file ' ]);
146
-
147
- // Run
148
- if (static ::git_check_access ()) {
149
- LogHelper::log ('SESSION START ' );
150
- LogHelper::log (ShellHelper::exec ([
151
- 'cd ' . static ::$ config ['project_root ' ],
152
- 'git branch ' ,
153
- 'git pull ' ,
154
- ]));
155
-
156
- static ::end ();
157
- }
158
- }
159
-
160
- public static function end ()
161
- {
162
- LogHelper::log ('SESSION END ' );
163
- }
164
-
165
- public static function git_check_access ()
166
- {
167
- if (isset ($ _GET ['key ' ]) && !empty ($ _GET ['key ' ])) {
168
- if (static ::$ config ['key ' ] === $ _GET ['key ' ]) {
169
- LogHelper::log ('ACCESS ' );
170
- return true ;
171
- } else {
172
- LogHelper::log ('DENY << :// ' . $ _SERVER ['HTTP_HOST ' ] . $ _SERVER ['REQUEST_URI ' ]);
173
- static ::end ();
174
- }
175
- }
176
- return false ;
177
- }
178
- }
179
-
180
95
/**
181
96
* Main class for deploying
182
97
* Example for use it:
0 commit comments