Update Dashboard #802
This file contains hidden or 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: Update Dashboard | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "00 18 * * *" | |
| push: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - "README.md" | |
| - ".github/workflows/delete-old-workflows.yml" | |
| - ".github/workflows/update-adguardhome.yml" | |
| - ".github/workflows/update-mihomo.yml" | |
| - ".github/workflows/update-singbox.yml" | |
| permissions: | |
| contents: write | |
| jobs: | |
| Update: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Clone Repository | |
| uses: actions/checkout@v7 | |
| - name: Set variables | |
| run: | | |
| while true; do | |
| yacd_meta_version=$(curl -sSL https://api.github.com/repos/MetaCubeX/Yacd-meta/releases/latest | jq -r '.tag_name') | |
| yacd_meta_time=$(curl -sSL https://api.github.com/repos/MetaCubeX/Yacd-meta/commits/gh-pages | jq -r '.commit.committer.date' | xargs -I {} date -d '{} +8 hours' '+%Y-%m-%d') | |
| metacubexd_version=$(curl -sSL https://api.github.com/repos/MetaCubeX/metacubexd/releases/latest | jq -r '.tag_name') | |
| metacubexd_time=$(curl -sSL https://api.github.com/repos/MetaCubeX/metacubexd/commits/gh-pages | jq -r '.commit.committer.date' | xargs -I {} date -d '{} +8 hours' '+%Y-%m-%d') | |
| zashboard_version=$(curl -sSL https://api.github.com/repos/Zephyruso/zashboard/releases/latest | jq -r '.tag_name') | |
| zashboard_time=$(curl -sSL https://api.github.com/repos/Zephyruso/zashboard/commits/gh-pages-cdn-fonts | jq -r '.commit.committer.date' | xargs -I {} date -d '{} +8 hours' '+%Y-%m-%d') | |
| singbox_dashboard_version=$(curl -sSL https://api.github.com/repos/SagerNet/sing-box-dashboard/commits/gh-pages | jq -r '.sha[:7]') | |
| singbox_dashboard_time=$(curl -sSL https://api.github.com/repos/SagerNet/sing-box-dashboard/commits/gh-pages | jq -r '.commit.committer.date' | xargs -I {} date -d '{} +8 hours' '+%Y-%m-%d') | |
| if [[ -n "${yacd_meta_version}" && "${yacd_meta_version}" != "null" && -n "${metacubexd_version}" && "${metacubexd_version}" != "null" && -n "${zashboard_version}" && "${zashboard_version}" != "null" && -n "${singbox_dashboard_version}" && "${singbox_dashboard_version}" != "null" ]]; then | |
| echo "yacd_meta_version=${yacd_meta_version}" >> ${GITHUB_ENV} | |
| echo "yacd_meta_time=${yacd_meta_time}" >> ${GITHUB_ENV} | |
| echo "metacubexd_version=${metacubexd_version}" >> ${GITHUB_ENV} | |
| echo "metacubexd_time=${metacubexd_time}" >> ${GITHUB_ENV} | |
| echo "zashboard_version=${zashboard_version}" >> ${GITHUB_ENV} | |
| echo "zashboard_time=${zashboard_time}" >> ${GITHUB_ENV} | |
| echo "singbox_dashboard_version=${singbox_dashboard_version}" >> ${GITHUB_ENV} | |
| echo "singbox_dashboard_time=${singbox_dashboard_time}" >> ${GITHUB_ENV} | |
| break | |
| fi | |
| echo "未获取到面板版本号,将在 10 秒后重试..." | |
| sleep 10 | |
| done | |
| shell: bash | |
| - name: Compare `Dashboard` versions with current release | |
| run: | | |
| current_body=$(curl -sSL "https://api.github.com/repos/${{ github.repository }}/releases/tags/Dashboard" | jq -r '.body // ""') | |
| archs=( | |
| "Yacd-meta|${yacd_meta_version}|${yacd_meta_time}" | |
| "metacubexd|${metacubexd_version}|${metacubexd_time}" | |
| "zashboard|${zashboard_version}|${zashboard_time}" | |
| "sing-box dashboard|${singbox_dashboard_version}|${singbox_dashboard_time}" | |
| ) | |
| for arch in "${archs[@]}"; do | |
| IFS="|" read -r name version time <<< "$arch" | |
| var_name="${name//[^a-zA-Z0-9_]/_}_skip_release" | |
| if echo "${current_body}" | grep -q "${name}.*${version}.*${time}"; then | |
| echo "当前 ${name} 版本已是最新版本 ${version},无需更新" | |
| eval "${var_name}=true" | |
| else | |
| echo "当前 ${name} 版本较低,需要更新最新版本至 ${version}" | |
| eval "${var_name}=false" | |
| fi | |
| eval "value=\$${var_name}" | |
| echo "${var_name}=${value}" >> ${GITHUB_ENV} | |
| done | |
| - name: Download and compress `Yacd-meta` | |
| if: ${{ env.Yacd_meta_skip_release != 'true' }} | |
| run: | | |
| mkdir -p ./Dashboard/ ./tmp/Yacd-meta/ | |
| curl -sS -o ./tmp/Yacd-meta/gh-pages.zip -L https://github.com/MetaCubeX/Yacd-meta/archive/gh-pages.zip | |
| unzip -q -o ./tmp/Yacd-meta/gh-pages.zip -d ./tmp/Yacd-meta/ | |
| cd ./tmp/Yacd-meta/Yacd-meta-gh-pages/ | |
| tar -czf ../../../Dashboard/Yacd-meta.tar.gz * | |
| - name: Download and compress `metacubexd` | |
| if: ${{ env.metacubexd_skip_release != 'true' }} | |
| run: | | |
| mkdir -p ./Dashboard/ ./tmp/metacubexd/ | |
| curl -sS -o ./tmp/metacubexd/gh-pages.zip -L https://github.com/MetaCubeX/metacubexd/archive/gh-pages.zip | |
| unzip -q -o ./tmp/metacubexd/gh-pages.zip -d ./tmp/metacubexd/ | |
| cd ./tmp/metacubexd/metacubexd-gh-pages/ | |
| tar -czf ../../../Dashboard/metacubexd.tar.gz * | |
| - name: Download and compress `zashboard` | |
| if: ${{ env.zashboard_skip_release != 'true' }} | |
| run: | | |
| mkdir -p ./Dashboard/ ./tmp/zashboard/ | |
| curl -sS -o ./tmp/zashboard/gh-pages.zip -L https://github.com/Zephyruso/zashboard/archive/gh-pages-cdn-fonts.zip | |
| unzip -q -o ./tmp/zashboard/gh-pages.zip -d ./tmp/zashboard/ | |
| cd ./tmp/zashboard/zashboard-gh-pages-cdn-fonts/ | |
| tar -czf ../../../Dashboard/zashboard.tar.gz * | |
| - name: Download and compress `sing-box dashboard` | |
| if: ${{ env.sing_box_dashboard_skip_release != 'true' }} | |
| run: | | |
| mkdir -p ./Dashboard/ ./tmp/sing-box-dashboard/ | |
| curl -sS -o ./tmp/sing-box-dashboard/gh-pages.zip -L https://github.com/SagerNet/sing-box-dashboard/archive/gh-pages.zip | |
| unzip -q -o ./tmp/sing-box-dashboard/gh-pages.zip -d ./tmp/sing-box-dashboard/ | |
| cd ./tmp/sing-box-dashboard/sing-box-dashboard-gh-pages/ | |
| tar -czf ../../../Dashboard/sing-box-dashboard.tar.gz * | |
| - name: Check if `Dashboard` files exist | |
| run: | | |
| if ls ./Dashboard/*.tar.gz >/dev/null 2>&1; then | |
| echo "Dashboard 文件夹内存在新面板文件,需要上传" | |
| echo "dashboard_exist=true" >> ${GITHUB_ENV} | |
| else | |
| echo "Dashboard 文件夹内没有新面板文件,无需上传" | |
| echo "dashboard_exist=false" >> ${GITHUB_ENV} | |
| fi | |
| - name: Release and upload `Dashboard` assets | |
| if: ${{ env.dashboard_exist == 'true' }} | |
| uses: svenstaro/upload-release-action@v2 | |
| with: | |
| repo_token: ${{ secrets.GITHUB_TOKEN }} | |
| release_name: Dashboard | |
| tag: Dashboard | |
| overwrite: true | |
| body: | | |
| 更新 [Yacd-meta](https://github.com/MetaCubeX/Yacd-meta)至 ${{ env.yacd_meta_version }},发布于 ${{ env.yacd_meta_time }} | |
| 更新 [metacubexd](https://github.com/MetaCubeX/metacubexd)至 ${{ env.metacubexd_version }},发布于 ${{ env.metacubexd_time }} | |
| 更新 [zashboard](https://github.com/Zephyruso/zashboard)至 ${{ env.zashboard_version }},发布于 ${{ env.zashboard_time }} | |
| 更新 [sing-box dashboard](https://github.com/SagerNet/sing-box-dashboard)至 ${{ env.singbox_dashboard_version }},发布于 ${{ env.singbox_dashboard_time }} | |
| file_glob: true | |
| file: ./Dashboard/* |