Fetch AI Models #25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Fetch AI Models | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| providers: | |
| description: 'Comma-separated list of providers to fetch (leave empty for all)' | |
| required: false | |
| default: '' | |
| push: | |
| tags: | |
| - 'release-*.*.*' | |
| env: | |
| NODE_ENV: production | |
| QINIU_CDN_AK: ${{ secrets.QINIU_CDN_AK }} | |
| QINIU_CDN_SK: ${{ secrets.QINIU_CDN_SK }} | |
| QINIU_BUCKET: ${{ secrets.QINIU_BUCKET }} | |
| jobs: | |
| fetch-and-update: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22.13.1' | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v2 | |
| with: | |
| version: 10.12.1 | |
| - name: Cache pnpm dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.pnpm-store | |
| node_modules/ | |
| key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pnpm- | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Build project | |
| run: pnpm build | |
| - name: Create dist directory | |
| run: mkdir -p dist | |
| - name: Fetch model data | |
| run: | | |
| if [ -n "${{ github.event.inputs.providers }}" ]; then | |
| node build/cli.js fetch-providers -p "${{ github.event.inputs.providers }}" -o dist | |
| else | |
| node build/cli.js fetch-all -o dist | |
| fi | |
| env: | |
| # Add API keys as secrets if needed | |
| OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | |
| ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} | |
| GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }} | |
| GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} | |
| - name: Validate generated JSON files | |
| run: | | |
| echo "Validating JSON files..." | |
| for file in dist/*.json; do | |
| if [ -f "$file" ]; then | |
| echo "Validating $file" | |
| jq empty "$file" || (echo "Invalid JSON in $file" && exit 1) | |
| fi | |
| done | |
| - name: List generated files | |
| run: | | |
| echo "Generated files:" | |
| ls -la dist/ | |
| echo "File sizes:" | |
| du -h dist/*.json | |
| - name: Prepare CDN upload payload | |
| run: | | |
| rm -rf cdn_upload | |
| mkdir -p cdn_upload/models | |
| if compgen -G "dist/*" > /dev/null; then | |
| cp -r dist/* cdn_upload/models/ | |
| fi | |
| echo "CDN payload contents:" | |
| find cdn_upload -type f | sort | |
| - name: Upload dist to Qiniu CDN | |
| id: upload_cdn | |
| if: ${{ env.QINIU_CDN_AK != '' && env.QINIU_CDN_SK != '' && env.QINIU_BUCKET != '' }} | |
| uses: hujiulong/action-qiniu-upload@master | |
| with: | |
| access_key: ${{ env.QINIU_CDN_AK }} | |
| secret_key: ${{ env.QINIU_CDN_SK }} | |
| bucket: ${{ env.QINIU_BUCKET }} | |
| source_dir: 'cdn_upload/models' | |
| dest_dir: '/models' | |
| ignore_source_map: false | |
| - name: CDN Upload Summary | |
| if: steps.upload_cdn.outcome == 'success' | |
| run: | | |
| echo "✅ 模型配置已同步至 Qiniu CDN" | |
| echo "📂 源目录: dist" | |
| echo "🚀 目标目录: /models" | |
| echo "🗂️ 同步文件列表:" | |
| find cdn_upload/models -type f | sort | |
| - name: Generate release info | |
| id: release_info | |
| run: | | |
| # Extract provider information from all.json | |
| if [ -f "dist/all.json" ]; then | |
| TOTAL_MODELS=$(jq -r '.totalModels' dist/all.json) | |
| PROVIDERS=$(jq -r '.providers | keys | join(", ")' dist/all.json) | |
| PROVIDER_COUNT=$(jq -r '.providers | keys | length' dist/all.json) | |
| echo "total_models=$TOTAL_MODELS" >> $GITHUB_OUTPUT | |
| echo "providers=$PROVIDERS" >> $GITHUB_OUTPUT | |
| echo "provider_count=$PROVIDER_COUNT" >> $GITHUB_OUTPUT | |
| else | |
| echo "total_models=0" >> $GITHUB_OUTPUT | |
| echo "providers=none" >> $GITHUB_OUTPUT | |
| echo "provider_count=0" >> $GITHUB_OUTPUT | |
| fi | |
| # Generate timestamp | |
| echo "timestamp=$(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_OUTPUT | |
| echo "date_short=$(date -u '+%Y%m%d')" >> $GITHUB_OUTPUT | |
| - name: Create Release Assets | |
| if: github.ref_type == 'tag' | |
| run: | | |
| # Create tarball of all JSON files with proper naming | |
| cd dist | |
| TAG_NAME="${{ github.ref_name }}" | |
| tar -czf "../provider-configs-${TAG_NAME}.tar.gz" *.json | |
| # Also create individual provider archives | |
| for file in *.json; do | |
| if [ "$file" != "all.json" ]; then | |
| provider_name=$(basename "$file" .json) | |
| tar -czf "../${provider_name}-${TAG_NAME}.tar.gz" "$file" | |
| fi | |
| done | |
| cd .. | |
| - name: Upload Artifacts (workflow dispatch) | |
| if: github.event_name == 'workflow_dispatch' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: provider-configs-${{ steps.release_info.outputs.date_short }} | |
| path: | | |
| dist/*.json | |
| retention-days: 30 | |
| - name: Create Release (tagged) | |
| if: github.ref_type == 'tag' | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| name: Release ${{ github.ref_name }} | |
| body: | | |
| 🏷️ **Tagged Release of AI Model Configurations** | |
| **Release Version:** ${{ github.ref_name }} | |
| **Generated:** ${{ steps.release_info.outputs.timestamp }} | |
| **Total Models:** ${{ steps.release_info.outputs.total_models }} | |
| **Providers:** ${{ steps.release_info.outputs.provider_count }} (${{ steps.release_info.outputs.providers }}) | |
| ## 📦 Available Downloads | |
| ### Complete Package | |
| - `provider-configs-${{ github.ref_name }}.tar.gz` - All provider configurations | |
| ### Individual Provider Packages | |
| Available individual provider archives for selective downloading. | |
| ### Raw JSON Files | |
| Individual JSON files are also available as release assets for direct access. | |
| ## 📊 Provider Details | |
| - **Total Models:** ${{ steps.release_info.outputs.total_models }} | |
| - **Providers:** ${{ steps.release_info.outputs.providers }} | |
| - **Provider Count:** ${{ steps.release_info.outputs.provider_count }} | |
| ## 🔄 Integration | |
| ### Direct JSON Access | |
| ```javascript | |
| // Access aggregated data | |
| const response = await fetch('https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/all.json'); | |
| const modelData = await response.json(); | |
| ``` | |
| ### Complete Package Download | |
| ```bash | |
| wget https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/provider-configs-${{ github.ref_name }}.tar.gz | |
| tar -xzf provider-configs-${{ github.ref_name }}.tar.gz | |
| ``` | |
| --- | |
| *This release was automatically generated from the latest provider data.* | |
| files: | | |
| dist/*.json | |
| *.tar.gz | |
| draft: false | |
| prerelease: false |