Files
antigravity/action.yml
T

96 lines
4.5 KiB
YAML

# 用途:定義可在 GitHub Actions 中使用的 Antigravity CLI composite action,負責安裝 Antigravity CLI、設定 OAuth token、執行提示詞並輸出文字結果。
# 更新日期:2026/06/27 23:35:00
# 設定 action 顯示名稱,供 workflow 引用與介面顯示。
name: 'Antigravity CLI'
# 設定 action 描述,說明此 composite action 提供 Antigravity CLI 工具能力。
description: 'Antigravity CLI 工具'
# 設定 action 作者資訊。
author: 'Jeffery'
# 宣告此 action 可接收的輸入參數。
inputs:
# 定義傳給 Antigravity CLI 的提示詞輸入。
prompt:
# 說明 prompt 輸入會被傳遞給 Antigravity CLI。
description: '傳給 Antigravity CLI 的提示詞'
# 允許呼叫端不提供 prompt,未提供時使用預設值。
required: false
# 設定 prompt 的預設提示詞。
default: "請自我介紹"
# 定義 base64 編碼後的 OAuth token 檔案內容輸入。
oauth:
# 說明 oauth 輸入需提供 base64 編碼的 Antigravity OAuth token 檔案內容;不得在註解或日誌中輸出明文。
description: 'base64 編碼的 Antigravity OAuth token 檔案內容'
# 要求呼叫端必須提供 OAuth token 內容。
required: true
# 宣告此 action 會輸出的資料。
outputs:
# 定義文字輸出欄位,供後續 workflow step 使用。
text:
# 說明 text 輸出為 Antigravity CLI 回傳的文字。
description: '輸出的文字'
# 將輸出值對應到 antigravity step 寫入的 text output。
value: ${{ steps.antigravity.outputs.text }}
# 宣告 action 的執行方式與步驟。
runs:
# 指定此 action 使用 composite 執行模式。
using: 'composite'
# 定義 composite action 的執行步驟順序。
steps:
# 建立安裝 Antigravity CLI 與設定認證檔案的步驟。
- name: 安裝工具
# 宣告此步驟需要的環境變數。
env:
# 將呼叫端提供的 oauth input 放入 OAUTH 環境變數,供 run 區塊解碼寫入檔案。
OAUTH: ${{ inputs.oauth }}
# 執行 Antigravity CLI 安裝與 OAuth token 檔案建立流程。
run: |
# 下載並執行 Antigravity CLI 安裝腳本,curl 失敗時會因 -f 參數讓指令失敗。
curl -fsSL https://antigravity.google/cli/install.sh | bash
# 將使用者本機安裝路徑加入 GitHub Actions 後續步驟的 PATH。
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
# 設定 Antigravity CLI 預期讀取的 OAuth token 檔案路徑。
oauth_file="$HOME/.gemini/antigravity-cli/antigravity-oauth-token"
# 建立 OAuth token 檔案所在目錄,並限制目錄權限為擁有者可讀寫執行。
install -d -m 700 "$(dirname "$oauth_file")"
# 將 OAUTH 環境變數中的 base64 內容解碼後寫入 token 檔案;此處不輸出 secret 明文。
printf '%s' "$OAUTH" | base64 -d > "$oauth_file"
# 限制 token 檔案權限為擁有者可讀寫,避免其他使用者讀取。
chmod 600 "$oauth_file"
# 指定此步驟使用 bash shell 執行。
shell: bash
# 建立執行 Antigravity CLI 並寫入 action output 的步驟。
- name: 執行工具
# 設定步驟 id,供 outputs.text 透過 steps.antigravity.outputs.text 取得結果。
id: antigravity
# 宣告此步驟需要的環境變數。
env:
# 從 repository variable 讀取 Antigravity CLI 使用的模型名稱。
MODEL: ${{ vars.ANTIGRAVITY_MODEL }}
# 將呼叫端提供的 prompt input 放入 PROMPT 環境變數。
PROMPT: ${{ inputs.prompt }}
# 執行 Antigravity CLI,列印結果並寫入 GitHub Actions output。
run: |
# 確認呼叫端 repository 已設定 ANTIGRAVITY_MODEL variable。
if [ -z "$MODEL" ]; then
echo 'ANTIGRAVITY_MODEL repository variable is required.' >&2
exit 1
fi
# 使用指定提示詞與模型執行 Antigravity CLI,並把標準輸出捕捉到 text 變數。
text="$(agy --print "$PROMPT" --model "$MODEL")"
# 將 Antigravity CLI 回傳文字輸出到目前步驟日誌。
printf '%s\n' "$text"
# 開始以 GitHub Actions multiline output 格式寫入 text 輸出。
{
# 寫入 multiline output 的起始標記。
echo 'text<<ANTIGRAVITY_OUTPUT'
# 寫入 Antigravity CLI 回傳文字內容。
printf '%s\n' "$text"
# 寫入 multiline output 的結束標記。
echo 'ANTIGRAVITY_OUTPUT'
} >> "$GITHUB_OUTPUT"
# 指定此步驟使用 bash shell 執行。
shell: bash