Gmeek Deploy Another Repo

Gmeek Deploy Another Repo

Gmeek 部署其他仓库

📦 原有: Gmeek.yml

原有 GitHub Actions ,通过 actions/upload-pages-artifact@v3actions/deploy-pages@v4 自动化部署到本仓库的虚拟机上(注:不知这样理解是否正确)。

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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: build Gmeek

on:
workflow_dispatch:
issues:
types: [opened, edited]
schedule:
- cron: \"0 16 * * *\"

jobs:
build:
name: Generate blog
runs-on: ubuntu-24.04
if: ${{ github.event.repository.owner.id == github.event.sender.id || github.event_name == 'schedule' }}
permissions: write-all
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Pages
id: pages
uses: actions/configure-pages@v4

- name: Get config.json
run: |
echo \"====== check config.josn file ======\"
cat config.json
echo \"====== check config.josn end ======\"
sudo apt-get install jq

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.8

- name: Clone source code
run: |
GMEEK_VERSION=$(jq -r \".GMEEK_VERSION\" config.json)
git clone https://github.com/Meekdai/Gmeek.git /opt/Gmeek;
cd /opt/Gmeek/
lastTag=$(git describe --tags `git rev-list --tags --max-count=1`)
if [ $GMEEK_VERSION == 'last' ]; then git checkout $lastTag; else git checkout $GMEEK_VERSION; fi;

- name: Install dependencies
run: |
pip install --upgrade pip
pip install -r /opt/Gmeek/requirements.txt

- name: Generate new html
run: |
cp -r ./* /opt/Gmeek/
cd /opt/Gmeek/
python Gmeek.py ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} --issue_number '${{ github.event.issue.number }}'
cp -a /opt/Gmeek/docs ${{ github.workspace }}
cp -a /opt/Gmeek/backup ${{ github.workspace }}
cp /opt/Gmeek/blogBase.json ${{ github.workspace }}

- name: update html
run: |
git config --local user.email \"$(jq -r \".email\" config.json)\"
git config --local user.name \"${{ github.repository_owner }}\"
git add .
git commit -a -m '🎉auto update by Gmeek action' || echo \"nothing to commit\"
git push || echo \"nothing to push\"
sleep 3

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: 'docs/.'

deploy:
name: Deploy blog
runs-on: ubuntu-24.04
needs: build
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: \"pages\"
cancel-in-progress: false
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

🔧 .yml 修改需求

源仓库生成相关文件后,将静态页面 ./docs 下的文件推送到博客仓库分支 gh-pages 上,即网站部署在分支。

  • 源仓库: shenjuexiao/gmeek-source
  • 博客仓库: shenjuexiao/gmeek-docs
  • 工作流 Deploy 增加 docs 下静态页面部署到博客仓库 gh-pages 分支
  • 使用 peaceiris/actions-gh-pages
  • 跨仓库使用 token:${{ secrets.GMEEK_DOCS }}

❌ Error: HttpError: Not Found

Gmeek Deploy Setup Pages

注释掉本地的部署

1
2
3
4
# 不需要配置 GitHub Pages
# - name: Setup Pages
# id: pages
# uses: actions/configure-pages@v4
1
2
3
4
5
6
7
# 去掉源仓库的部署
# actions/upload-pages-artifact@v3 是专门为 GitHub Pages 设计的
# 创建特殊的 artifact,只能被 actions/deploy-pages@v4 使用
# - name: Upload artifact
# uses: actions/upload-pages-artifact@v3
# with:
# path: 'docs/.'
1
2
3
4
# 去掉源仓库的部署
# - name: Deploy to GitHub Pages
# id: deployment
# uses: actions/deploy-pages@v4

🔑 Error: Action failed with "not found deploy key for tokens"

Gmeek Deploy docs to

源仓库需要设置 token

  • 创建 GitHub 个人访问令牌 PAT Personal access tokens (classic)
    GitHub 头像,Settings -> Developer settings -> Personal access tokens -> Tokens (classic)
    新建 Token,勾选权限:repo(全部仓库读写权限)。
    复制生成的 Token(仅展示一次,丢失需重建)。
  • 仓库配置 Repository secrets
    仓库首页, Settings -> Secrets and variables -> Actions -> New repository secret
    Name:GH_TOKEN。
    Value:粘贴上面的 PAT。

✅ 修改后 gmeek-docs.yml

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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: build Gmeek

on:
workflow_dispatch:
issues:
types: [opened, edited]
# schedule:
# - cron: \"0 16 * * *\"

jobs:
build:
name: Generate blog
runs-on: ubuntu-24.04
if: ${{ github.event.repository.owner.id == github.event.sender.id || github.event_name == 'schedule' }}
permissions: write-all
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get config.json
run: |
echo \"====== check config.josn file ======\"
cat config.json
echo \"====== check config.josn end ======\"
sudo apt-get install jq

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.8

- name: Clone source code
run: |
GMEEK_VERSION=$(jq -r \".GMEEK_VERSION\" config.json)
git clone https://github.com/Meekdai/Gmeek.git /opt/Gmeek;
cd /opt/Gmeek/
lastTag=$(git describe --tags `git rev-list --tags --max-count=1`)
if [ $GMEEK_VERSION == 'last' ]; then git checkout $lastTag; else git checkout $GMEEK_VERSION; fi;

- name: Install dependencies
run: |
pip install --upgrade pip
pip install -r /opt/Gmeek/requirements.txt

- name: Generate new html
run: |
cp -r ./* /opt/Gmeek/
cd /opt/Gmeek/
python Gmeek.py ${{ secrets.GITHUB_TOKEN }} ${{ github.repository }} --issue_number '${{ github.event.issue.number }}'
cp -a /opt/Gmeek/docs ${{ github.workspace }}
cp -a /opt/Gmeek/backup ${{ github.workspace }}
cp /opt/Gmeek/blogBase.json ${{ github.workspace }}

- name: update html
run: |
git config --local user.email \"$(jq -r \".email\" config.json)\"
git config --local user.name \"${{ github.repository_owner }}\"
git add .
git commit -a -m '🎉auto update by Gmeek action' || echo \"nothing to commit\"
git push || echo \"nothing to push\"
sleep 3

# 生成 HTML 后立即将 docs 文件夹上传为 artifact
- name: Upload docs artifact
uses: actions/upload-artifact@v4
with:
name: docs
path: ${{ github.workspace }}/docs
# 设置保留 1 天,节省存储空间
retention-days: 1

deploy:
name: Deploy blog
runs-on: ubuntu-24.04
needs: build
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: \"pages\"
cancel-in-progress: false
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
# 先下载 build job 上传的 docs artifact,下载到 ./docs 目录
- name: Download docs artifact
uses: actions/download-artifact@v4
with:
name: docs
path: ./docs

# 新增:部署 docs 到博客仓库的gh-pages分支
- name: Deploy docs to gmeek-docs gh-pages
uses: peaceiris/actions-gh-pages@v3
with:
personal_token: ${{ secrets.GMEEK_DOCS }}
external_repository: shenjuexiao/gmeek-docs
publish_branch: gh-pages
publish_dir: ./docs
commit_message: '🚀 Deploy static pages to gh-pages'
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
keep_files: false
force_orphan: false