Files
antigravity/action.yml
T

98 lines
5.1 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 用途:定義可在 GitHub Actions 中使用的 Antigravity CLI composite action,負責安裝 Antigravity CLI、設定 OAuth token、執行提示詞並輸出文字結果。
# 更新日期:2026/06/29 16:11:33
# 設定 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: '輸出的文字'
# 將輸出值對應到 id 為 antigravity 的步驟所寫入的 text output。
value: ${{ steps.antigravity.outputs.text }}
# 宣告 action 的執行方式與步驟。
runs:
# 指定此 action 使用 composite 執行模式(由多個 step 組成)。
using: 'composite'
# 定義 composite action 的執行步驟順序。
steps:
# 第一步:建立安裝 Antigravity CLI 與設定認證檔案的步驟。
- name: 安裝工具
# 宣告此步驟需要的環境變數。
env:
# 將呼叫端提供的 oauth input 放入 OAUTH 環境變數,供 run 區塊解碼寫入檔案;此值為 secret,不可記錄到日誌。
OAUTH: ${{ inputs.oauth }}
# 執行 Antigravity CLI 安裝與 OAuth token 檔案建立流程。
run: |
# 下載並執行 Antigravity CLI 安裝腳本;curl -f 在 HTTP 錯誤時會讓指令失敗,-sSL 為靜默、顯示錯誤、跟隨重導。
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 檔案所在目錄,並限制目錄權限為擁有者可讀寫執行(700)。
install -d -m 700 "$(dirname "$oauth_file")"
# 將 OAUTH 環境變數中的 base64 內容解碼後寫入 token 檔案;此處輸出的是 secret 明文檔案,切勿 echo 或記錄其內容。
printf '%s' "$OAUTH" | base64 -d > "$oauth_file"
# 限制 token 檔案權限為擁有者可讀寫(600),避免其他使用者讀取機敏 token。
chmod 600 "$oauth_file"
# 指定此步驟使用 bash shell 執行。
shell: bash
# 第二步:建立執行 Antigravity CLI 並寫入 action output 的步驟。
- name: 執行工具
# 設定步驟 id 為 antigravity,供 outputs.text 透過 steps.antigravity.outputs.text 取得結果。
id: antigravity
# 宣告此步驟需要的環境變數。
env:
# 從 repository variable 讀取 Antigravity CLI 使用的模型名稱(ANTIGRAVITY_MODEL)。
MODEL: ${{ vars.ANTIGRAVITY_MODEL }}
# 將呼叫端提供的 prompt input 放入 PROMPT 環境變數。
PROMPT: ${{ inputs.prompt }}
# 執行 Antigravity CLI,列印結果並寫入 GitHub Actions output。
run: |
# 前置檢查:確認呼叫端 repository 已設定 ANTIGRAVITY_MODEL variable,未設定時提前失敗。
if [ -z "$MODEL" ]; then
# 將錯誤訊息輸出到標準錯誤,提示需設定 ANTIGRAVITY_MODEL repository variable。
echo 'ANTIGRAVITY_MODEL repository variable is required.' >&2
# 以非零退出碼結束步驟,使整個 action 失敗。
exit 1
fi
# 使用指定提示詞與模型執行 Antigravity CLIagy --print),並把標準輸出捕捉到 text 變數。
text="$(agy --print "$PROMPT" --model "$MODEL")"
# 將 Antigravity CLI 回傳文字輸出到目前步驟日誌。
printf '%s\n' "$text"
# 開始以 GitHub Actions multiline output 格式寫入 text 輸出(使用 here-string 邊界)。
{
# 寫入 multiline output 的起始標記(heredoc 邊界 ANTIGRAVITY_OUTPUT)。
echo 'text<<ANTIGRAVITY_OUTPUT'
# 寫入 Antigravity CLI 回傳文字內容。
printf '%s\n' "$text"
# 寫入 multiline output 的結束標記。
echo 'ANTIGRAVITY_OUTPUT'
} >> "$GITHUB_OUTPUT"
# 指定此步驟使用 bash shell 執行。
shell: bash