Feature/add cicd #13
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: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| - feature/* | |
| pull_request: | |
| branches: | |
| - main | |
| - master | |
| jobs: | |
| test: | |
| name: 🧪 Run Tests and Coverage | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js 18 | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 18 | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run tests | |
| run: npm test --silent | |
| - name: Check whether running under act (set output) | |
| id: check_act_test | |
| run: | | |
| if [ "${IS_ACT}" = "true" ]; then | |
| echo "is_act=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "is_act=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Upload coverage report | |
| if: ${{ always() && steps.check_act_test.outputs.is_act != 'true' }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: jest-coverage | |
| path: coverage/ | |
| - name: Generate test summary | |
| if: always() | |
| run: | | |
| echo "### ✅ Test Results" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| npm test --silent >> $GITHUB_STEP_SUMMARY || true | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| release: | |
| name: 🚀 Version & Release | |
| runs-on: ubuntu-latest | |
| needs: test | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check whether running under act (set output) | |
| id: check_act_release | |
| run: | | |
| if [ "${IS_ACT}" = "true" ]; then | |
| echo "is_act=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "is_act=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Setup Node.js | |
| if: ${{ steps.check_act_release.outputs.is_act != 'true' }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 18 | |
| cache: 'npm' | |
| - name: Install dependencies | |
| if: ${{ steps.check_act_release.outputs.is_act != 'true' }} | |
| run: npm ci | |
| - name: Semantic Release | |
| if: ${{ steps.check_act_release.outputs.is_act != 'true' }} | |
| uses: cycjimmy/semantic-release-action@v4 | |
| with: | |
| extra_plugins: | | |
| @semantic-release/changelog | |
| @semantic-release/git | |
| @semantic-release/github | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| deploy: | |
| name: 📦 Deploy to Render | |
| runs-on: ubuntu-latest | |
| needs: release | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Check whether running under act (set output) | |
| id: check_act_deploy | |
| run: | | |
| if [ "${IS_ACT}" = "true" ]; then | |
| echo "is_act=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "is_act=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Setup Node.js | |
| if: ${{ steps.check_act_deploy.outputs.is_act != 'true' }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 18 | |
| cache: 'npm' | |
| - name: Install dependencies | |
| if: ${{ steps.check_act_deploy.outputs.is_act != 'true' }} | |
| run: npm ci | |
| - name: Deploy to Render | |
| if: ${{ steps.check_act_deploy.outputs.is_act != 'true' }} | |
| env: | |
| RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }} | |
| RENDER_SERVICE_ID: ${{ secrets.RENDER_SERVICE_ID }} | |
| run: | | |
| curl -X POST "https://api.render.com/v1/services/${RENDER_SERVICE_ID}/deploys" \ | |
| -H "Accept: application/json" \ | |
| -H "Authorization: Bearer ${RENDER_API_KEY}" \ | |
| -d '' | |
| - name: Send Telegram notification | |
| if: ${{ always() && steps.check_act_deploy.outputs.is_act != 'true' }} | |
| run: | | |
| VERSION=$(git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD) | |
| MESSAGE="✅ Deployment completed successfully on Render! | |
| 🕓 $(date) | |
| 🏷️ Version: $VERSION | |
| 🔗 Repo: $GITHUB_REPOSITORY" | |
| curl -s -X POST https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage \ | |
| -d chat_id=${{ secrets.TELEGRAM_CHAT_ID }} \ | |
| -d text="$MESSAGE" |