前一篇在 Mapleboard 上成功地佈署了新版 serverless 平台, 驗證 API Key 功能正常, 整個重構專案來到尾聲, 本篇要將專案提交上傳 GitHub 更新儲存庫.
8. 提交新版 serverless 與上傳 GitHub :
在提交之前, 我回顧了前面的測試過程, 發現剛開始時是從 https://github.com/tony1966/serverless.git 複製專案到 D:\antigravity_cli\projects 底下, 然後將其打上 tag 標記後建立一個新分支 api-token-auth, 再叫 agy 用 Claude 模型去重構此專案, 這就形成了 Nested Repository (巢狀儲存庫) : serverless 資料夾內自成一國 (裡面有自己的 .git), 而外層的 antigravity_cli 也有自己的 .git 現象.
站在 D:\antigravity_cli 的角度看 projects/serverless 時, Git 預設只會把 serverless 當成一個被忽略的子目錄或是一個未追蹤的 gitlink, 兩邊的 Commit 完全是分開互不干擾的. 在 serverless 下提交並 push 時會上傳到 https://github.com/tony1966/serverless 上, 而非 Antigravity CLI 的 repo 庫https://github.com/tony1966/antigravity_cli. 雖然這種國中有國的情況並不少見, 但我想讓專案資料夾與儲存庫的關係單純點, 所以將此 serverless 專案剪下來貼到 D:\ 下, 與 D:\antigravity_cli\projects 分家.
分家後的 serverless 也要有自己的 .gitignore, 所以我把 Antigravity CLI 大倉庫下的 .gitignore 複製一份來給它用 :
# ==========================================
# Python 相關快取與編譯檔案
# ==========================================
__pycache__/
*.py[cod]
*$py.class
.pytest_cache/
.poetry/
.venv/
venv/
ENV/
env/
# ==========================================
# 專案實務資料與測試產出
# ==========================================
*.json
*.db
*.log
# ==========================================
# 開發工具與編輯器暫存檔
# ==========================================
.vscode/
.idea/
*.swp
*.bak
.DS_Store
Thumbs.db
# ==========================================
# 敏感資料與環境變數 (絕對不能上傳)
# ==========================================
.env
.env.local
.env.*.local
*.env
分家後的 serverless 專案結構如下 :
PS D:\> tree serverless /f
列出磁碟區 新增磁碟區 的資料夾 PATH
磁碟區序號為 0000027B 1258:16B8
D:\SERVERLESS
│ .env
│ .gitignore
│ Procfile
│ requirements.txt
│ serverless.db
│ serverless.py
│ serverless_error.log
│
└─functions
│ add_function.py
│ add_table.py
│ clear_stats.py
│ delete_function.py
│ delete_record.py
│ drop_table.py
│ edit_function.py
│ execute_sql.py
│ export_table.py
│ hello.py
│ list_functions.py
│ list_tables.py
│ save_function.py
│ show_schema.py
│ show_stats.py
│ update_function.py
│ view_table.py
│ __init__.py
│
└─apps_backup
add.py
hello.py
linebot_gemini.py
linebot_gpt.py
send_books_messages.py
send_ksml_books_messages.py
update_ksml_books.py
這樣便可進行 Git 提交作業了, 首先切換到專案目錄下 :
S D:\> cd serverless
然後用 git add . 指令將所有變更加入暫存區, 把修改過的程式碼與新增的 .gitignore 檔加入追蹤 (.gitignore 內所舉的檔案除外) :
PS D:\serverless> git add .
warning: in the working copy of 'functions/save_function.py', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'functions/update_function.py', LF will be replaced by CRLF the next time Git touches it
PS D:\serverless>
報出的 warning 可以忽略.
然後建立 Commit 紀錄, 將變更封裝並附上明確的功能說明 :
PS D:\serverless> git commit -m "feat: implement serverless API core with API Key auth"
[feature/api-token-auth df845ce] feat: implement serverless API core with API Key auth
5 files changed, 172 insertions(+), 37 deletions(-)
create mode 100644 .gitignore
create mode 100644 functions/hello.py
接下來是推送到 GitHub 遠端倉庫的 feature/api-token-auth 分支 (-u 參數會自動建立本地與遠端分支的追蹤關係) :
PS D:\serverless> git push -u origin feature/api-token-auth
Enumerating objects: 23, done.
Counting objects: 100% (23/23), done.
Delta compression using up to 16 threads
Compressing objects: 100% (18/18), done.
Writing objects: 100% (18/18), 8.71 KiB | 1.24 MiB/s, done.
Total 18 (delta 7), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (7/7), completed with 4 local objects.
remote:
remote: Create a pull request for 'feature/api-token-auth' on GitHub by visiting:
remote: https://github.com/tony1966/serverless/pull/new/feature/api-token-auth
remote:
To https://github.com/tony1966/serverless.git
* [new branch] feature/api-token-auth -> feature/api-token-auth
branch 'feature/api-token-auth' set up to track 'origin/feature/api-token-auth'.
可見 18 個檔案物件已成功打包上傳 (其中包含新的 .gitignore 與 code), 且在 GitHub 成功建立獨立的 feature/api-token-auth 分支與追蹤關係. 這時到 GitHub 去察看此 repo :
可見 GitHub 遠端倉庫 tony1966/serverless 已經順利接收到了最新的變更, 而下方的是 main 分支 (正式生產環境) 的檔案列表, 顯示它依然維持 6 個月前的穩定版本, 只要此 feature/api-token-auth 分支尚未合併到 main 分支就不會影響目前依賴此 repo 的線上服務 (例如 render.com).
目前暫時先做到這裡, 後續若準備好要把 API Key 驗證功能部署到 Render.com 時, 只要按右上角的 "Compare & pull request" 鈕, 檢查變更內容沒問題後按 "Create pull request" 鈕, 再按 "Merge pull request" 與 "Confirm merge" 鈕即可合併的 main 分支, 完成升版的最後一塊拼圖.
如果要在終端機下指令合併, 順序如下 :
# 切換到 main 分支
git checkout main
# 拉取遠端最新 main(確保同步)
git pull origin main
# 將 feature 分支合併進 main
git merge feature/api-token-auth
# 推送回 GitHub main 分支(會觸發 Render 自動部署)
git push origin main

沒有留言 :
張貼留言