hugo-github-linux-build-deploy #252
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: "hugo-github-linux-build-deploy" | |
| on: | |
| # push: | |
| # branches: | |
| # - hugo-blog | |
| # paths-ignore: | |
| # - .github/workflows/pages-deploy.yml | |
| # - .gitignore | |
| # - README.md | |
| # - LICENSE | |
| # Allows you to run this workflow manually from the Actions tab | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| # Allow one concurrent deployment | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: true | |
| jobs: | |
| build-hugo-blog: | |
| runs-on: ["self-hosted", "zp-nc10"] | |
| environment: | |
| name: github-pages | |
| env: | |
| BRANCH_NAME: 'hugo-ok' | |
| steps: | |
| # - name: Auto Checkout | |
| # uses: actions/checkout@v4 | |
| # with: | |
| # fetch-depth: 0 | |
| # submodules: true | |
| - name: 手动Checkout | |
| env: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| if [[ -e ".git" ]]; then | |
| echo "目录已存在,直接更新" | |
| git checkout $BRANCH_NAME | |
| git pull | |
| git log -n2 | |
| else | |
| echo "目录不存在,开始克隆" | |
| git clone https://gh-proxy.com/github.com/linjonh/TechBlog.git . | |
| git checkout $BRANCH_NAME | |
| fi | |
| pwd && cd themes | |
| if [[ -e "loveIt/.git" ]]; then | |
| echo "目录已存在,直接更新" | |
| cd loveIt && git pull | |
| git log -n2 && cd .. | |
| else | |
| echo "目录不存在,开始克隆" | |
| git clone https://gh-proxy.com/github.com/linjonh/hugo-theme-loveIt.git loveIt | |
| fi | |
| pwd && cd .. && pwd | |
| git config --global --add safe.directory $(pwd) | |
| git config --global --add safe.directory $(pwd)/themes/loveIt | |
| git status | |
| #uses: actions/cache@v3 | |
| #with: | |
| #path: | | |
| #resources | |
| #public | |
| #key: ${{ runner.os }}-hugo-${{ github.sha }} | |
| #restore-keys: | | |
| #${{ runner.os }}-hugo- | |
| #- name: Cache Hugo Resources | |
| - name: Setup Pages | |
| id: pages | |
| uses: actions/configure-pages@v4 | |
| # - name: 安装 Hugo | |
| # uses: peaceiris/actions-hugo@v3 | |
| # with: | |
| # hugo-version: "0.145.0" # 也可以指定具体版本,如 '0.123.4' | |
| # extended: true # 是否安装扩展版(支持 SCSS/SASS) | |
| - name: 检查是否已安装 Hugo | |
| id: hugo_check | |
| run: | | |
| if command -v hugo > /dev/null; then | |
| echo "found=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "found=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: 安装 Hugo | |
| if: steps.hugo_check.outputs.found == 'false' | |
| uses: peaceiris/actions-hugo@v3 | |
| with: | |
| hugo-version: "0.145.0" | |
| extended: true | |
| - name: show veresion | |
| run: hugo version | |
| # 先安装 Node.js,Firebase 部署需要用到 ✅ (先安装 Node.js 和 npx) | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Build site | |
| # --gc:启用垃圾回收(清理无用资源)。 | |
| # --minify:压缩 HTML、CSS 和 JS,提高构建效率。 | |
| # --templateMetrics:输出模板渲染耗时。 | |
| # --templateMetricsHints:提供优化建议,帮你找出构建瓶颈。 | |
| run: | | |
| echo "开始构建" | |
| echo "pwd && GOMAXPROCS=$(nproc) HUGO_ENVIRONMENT=production hugo --gc --minify --templateMetrics --templateMetricsHints" | |
| pwd && GOMAXPROCS=$(nproc) HUGO_ENVIRONMENT=production hugo --gc --minify --templateMetrics --templateMetricsHints | |
| # #上传到github pages | |
| # - name: Upload site artifact | |
| # uses: actions/upload-pages-artifact@v3 | |
| # with: | |
| # path: public | |
| # 上传到 Firebase Hosting | |
| - name: Deploy to Firebase Hosting | |
| uses: FirebaseExtended/action-hosting-deploy@v0 | |
| with: | |
| repoToken: ${{ secrets.GITHUB_TOKEN }} | |
| firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_DEEPSEEKSBLOG }} | |
| channelId: live | |
| projectId: deepseeksblog | |
| # 上传搜索数据到 Algolia | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Upload search data to Algolia | |
| env: | |
| ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }} | |
| ALGOLIA_WRITE_KEY: ${{ secrets.ALGOLIA_WRITE_KEY }} | |
| run: npm run upload | |
| # deploy: | |
| # environment: | |
| # name: github-pages | |
| # url: ${{ steps.deployment.outputs.page_url }} | |
| # runs-on: ["self-hosted", "4090"] | |
| # needs: build-hugo-blog | |
| # steps: | |
| # - name: Deploy to GitHub Pages | |
| # id: deployment | |
| # uses: actions/deploy-pages@v4 |