feat(action): 安裝 Claude Code CLI 並還原 OAuth 憑證

This commit is contained in:
Jeffery
2026-07-17 12:52:10 +08:00
parent 9b23a21106
commit 3b3bb8058d
+43 -15
View File
@@ -1,22 +1,50 @@
name: 'Gitea Composite Template'
description: 'Gitea Composite 範本'
# ============================================================================
# 用途:安裝 Claude Code CLI,並將 base64 編碼的 OAuth 憑證解碼寫入設定檔的 Gitea Composite Action。
# 更新時間:2026/07/17 11:54:39
# ============================================================================
# action 名稱,顯示於 Gitea Actions UI 與被其他 workflow 引用時的識別名稱
name: 'Setup Claude'
# action 用途描述,說明此 composite action 的目的
description: '安裝 Claude Code CLI 並還原 OAuth 憑證的 Gitea Composite Action'
# action 作者
author: 'Jeffery'
# 輸入參數契約:定義呼叫端可傳入的參數
inputs:
message:
description: '輸入訊息'
required: false
default: 'Hello, World!'
outputs:
message:
description: '輸出訊息'
value: ${{ steps.exchange.outputs.message }}
# oauthbase64 編碼的 OAuth 憑證字串,通常由呼叫端以 secret 傳入
oauth:
# 參數說明
description: 'base64 編碼的 OAuth 憑證字串(解碼後寫入 Claude 憑證檔)'
# 必填;缺少憑證則無法完成設定
required: true
# 執行定義區塊
runs:
# 指定為 composite(複合)action,由多個 step 組成
using: 'composite'
# 依序執行的步驟清單
steps:
- name: Exchange
id: exchange
# 啟動橫幅 step:於 action 開始時印出 action 名稱/用途/更新時間,方便日誌辨識
- name: 顯示 action 資訊
# 使用 bash shell 執行
shell: bash
env:
MESSAGE: ${{ inputs.message }}
# 刻意設計的啟動輸出,以分隔線包住 action 基本資訊(各 echo 行為刻意保留的橫幅格式,勿改寫)
run: |
echo "message=$MESSAGE" >> "$GITHUB_OUTPUT"
echo "================================================"
echo "Action : Setup Claude"
echo "用途 : 安裝 Claude Code CLI 並還原 OAuth 憑證"
echo "更新時間: 2026/07/17 11:54:39"
echo "================================================"
# 安裝 Claude Code CLI(以 npm 全域安裝,單行指令)
- name: 安裝 Claude Code CLI
# 使用 bash shell 執行
shell: bash
# 以 npm 全域安裝官方 Claude Code 套件
run: npm install -g @anthropic-ai/claude-code
# 將 base64 OAuth 憑證解碼並寫入 Claude 憑證檔(單行:建目錄 → 解碼寫檔 → 限縮權限;不輸出憑證內容)
- name: 寫入 OAuth 憑證
# 使用 bash shell 執行
shell: bash
# 環境變數:把 inputs.oauth 帶入環境供 run 使用(避免直接內嵌於指令列)
env:
OAUTH_B64: ${{ inputs.oauth }}
# 單行完成:mkdir 父目錄、base64 解碼寫入憑證檔、chmod 600 限縮權限
run: mkdir -p "$HOME/.claude" && printf '%s' "$OAUTH_B64" | base64 -d > "$HOME/.claude/.credentials.json" && chmod 600 "$HOME/.claude/.credentials.json"