Sync Examples from SDKs #14
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: Sync Examples from SDKs | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| exchange: | |
| description: 'Exchange to sync (binance, bitget, bitmart, bybit, coinbase, gate, kraken, kucoin, okx)' | |
| required: true | |
| type: choice | |
| options: | |
| - all | |
| - binance | |
| - bitget | |
| - bitmart | |
| - bybit | |
| - coinbase | |
| - gate | |
| - kraken | |
| - kucoin | |
| - okx | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout crypto-api-examples | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Configure Git | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Determine exchanges to sync | |
| id: determine-exchanges | |
| run: | | |
| if [ "${{ github.event.inputs.exchange }}" == "all" ]; then | |
| echo "exchanges=binance bitget bitmart bybit coinbase gate kraken kucoin okx" >> $GITHUB_OUTPUT | |
| echo "✅ Will sync all exchanges" | |
| else | |
| echo "exchanges=${{ github.event.inputs.exchange }}" >> $GITHUB_OUTPUT | |
| echo "✅ Will sync: ${{ github.event.inputs.exchange }}" | |
| fi | |
| - name: Clone SDK repositories | |
| run: | | |
| cd .. | |
| for exchange in ${{ steps.determine-exchanges.outputs.exchanges }}; do | |
| case $exchange in | |
| binance) REPO="binance" ORG="tiagosiebler" ;; | |
| bitget) REPO="bitget-api" ORG="tiagosiebler" ;; | |
| bitmart) REPO="bitmart-api" ORG="tiagosiebler" ;; | |
| bybit) REPO="bybit-api" ORG="tiagosiebler" ;; | |
| coinbase) REPO="coinbase-api" ORG="tiagosiebler" ;; | |
| gate) REPO="gateio-api" ORG="tiagosiebler" ;; | |
| kraken) REPO="kraken-api" ORG="sieblyio" ;; | |
| kucoin) REPO="kucoin-api" ORG="tiagosiebler" ;; | |
| okx) REPO="okx-api" ORG="tiagosiebler" ;; | |
| esac | |
| if [ ! -d "$REPO" ]; then | |
| echo "📥 Cloning $REPO..." | |
| git clone --depth 1 "https://github.com/$ORG/$REPO.git" || { | |
| echo "⚠️ Failed to clone $REPO, trying with token..." | |
| git clone --depth 1 "https://${{ secrets.GITHUB_TOKEN }}@github.com/$ORG/$REPO.git" || { | |
| echo "❌ Failed to clone $REPO" | |
| continue | |
| } | |
| } | |
| else | |
| echo "📥 Updating $REPO..." | |
| cd "$REPO" | |
| git pull || git fetch origin && git reset --hard origin/main || git reset --hard origin/master | |
| cd .. | |
| fi | |
| done | |
| cd crypto-api-examples | |
| - name: Verify GitHub CLI | |
| run: gh --version | |
| - name: Sync examples | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| for exchange in ${{ steps.determine-exchanges.outputs.exchanges }}; do | |
| echo "🔄 Syncing $exchange..." | |
| # Run sync script (it will handle PR creation) | |
| # Capture exit code to see if it failed | |
| if ! npm run sync:$exchange; then | |
| echo "❌ Failed to sync $exchange. Check logs above for details." | |
| exit 1 | |
| fi | |
| done | |
| - name: Summary | |
| if: always() | |
| run: | | |
| echo "## Sync Examples Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "✅ Sync workflow completed" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Check the logs above for details and PR creation links." >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Note:** If PRs were not created automatically, check the logs above for clickable PR creation links." >> $GITHUB_STEP_SUMMARY |