feat: 新增 setup-opencode action,支持 npm 全局安装和智能缓存
- 使用 npm 全局安装 OpenCode,支持版本管理和自动更新 - 智能缓存策略:缓存 npm 目录和全局安装,加速后续构建 - 支持淘宝镜像源和自定义 npm 镜像,国内环境友好 - 版本检测:自动比对已安装版本,避免重复安装 - 输出安装版本、缓存命中状态和更新状态 - 提供详细的使用文档和多场景示例
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
name: Basic OpenCode Usage
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, develop ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: 检出代码
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 安装 OpenCode
|
||||
id: setup-opencode
|
||||
uses: ./.gitea/actions/setup-opencode
|
||||
with:
|
||||
version: 'latest'
|
||||
|
||||
- name: 显示安装信息
|
||||
run: |
|
||||
echo "OpenCode 版本: ${{ steps.setup-opencode.outputs.version }}"
|
||||
echo "缓存命中: ${{ steps.setup-opencode.outputs.cache-hit }}"
|
||||
echo "执行更新: ${{ steps.setup-opencode.outputs.updated }}"
|
||||
|
||||
- name: 验证安装
|
||||
run: |
|
||||
opencode --version
|
||||
which opencode
|
||||
|
||||
- name: 使用 OpenCode
|
||||
run: |
|
||||
opencode build
|
||||
@@ -0,0 +1,33 @@
|
||||
name: China Mirror Example
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: 检出代码
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 安装 OpenCode(淘宝镜像)
|
||||
id: setup
|
||||
uses: ./.gitea/actions/setup-opencode
|
||||
with:
|
||||
version: 'latest'
|
||||
use-taobao-registry: 'true'
|
||||
|
||||
- name: 显示安装信息
|
||||
run: |
|
||||
echo "安装版本: ${{ steps.setup.outputs.version }}"
|
||||
echo "缓存命中: ${{ steps.setup.outputs.cache-hit }}"
|
||||
|
||||
if [[ "${{ steps.setup.outputs.cache-hit }}" == "true" ]]; then
|
||||
echo "✅ 使用缓存,快速完成安装"
|
||||
else
|
||||
echo "📥 通过 npm 安装完成"
|
||||
fi
|
||||
|
||||
- name: 构建项目
|
||||
run: |
|
||||
opencode build --release
|
||||
@@ -0,0 +1,21 @@
|
||||
name: Custom Registry Example
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: 检出代码
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 使用自定义 npm 镜像源
|
||||
uses: ./.gitea/actions/setup-opencode
|
||||
with:
|
||||
version: '1.2.3'
|
||||
npm-registry: 'https://registry.npmmirror.com'
|
||||
|
||||
- name: 构建
|
||||
run: |
|
||||
opencode build
|
||||
@@ -0,0 +1,21 @@
|
||||
name: Specific Version Example
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: 检出代码
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: 安装 OpenCode 1.2.3
|
||||
uses: ./.gitea/actions/setup-opencode
|
||||
with:
|
||||
version: '1.2.3'
|
||||
cache-prefix: 'opencode-stable'
|
||||
|
||||
- name: 构建项目
|
||||
run: |
|
||||
opencode build --release
|
||||
Reference in New Issue
Block a user