|
| 1 | +name: OnCall Bot CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master ] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +env: |
| 9 | + REGISTRY: ghcr.io |
| 10 | + IMAGE_NAME: sre-helmcode/oncall-slack-bot |
| 11 | + VERSION: "1.0.4" |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-and-deploy: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + contents: write |
| 18 | + packages: write |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 25 | + |
| 26 | + - name: Set up Python |
| 27 | + uses: actions/setup-python@v4 |
| 28 | + with: |
| 29 | + python-version: '3.11' |
| 30 | + |
| 31 | + - name: Install dependencies and test |
| 32 | + run: | |
| 33 | + python -m pip install --upgrade pip |
| 34 | + pip install -r requirements.txt |
| 35 | + # Basic syntax check |
| 36 | + python -m py_compile main.py |
| 37 | + python -m py_compile handlers/commands.py |
| 38 | + python -m py_compile services/postgres_storage.py |
| 39 | +
|
| 40 | + - name: Log in to Container Registry |
| 41 | + uses: docker/login-action@v3 |
| 42 | + with: |
| 43 | + registry: ${{ env.REGISTRY }} |
| 44 | + username: ${{ github.actor }} |
| 45 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + |
| 47 | + - name: Build and push Docker image |
| 48 | + uses: docker/build-push-action@v5 |
| 49 | + with: |
| 50 | + context: . |
| 51 | + push: true |
| 52 | + tags: | |
| 53 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} |
| 54 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest |
| 55 | +
|
| 56 | + - name: Update Helm chart |
| 57 | + run: | |
| 58 | + # Update image tag in values.yaml |
| 59 | + sed -i "s/tag: \".*\"/tag: \"${{ env.VERSION }}\"/" helm/oncall-slack-bot/values.yaml |
| 60 | +
|
| 61 | + # Update chart version |
| 62 | + sed -i "s/version: .*/version: ${{ env.VERSION }}/" helm/oncall-slack-bot/Chart.yaml |
| 63 | + sed -i "s/appVersion: .*/appVersion: \"${{ env.VERSION }}\"/" helm/oncall-slack-bot/Chart.yaml |
| 64 | +
|
| 65 | + - name: Commit changes |
| 66 | + run: | |
| 67 | + git config --local user.email "action@github.com" |
| 68 | + git config --local user.name "GitHub Action" |
| 69 | +
|
| 70 | + if git diff --quiet; then |
| 71 | + echo "No changes to commit" |
| 72 | + exit 0 |
| 73 | + fi |
| 74 | +
|
| 75 | + git add helm/oncall-slack-bot/values.yaml helm/oncall-slack-bot/Chart.yaml |
| 76 | + git commit -m "🚀 Update to version ${{ env.VERSION }}" |
| 77 | + git push |
| 78 | +
|
| 79 | + - name: Deploy summary |
| 80 | + run: | |
| 81 | + echo "✅ Deployment completed!" |
| 82 | + echo "🐳 Image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}" |
| 83 | + echo "📦 ArgoCD will deploy automatically" |
0 commit comments