File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,4 +9,5 @@ Homestead.json
99Homestead.yaml
1010npm-debug.log
1111yarn-error.log
12- .env
12+ .env
13+ version.txt
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ if (!function_exists ('get_app_version ' )) {
4+ /**
5+ * 获取应用版本号(基于 Git commit ID)
6+ *
7+ * @return string 返回短版本的 commit ID(前7位)或 'unknown'
8+ */
9+ function get_app_version ()
10+ {
11+ // 尝试从缓存中获取版本号(避免频繁读取文件或执行 git 命令)
12+ $ cacheKey = 'app_version ' ;
13+ $ cachedVersion = \Cache::get ($ cacheKey );
14+
15+ if ($ cachedVersion !== null ) {
16+ return $ cachedVersion ;
17+ }
18+
19+ $ version = 'unknown ' ;
20+
21+ try {
22+ // 优先从 version.txt 文件读取(适用于生产环境)
23+ $ versionFile = base_path ('version.txt ' );
24+ if (file_exists ($ versionFile )) {
25+ $ version = trim (file_get_contents ($ versionFile ));
26+ }
27+
28+ // 如果文件不存在或为空,尝试从 Git 获取(适用于开发环境)
29+ if (empty ($ version ) || $ version === 'unknown ' ) {
30+ $ gitVersion = trim (shell_exec ('git rev-parse --short=7 HEAD 2>/dev/null ' ) ?? '' );
31+ if (!empty ($ gitVersion )) {
32+ $ version = $ gitVersion ;
33+ }
34+ }
35+
36+ // 缓存版本号10分钟
37+ \Cache::put ($ cacheKey , $ version , 10 );
38+
39+ return $ version ;
40+ } catch (\Exception $ e ) {
41+ return 'unknown ' ;
42+ }
43+ }
44+ }
Original file line number Diff line number Diff line change 2727 ],
2828 "psr-4" : {
2929 "App\\ " : " app/"
30- }
30+ },
31+ "files" : [
32+ " app/helpers.php"
33+ ]
3134 },
3235 "autoload-dev" : {
3336 "psr-4" : {
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # CBDB Online Main Server 部署脚本
4+ # 用于在服务器上部署应用时执行必要的更新操作
5+
6+ set -e
7+
8+ echo " 开始部署..."
9+
10+ # 1. 生成版本号文件
11+ echo " 生成版本号文件..."
12+ git rev-parse --short=7 HEAD > version.txt
13+ echo " 版本号: $( cat version.txt) "
14+
15+ # 2. 安装/更新依赖
16+ echo " 更新 Composer 依赖..."
17+ composer install --no-dev --optimize-autoloader
18+
19+ # 3. 清除缓存
20+ echo " 清除应用缓存..."
21+ php artisan cache:clear
22+ php artisan config:clear
23+ php artisan route:clear
24+ php artisan view:clear
25+
26+ # 4. 优化缓存(可选,生产环境建议开启)
27+ # echo "优化缓存..."
28+ # php artisan config:cache
29+ # php artisan route:cache
30+ # php artisan view:cache
31+
32+ echo " 部署完成!"
Original file line number Diff line number Diff line change 22<footer class =" main-footer" >
33 <!-- To the right -->
44 <div class =" pull-right hidden-xs" >
5-
5+ < b >Version:</ b > {{ get_app_version () } }
66 </div >
77 <!-- Default to the left -->
88 <strong >Copyright © ; <a href =" https://cbdb.hsites.harvard.edu/" target =" _blank" >Chinese Biographical Database Project (CBDB)</a >.</strong > Content licensed under <a href =" https://creativecommons.org/licenses/by-nc-sa/4.0/" target =" _blank" >CC BY-NC-SA 4.0 International</a >.
You can’t perform that action at this time.
0 commit comments