開發(fā)了一款小眾開源工具,沒想到還有這么多人用!
由于 Gitee Pages 的訪問速度很快,很多朋友會(huì)選擇 Gitee Pages 部署項(xiàng)目(如:個(gè)人博客、開源項(xiàng)目國內(nèi)鏡像站點(diǎn))。但是它不像 GitHub Pages 那樣,一提交代碼就能自動(dòng)更新 Pages,因?yàn)?Gitee 的自動(dòng)部署屬于 Gitee Pages Pro 的服務(wù)。
為了實(shí)現(xiàn) Gitee Pages 的自動(dòng)部署,我用了近百行 Python 代碼開發(fā)了?Gitee Pages Action[1]?,只需要在 GitHub 項(xiàng)目的 Settings 頁面下配置 keys,然后在?.github/workflows/?下創(chuàng)建一個(gè)工作流,引入一些配置參數(shù)即可。歡迎體驗(yàn),若有使用上的問題,也歡迎隨時(shí)在?Issues[2]?反饋。
開源地址:https://github.com/yanglbme/gitee-pages-action
注:首次需要手動(dòng)登錄 Gitee ,點(diǎn)擊“啟動(dòng)”進(jìn)行 Gitee Pages 服務(wù)的部署。
入?yún)?/h2>參數(shù) 描述 gitee-usernameGitee 用戶名 gitee-passwordGitee 密碼 gitee-repoGitee 倉庫(嚴(yán)格區(qū)分大小寫) branch要部署的分支(分支必須存在) directory要部署的分支上的目錄 https是否強(qiáng)制使用 HTTPS
示例
| 參數(shù) | 描述 |
gitee-username | Gitee 用戶名 |
gitee-password | Gitee 密碼 |
gitee-repo | Gitee 倉庫(嚴(yán)格區(qū)分大小寫) |
branch | 要部署的分支(分支必須存在) |
directory | 要部署的分支上的目錄 |
https | 是否強(qiáng)制使用 HTTPS |
以下是一個(gè)完整示例。
在你的 GitHub 倉庫?.github/workflows/?文件夾下創(chuàng)建一個(gè)?.yml?文件,如?sync.yml,內(nèi)容如下:
name: Syncon: page_buildjobs:build:runs-on: ubuntu-lateststeps:- name: Sync to Giteeuses: wearerequired/git-mirror-action@masterenv:# 注意在 Settings->Secrets 配置 GITEE_RSA_PRIVATE_KEYSSH_PRIVATE_KEY: ${{ secrets.GITEE_RSA_PRIVATE_KEY }}with:# 注意替換為你的 GitHub 源倉庫地址source-repo: git@github.com:doocs/advanced-java.git# 注意替換為你的 Gitee 目標(biāo)倉庫地址destination-repo: git@gitee.com:Doocs/advanced-java.git- name: Build Gitee Pagesuses: yanglbme/gitee-pages-action@mainwith:# 注意替換為你的 Gitee 用戶名gitee-username: yanglbme# 注意在 Settings->Secrets 配置 GITEE_PASSWORDgitee-password: ${{ secrets.GITEE_PASSWORD }}# 注意替換為你的 Gitee 倉庫,倉庫名嚴(yán)格區(qū)分大小寫,請(qǐng)準(zhǔn)確填寫,否則會(huì)出錯(cuò)gitee-repo: doocs/advanced-java# 要部署的分支,默認(rèn)是 master,若是其他分支,則需要指定(指定的分支必須存在)branch: main
先使用?wearerequired/git-mirror-action[3]?將 GitHub 倉庫同步到 Gitee 倉庫,再使用?yanglbme/gitee-pages-action[4]?實(shí)現(xiàn) Gitee Pages 的自動(dòng)部署。
請(qǐng)確保在 GitHub 項(xiàng)目的 Settings -> Secrets 路徑下配置好?GITEE_RSA_PRIVATE_KEY?以及?GITEE_PASSWORD?兩個(gè)密鑰。其中:
?GITEE_RSA_PRIVATE_KEY: 存放你的?id_rsa?私鑰。?GITEE_PASSWORD: 存放你的 Gitee 帳號(hào)的密碼。

如果一切配置正常,并成功觸發(fā)?Gitee Pages Action[5]?,我們會(huì)在 Gitee 公眾號(hào)收到一條登錄通知。這是 GitHub Action 程序幫我們登錄到 Gitee 官網(wǎng),并為我們點(diǎn)擊了項(xiàng)目的部署按鈕。

注:
1.branch?參數(shù)默認(rèn)是?master,如果你是部署在?gh-pages(或者?main) 分支等等,務(wù)必指定?branch: gh-pages(或者?branch: main)。2.branch?對(duì)應(yīng)的分支,必須在倉庫中實(shí)際存在,請(qǐng)不要隨意(不)指定分支,否則可能導(dǎo)致 Gitee Pages 站點(diǎn)出現(xiàn) 404 無法訪問的情況。3.示例中觸發(fā) Action 執(zhí)行的事件設(shè)置為?page_build,你也可以根據(jù)實(shí)際情況指定為其它的觸發(fā)事件。請(qǐng)參考?Events that trigger workflows[6]。
誰在使用
目前,螞蟻金服-數(shù)據(jù)可視化技術(shù)團(tuán)隊(duì)、Doocs 開源社區(qū)等旗下的多個(gè) GitHub 項(xiàng)目都在使用 Gitee Pages Action。如?antvis/g[7]、antvis/F2[8]、antvis/G6[9]、antvis/L7[10]、doocs/advanced-java[11]、doocs/leetcode[12]?等等。
當(dāng)然,還有其他不少用戶在使用這款工具,推薦你用用,覺得不錯(cuò)的話,記得點(diǎn)個(gè) Star 支持一下噢~

引用鏈接
[1]?Gitee Pages Action:?https://github.com/marketplace/actions/gitee-pages-action[2]?Issues:?https://github.com/yanglbme/gitee-pages-action/issues[3]?wearerequired/git-mirror-action:?https://github.com/wearerequired/git-mirror-action[4]?yanglbme/gitee-pages-action:?https://github.com/yanglbme/gitee-pages-action[5]?Gitee Pages Action:?https://github.com/marketplace/actions/gitee-pages-action[6]?Events that trigger workflows:?https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows[7]?antvis/g:?https://github.com/antvis/g[8]?antvis/F2:?https://github.com/antvis/F2[9]?antvis/G6:?https://github.com/antvis/G6[10]?antvis/L7:?https://github.com/antvis/G2Plot[11]?doocs/advanced-java:?https://github.com/doocs/advanced-java[12]?doocs/leetcode:?https://github.com/doocs/leetcode
長按識(shí)別下圖二維碼,關(guān)注公眾號(hào)「Doocs 開源社區(qū)」,第一時(shí)間跟你們分享好玩、實(shí)用的技術(shù)文章與業(yè)內(nèi)最新資訊。
