update-service #228
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
| # Workflow triggered by Jenkins to update rc.yaml when a service is built | |
| # | |
| # Jenkins calls: | |
| # curl -X POST \ | |
| # -H "Authorization: token $GITHUB_TOKEN" \ | |
| # -H "Accept: application/vnd.github.v3+json" \ | |
| # https://api.github.com/repos/linto-ai/linto-deploy/dispatches \ | |
| # -d '{"event_type":"service-updated","client_payload":{"service":"studio-api","tag":"latest","commit_sha":"abc123"}}' | |
| name: Update RC Version | |
| on: | |
| repository_dispatch: | |
| types: [update-service] | |
| jobs: | |
| update-rc: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install dependencies | |
| run: pip install requests pyyaml | |
| - name: Update RC version | |
| env: | |
| SERVICE: ${{ github.event.client_payload.service }} | |
| TAG: ${{ github.event.client_payload.tag || 'latest' }} | |
| COMMIT_SHA: ${{ github.event.client_payload.commit_sha }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| python scripts/update-rc-service.py | |
| - name: Commit and push changes | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add versions/rc.yaml | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| exit 0 | |
| fi | |
| git commit -m "chore(rc): update ${{ github.event.client_payload.service }} to ${{ github.event.client_payload.commit_sha }}" | |
| # Retry push with rebase to handle concurrent workflow runs | |
| max_attempts=5 | |
| for i in $(seq 1 $max_attempts); do | |
| if git push; then | |
| echo "Push successful" | |
| exit 0 | |
| fi | |
| echo "Push failed (attempt $i/$max_attempts), rebasing and retrying..." | |
| sleep $(( (RANDOM % 3) + i )) | |
| if ! git pull --rebase; then | |
| echo "Rebase failed (merge conflict), aborting" | |
| git rebase --abort | |
| exit 1 | |
| fi | |
| done | |
| echo "Push failed after $max_attempts attempts" | |
| exit 1 |