|
| 1 | +name: Auto-update Go SDK |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run daily at 2 AM UTC |
| 6 | + - cron: "0 2 * * *" |
| 7 | + workflow_dispatch: # Allow manual trigger |
| 8 | + inputs: |
| 9 | + force_update: |
| 10 | + description: "Force update even if no new SDK version" |
| 11 | + required: false |
| 12 | + default: false |
| 13 | + type: boolean |
| 14 | + |
| 15 | +jobs: |
| 16 | + check-sdk-updates: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + has_updates: ${{ steps.check-updates.outputs.has_updates }} |
| 20 | + new_version: ${{ steps.check-updates.outputs.new_version }} |
| 21 | + current_version: ${{ steps.check-updates.outputs.current_version }} |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout repository |
| 25 | + uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 28 | + |
| 29 | + - name: Set up Go |
| 30 | + uses: actions/setup-go@v5 |
| 31 | + with: |
| 32 | + go-version: "1.24" |
| 33 | + |
| 34 | + - name: Check for SDK updates |
| 35 | + id: check-updates |
| 36 | + run: | |
| 37 | + # Get current SDK version from go.mod |
| 38 | + current_version=$(grep "github.com/VapiAI/server-sdk-go" go.mod | awk '{print $2}') |
| 39 | + echo "Current SDK version: $current_version" |
| 40 | + echo "current_version=$current_version" >> $GITHUB_OUTPUT |
| 41 | +
|
| 42 | + # Get latest SDK version from GitHub API |
| 43 | + latest_version=$(curl -s https://api.github.com/repos/VapiAI/server-sdk-go/releases/latest | jq -r '.tag_name') |
| 44 | + echo "Latest SDK version: $latest_version" |
| 45 | + echo "new_version=$latest_version" >> $GITHUB_OUTPUT |
| 46 | +
|
| 47 | + # Compare versions (remove 'v' prefix for comparison) |
| 48 | + current_clean=$(echo $current_version | sed 's/^v//') |
| 49 | + latest_clean=$(echo $latest_version | sed 's/^v//') |
| 50 | +
|
| 51 | + if [[ "$current_clean" != "$latest_clean" ]] || [[ "${{ github.event.inputs.force_update }}" == "true" ]]; then |
| 52 | + echo "SDK update available: $current_version -> $latest_version" |
| 53 | + echo "has_updates=true" >> $GITHUB_OUTPUT |
| 54 | + else |
| 55 | + echo "No SDK updates available" |
| 56 | + echo "has_updates=false" >> $GITHUB_OUTPUT |
| 57 | + fi |
| 58 | +
|
| 59 | + update-and-release: |
| 60 | + runs-on: ubuntu-latest |
| 61 | + needs: check-sdk-updates |
| 62 | + if: needs.check-sdk-updates.outputs.has_updates == 'true' |
| 63 | + |
| 64 | + steps: |
| 65 | + - name: Checkout repository |
| 66 | + uses: actions/checkout@v4 |
| 67 | + with: |
| 68 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 69 | + |
| 70 | + - name: Set up Go |
| 71 | + uses: actions/setup-go@v5 |
| 72 | + with: |
| 73 | + go-version: "1.24" |
| 74 | + |
| 75 | + - name: Configure Git |
| 76 | + run: | |
| 77 | + git config --global user.name "github-actions[bot]" |
| 78 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 79 | +
|
| 80 | + - name: Update Go SDK dependency |
| 81 | + run: | |
| 82 | + echo "Updating Go SDK to ${{ needs.check-sdk-updates.outputs.new_version }}" |
| 83 | + go get github.com/VapiAI/server-sdk-go@${{ needs.check-sdk-updates.outputs.new_version }} |
| 84 | + go mod tidy |
| 85 | +
|
| 86 | + - name: Run tests |
| 87 | + run: | |
| 88 | + echo "Running tests to ensure compatibility..." |
| 89 | + make test |
| 90 | +
|
| 91 | + - name: Run linter |
| 92 | + run: | |
| 93 | + echo "Running linter to ensure code quality..." |
| 94 | + make lint |
| 95 | +
|
| 96 | + - name: Bump CLI version |
| 97 | + id: bump-version |
| 98 | + run: | |
| 99 | + # Read current CLI version |
| 100 | + current_cli_version=$(cat VERSION | tr -d '\n') |
| 101 | + echo "Current CLI version: $current_cli_version" |
| 102 | +
|
| 103 | + # Parse version components (assuming semantic versioning) |
| 104 | + IFS='.' read -ra ADDR <<< "$current_cli_version" |
| 105 | + major=${ADDR[0]} |
| 106 | + minor=${ADDR[1]} |
| 107 | + patch=${ADDR[2]} |
| 108 | +
|
| 109 | + # Increment patch version |
| 110 | + new_patch=$((patch + 1)) |
| 111 | + new_cli_version="$major.$minor.$new_patch" |
| 112 | +
|
| 113 | + echo "New CLI version: $new_cli_version" |
| 114 | + echo "$new_cli_version" > VERSION |
| 115 | +
|
| 116 | + echo "new_cli_version=$new_cli_version" >> $GITHUB_OUTPUT |
| 117 | +
|
| 118 | + - name: Update version references |
| 119 | + run: | |
| 120 | + # Update any hardcoded version references in the code |
| 121 | + new_version="${{ steps.bump-version.outputs.new_cli_version }}" |
| 122 | +
|
| 123 | + # Update version in cmd/version.go if it exists |
| 124 | + if [ -f "cmd/version.go" ]; then |
| 125 | + sed -i "s/version = \"[^\"]*\"/version = \"$new_version\"/" cmd/version.go |
| 126 | + fi |
| 127 | +
|
| 128 | + - name: Commit changes |
| 129 | + run: | |
| 130 | + git add . |
| 131 | + git commit -m "chore: update Go SDK to ${{ needs.check-sdk-updates.outputs.new_version }} |
| 132 | +
|
| 133 | + - Updated github.com/VapiAI/server-sdk-go from ${{ needs.check-sdk-updates.outputs.current_version }} to ${{ needs.check-sdk-updates.outputs.new_version }} |
| 134 | + - Bumped CLI version to ${{ steps.bump-version.outputs.new_cli_version }} |
| 135 | + - Updated dependencies with go mod tidy |
| 136 | +
|
| 137 | + This automated update ensures the CLI stays compatible with the latest API changes." |
| 138 | +
|
| 139 | + - name: Create Pull Request |
| 140 | + id: create-pr |
| 141 | + uses: peter-evans/create-pull-request@v7 |
| 142 | + with: |
| 143 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 144 | + branch: auto-update-sdk-${{ needs.check-sdk-updates.outputs.new_version }} |
| 145 | + title: "chore: Auto-update Go SDK to ${{ needs.check-sdk-updates.outputs.new_version }}" |
| 146 | + body: | |
| 147 | + ## 🤖 Automated SDK Update |
| 148 | +
|
| 149 | + This PR automatically updates the Vapi Go SDK to the latest version to ensure CLI compatibility with recent API changes. |
| 150 | +
|
| 151 | + ### Changes |
| 152 | + - **Go SDK**: `${{ needs.check-sdk-updates.outputs.current_version }}` → `${{ needs.check-sdk-updates.outputs.new_version }}` |
| 153 | + - **CLI Version**: Bumped to `${{ steps.bump-version.outputs.new_cli_version }}` |
| 154 | + - **Dependencies**: Updated with `go mod tidy` |
| 155 | +
|
| 156 | + ### Verification |
| 157 | + - ✅ Tests passed (`make test`) |
| 158 | + - ✅ Linting passed (`make lint`) |
| 159 | + - ✅ Dependencies resolved (`go mod tidy`) |
| 160 | +
|
| 161 | + ### Next Steps |
| 162 | + 1. Review the changes in this PR |
| 163 | + 2. Merge when ready |
| 164 | + 3. A new release will be automatically created |
| 165 | +
|
| 166 | + ### SDK Release Notes |
| 167 | + Check the [Go SDK releases](https://github.com/VapiAI/server-sdk-go/releases/tag/${{ needs.check-sdk-updates.outputs.new_version }}) for details on what changed. |
| 168 | +
|
| 169 | + --- |
| 170 | + *This PR was created automatically by the SDK update workflow. Review and merge when ready.* |
| 171 | + labels: | |
| 172 | + dependencies |
| 173 | + automation |
| 174 | + sdk-update |
| 175 | + assignees: | |
| 176 | + ${{ github.actor }} |
| 177 | +
|
| 178 | + - name: Log PR creation |
| 179 | + if: steps.create-pr.outputs.pull-request-number |
| 180 | + run: | |
| 181 | + echo "📋 SDK Update PR created: #${{ steps.create-pr.outputs.pull-request-number }}" |
| 182 | + echo "🔗 PR URL: ${{ steps.create-pr.outputs.pull-request-url }}" |
| 183 | + echo "" |
| 184 | + echo "ℹ️ This PR requires manual review and approval." |
| 185 | + echo " Once merged, it will automatically trigger a new release." |
| 186 | +
|
| 187 | + notify-on-failure: |
| 188 | + runs-on: ubuntu-latest |
| 189 | + needs: [check-sdk-updates, update-and-release] |
| 190 | + if: failure() && needs.check-sdk-updates.outputs.has_updates == 'true' |
| 191 | + |
| 192 | + steps: |
| 193 | + - name: Notify on failure |
| 194 | + run: | |
| 195 | + echo "❌ SDK update workflow failed!" |
| 196 | + echo "Current SDK version: ${{ needs.check-sdk-updates.outputs.current_version }}" |
| 197 | + echo "New SDK version: ${{ needs.check-sdk-updates.outputs.new_version }}" |
| 198 | + echo "Manual intervention may be required." |
| 199 | +
|
| 200 | + # You can add Slack/Discord notifications here if needed |
| 201 | + # curl -X POST -H 'Content-type: application/json' \ |
| 202 | + # --data '{"text":"🚨 CLI SDK auto-update failed for version ${{ needs.check-sdk-updates.outputs.new_version }}"}' \ |
| 203 | + # ${{ secrets.SLACK_WEBHOOK_URL }} |
0 commit comments