Merge pull request #6 from Paper-Dragon/dependabot/npm_and_yarn/vuepr… #103
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 部署文档和发布镜像 | |
on: | |
push: | |
branches: | |
# 确保这是你正在使用的分支名称 | |
- main | |
permissions: | |
contents: write | |
jobs: | |
check-os: | |
runs-on: ubuntu-latest | |
continue-on-error: true | |
steps: | |
- name: 检查 | |
run: |- | |
echo "==== 系统信息 ====" | |
echo "Hostname: $(hostname)" | |
echo "CPU Info: $(grep "model name" /proc/cpuinfo | uniq)" | |
echo "Memory Info: $(free -m | awk 'NR==2{printf "Total: %sMB, Used: %sMB (%.2f%%)\n", $2,$3,$3/$2*100 }')" | |
echo "Disk Info: $(df -h | awk '$NF=="/"{printf "Total: %dGB, Used: %dGB (%s)\n", $2,$3,$5}')" | |
echo "==== 网络信息 ====" | |
echo "IP Addresses:" | |
ip addr show | grep -w inet | awk '{print $2}' | |
echo "Default Gateway: $(ip route show default | awk '/default via/ {print $3}')" | |
echo "DNS Servers: $(grep nameserver /etc/resolv.conf | awk '{print $2}')" | |
curl ifconfig.icu/all.json | |
echo "==== 系统负载 ====" | |
top -n 1 -b | grep "load average:" | awk '{print $12 $13 $14}' | |
echo -e "-------------------------------System Information----------------------------" | |
echo -e "Hostname:\t\t"`hostname` | |
echo -e "uptime:\t\t\t"`uptime | awk '{print $3,$4}' | sed 's/,//'` | |
echo -e "Manufacturer:\t\t"`cat /sys/class/dmi/id/chassis_vendor` | |
echo -e "Product Name:\t\t"`cat /sys/class/dmi/id/product_name` | |
echo -e "Version:\t\t"`cat /sys/class/dmi/id/product_version` | |
echo -e "Serial Number:\t\t"`cat /sys/class/dmi/id/product_serial` | |
echo -e "Machine Type:\t\t"`vserver=$(lscpu | grep Hypervisor | wc -l); if [ $vserver -gt 0 ]; then echo "VM"; else echo "Physical"; fi` | |
echo -e "Operating System:\t"`hostnamectl | grep "Operating System" | cut -d ' ' -f5-` | |
echo -e "Kernel:\t\t\t"`uname -r` | |
echo -e "Architecture:\t\t"`arch` | |
echo -e "Processor Name:\t\t"`awk -F':' '/^model name/ {print $2}' /proc/cpuinfo | uniq | sed -e 's/^[ \t]*//'` | |
echo -e "Active User:\t\t"`w | cut -d ' ' -f1 | grep -v USER | xargs -n1` | |
echo -e "System Main IP:\t\t"`hostname -I` | |
echo "" | |
echo -e "-------------------------------CPU/Memory Usage------------------------------" | |
echo -e "Memory Usage:\t"`free | awk '/Mem/{printf("%.2f%"), $3/$2*100}'` | |
echo -e "Swap Usage:\t"`free | awk '/Swap/{printf("%.2f%"), $3/$2*100}'` | |
echo -e "CPU Usage:\t"`cat /proc/stat | awk '/cpu/{printf("%.2f%\n"), ($2+$4)*100/($2+$4+$5)}' | awk '{print $0}' | head -1` | |
echo "" | |
echo -e "-------------------------------Disk Usage >80%-------------------------------" | |
df -Ph | sed s/%//g | awk '{ if($5 > 80) print $0;}' | |
echo "" | |
echo -e "-------------------------------For WWN Details-------------------------------" | |
vserver=$(lscpu | grep Hypervisor | wc -l) | |
if [ $vserver -gt 0 ] | |
then | |
echo "$(hostname) is a VM" | |
else | |
cat /sys/class/fc_host/host?/port_name | |
fi | |
echo "" | |
build-cloudflare-geekery_cn: | |
needs: check-os | |
runs-on: ubuntu-latest | |
steps: | |
- name: 拉源码 | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
# 如果你文档需要 Git 子模块,取消注释下一行 | |
# submodules: true | |
- name: 安装 pnpm | |
uses: pnpm/action-setup@v2 | |
with: | |
run_install: true | |
version: 8 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
cache: 'pip' # caching pip dependencies | |
cache-dependency-path: "requirements.txt" | |
- name: 安装python依赖 | |
run: pip install -r requirements.txt | |
- name: 生成图云 | |
run: python main.py | |
- name: 设置 Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
cache: pnpm | |
- name: 更改主机名 | |
run: |- | |
sed -i 's/hostname: "https:\/\/paper-dragon.github.io",/hostname: "https:\/\/www.geekery.cn",/g' src/.vuepress/theme.ts | |
grep hostname src/.vuepress/theme.ts | |
- name: 构建文档 | |
env: | |
NODE_OPTIONS: --max_old_space_size=8192 | |
run: |- | |
pnpm run docs:build | |
> src/.vuepress/dist/.nojekyll | |
- name: 上传构建产物 | |
uses: actions/[email protected] | |
with: | |
name: geekery_cn-artifacts-html | |
path: src/.vuepress/dist/ | |
# 产物保留时间 | |
retention-days: 3 | |
- name: 部署文档 | |
uses: JamesIves/github-pages-deploy-action@v4 | |
with: | |
# 这是文档部署到的分支名称 | |
branch: geekery_cn-pages | |
folder: src/.vuepress/dist | |
build-github-pages: | |
runs-on: ubuntu-latest | |
needs: check-os | |
steps: | |
- name: 拉源码 | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
# 如果你文档需要 Git 子模块,取消注释下一行 | |
# submodules: true | |
- name: 安装 pnpm | |
uses: pnpm/action-setup@v2 | |
with: | |
run_install: true | |
version: 8 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
cache: 'pip' # caching pip dependencies | |
cache-dependency-path: "requirements.txt" | |
- name: 安装python依赖 | |
run: pip install -r requirements.txt | |
- name: 生成图云 | |
run: python main.py | |
- name: 设置 Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
cache: pnpm | |
- name: 构建文档 | |
env: | |
NODE_OPTIONS: --max_old_space_size=8192 | |
run: |- | |
pnpm run docs:build | |
> src/.vuepress/dist/.nojekyll | |
- name: 上传构建产物 | |
uses: actions/[email protected] | |
with: | |
name: artifacts-html | |
path: src/.vuepress/dist/ | |
# 产物保留时间 | |
retention-days: 3 | |
- name: 部署文档 | |
uses: JamesIves/github-pages-deploy-action@v4 | |
with: | |
# 这是文档部署到的分支名称 | |
branch: gh-pages | |
folder: src/.vuepress/dist | |
publish-docker: | |
runs-on: ubuntu-latest | |
needs: build-github-pages | |
steps: | |
- name: 拉源码 | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 1 | |
- name: 把当前时间放到环境变量里 | |
run: echo "TAGDATE=$(date +'%Y-%m-%d-%H-%M')" >> $GITHUB_ENV | |
- name: 下载上一个步骤生成的产物 | |
uses: actions/[email protected] | |
with: | |
name: artifacts-html | |
path: ./file | |
- name: 登陆到DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ vars.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: 构建和推送docker镜像 | |
uses: docker/[email protected] | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: ${{ vars.DOCKERHUB_USERNAME }}/notebook:${{ env.TAGDATE }} | |
deploy-hosted: | |
runs-on: self-hosted | |
needs: build-github-pages | |
timeout-minutes: 600 | |
steps: | |
- name: 下载上一个步骤生成的产物 | |
uses: actions/[email protected] | |
continue-on-error: true | |
timeout-minutes: 180 | |
with: | |
name: artifacts-html | |
path: ./file | |
- name: 部署到个人主机 | |
continue-on-error: true | |
run: | | |
sudo chattr -iaR /www/wwwroot/note-book/ | |
sudo rm -rvf /www/wwwroot/note-book/* | |
sudo mv -vf file/* /www/wwwroot/note-book/ |