aboutsummaryrefslogtreecommitdiff
path: root/.forgejo/workflows/mkdocs-deploy.yml
blob: 473ff149b1b667cf8ee1e8d14dede7e291c70757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Note: This workflow is specially optimized for building the site in Mainland China.

name: Deploy MkDocs to Another Repository

on:
  push:
    branches:
      - main
    paths:
      - 'docs/**'
      - 'mkdocs.yml'
      - 'overrides/**'
      - '.forgejo/workflows/mkdocs-deploy.yml'
  pull_request:
    branches:
      - main
    paths:
      - 'docs/**'
      - 'mkdocs.yml'
      - 'overrides/**'
      - '.forgejo/workflows/mkdocs-deploy.yml'
  workflow_dispatch:

concurrency:
  group: "pages"
  cancel-in-progress: false

jobs:
  build-and-deploy:
    runs-on: build-env
    steps:
      - name: Checkout source code
        uses: https://gitea.cn/actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Install MkDocs dependencies
        run: |
          python -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
          
          python -m pip install --upgrade pip
          
          pip install -r requirements.txt

      - name: Build MkDocs site
        run: mkdocs build --strict

      - name: Deploy to target repository
        if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
        env:
          TARGET_REPO: https://codeberg.org/LinuxCabin/handbook-site
          TARGET_BRANCH: pages
          DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
        run: |
          cd site
          echo "hb.linuxcabin.top" > CNAME
          git init
          git config user.name "${{ github.actor }}"
          git config user.email "${{ github.actor }}@noreply.codeberg.org"
          git add .
          git commit -m "Deploy site $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
          git push --force https://x-access-token:${DEPLOY_TOKEN}@${TARGET_REPO#https://} HEAD:${TARGET_BRANCH}