n/websiteu/Clina · 10 个月前
注册 登录
n/website · 10 个月前 · 已编辑 · 320 次浏览
u/Clina钻石

将Fuwari博客部署到Codeberg Pages

Codeberg Pages 是 Codeberg 官方提供的一个静态网站托管平台,类似于 Github Pages.
今天我们就要将Fuwari博客部署到Codeberg Pages.
首先,在这里提起一个 Issue,标签选择 ci ,Expected Resource Usage 选 medium,I would also like the following users to be added 填 @自己的 Codeberg 用户名,其他自己看着填,等待审批通过。
审批通过后,打开你在Codeberg上的Fuwari仓库,在仓库根目录新建.forgejo/workflows文件夹.
在文件夹中添加 astro.yml 文件,内容如下:

name: Deploy Astro site to Pages

on:
  # Runs on pushes targeting the default branch
  push:
    branches:
      # If you want to build from a different branch, change it here.
      - main
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  build:
    # You can find the list of available runners on https://codeberg.org/actions/meta, or run one yourself.
    runs-on: codeberg-medium-lazy
    steps:
      - name: Clone the repository
        uses: https://code.forgejo.org/actions/checkout@v4
        with:
          submodules: recursive
          fetch-depth: 0
      - name: check .domains files
        run: |
          git ls-files public/.domains
          ls -la public/
          ls -la public/.domains || echo ".domains not found"
      - name: Setup pnpm
        uses: pnpm/action-setup@v2
        with:
          version: 10
      - name: Setup Node.js
        uses: https://code.forgejo.org/actions/setup-node@v4
        with:
          node-version: 22
          cache: 'pnpm'
      - name: Install dependencies
        run: |
          pnpm install
          pnpm install @astrojs/sitemap
      - name: Build Astro site
        run: pnpm run build

      - name: Upload generated files
        uses: https://code.forgejo.org/actions/upload-artifact@v3
        with:
          name: Generated files
          path: dist/
          include-hidden-files: true
      
  deploy:
    needs: [ build ]
    runs-on: codeberg-tiny-lazy
    steps:
      - name: Clone the repository
        uses: https://code.forgejo.org/actions/checkout@v4
        with:
          submodules: recursive
          fetch-depth: 0

      - name: Checkout the target branch and clean it up
        run: |
          git checkout pages || git switch --orphan pages
          rm -Rfv $(ls -A | egrep -v '^(\.git|LICENSE)$')

      - name: Download generated files
        uses: https://code.forgejo.org/actions/download-artifact@v3
        with:
          name: Generated files

      - name: Publish the website
        run: |
          git config user.email codeberg-ci
          git config user.name "Codeberg CI"
          echo "=== Files being committed ==="
          ls -la
          git add .
          git commit --allow-empty --message "Codeberg build for ${GITHUB_SHA}"
          git push origin pages

然后,就可以愉快的在Codeberg Pages上部署并使用Fuwari博客了!
如果觉得有用,就麻烦点个赞吧,谢谢

3
8
登录后参与讨论。

8 条回复

排序
  1. chendeshen 黄金 2 YEARS 10 个月前

    不错不错

    0
  2. azhaoyihao 荣耀 水王 10 个月前

    感谢大佬的教程分享!

    0
  3. dj56959566 黄金 不离不弃 10 个月前

    地址和效果图片呢

    0
  4. Clina 钻石 楼主 钻石会员 10 个月前

    https://clina.codeberg.page
    我自己的Fuwari博客

    0
  5. tyedh 💕 铂金 10 个月前

    不错不错

    0
  6. syshxt 黄金 10 个月前

    感谢分享,又多了一个选择,提ci多久通过?

    0
  7. Clina 钻石 楼主 钻石会员 10 个月前

    大概1个小时

    0
  8. Clina 钻石 楼主 钻石会员 10 个月前

    https://codeberg.org/Clina/fuwari
    这是我的Fuwari仓库,托管在Codeberg上

    0