From dee16d922c254ca8664d578e3c0ecbce6edb578d Mon Sep 17 00:00:00 2001 From: Ali Sadeghi Date: Fri, 17 Oct 2025 17:27:24 +0330 Subject: [PATCH 1/3] fix: update Telegram notification to include deployment status and improve message formatting --- .github/workflows/ci.yml | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d9ebb1b..585d543 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -96,7 +96,7 @@ jobs: @semantic-release/git @semantic-release/github env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GH_PAT }} deploy: name: 📦 Deploy to Render @@ -141,26 +141,29 @@ jobs: -d '' - name: Send Telegram notification - if: ${{ always() && steps.check_act_deploy.outputs.is_act != 'true' }} + if: always() run: | VERSION=$(git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD) BRANCH=$(git rev-parse --abbrev-ref HEAD) COMMIT=$(git rev-parse --short HEAD) REPO_URL="https://github.com/$GITHUB_REPOSITORY" LAST_AUTHOR=$(git log -1 --pretty=format:'%an') - LAST_COMMIT_MSG=$(git log -1 --pretty=format:'%s') - MESSAGE="✅ Deployment completed successfully on Render! - 🕓 $(date) - 🏷️ Version/Tag: $VERSION - 🌿 Branch: $BRANCH - 🔀 Commit: $COMMIT - 👤 Last Commit Author: $LAST_AUTHOR - 💬 Last Commit Msg: $LAST_COMMIT_MSG - 🔗 Repo: $REPO_URL" + if [ "${{ job.status }}" = "success" ]; then + STATUS="✅ *Deployment succeeded*" + else + STATUS="❌ *Deployment failed*" + fi + MESSAGE="$STATUS + 🕓 *Date:* $(date) + 🏷️ *Version/Tag:* $VERSION + 🌿 *Branch:* $BRANCH + 🔀 *Commit:* $COMMIT + 👤 *Author:* $LAST_AUTHOR + 🔗 *Repo:* $REPO_URL" + curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \ -d "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \ -d "text=$MESSAGE" \ -d "parse_mode=Markdown" - From 42966106d72a44e4855b44c0b16e5843a2a8ef7f Mon Sep 17 00:00:00 2001 From: Ali Sadeghi Date: Fri, 17 Oct 2025 23:27:35 +0330 Subject: [PATCH 2/3] fix: streamline CI pipeline and enhance Telegram notification with detailed results --- .github/workflows/ci.yml | 82 +++++++++++++++++----------------------- package.json | 4 ++ 2 files changed, 39 insertions(+), 47 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 585d543..cb6c252 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,15 +1,12 @@ -name: CI/CD Pipeline +name: CI Pipeline on: push: branches: - main - - master - - feature/* pull_request: branches: - main - - master jobs: test: @@ -32,17 +29,8 @@ jobs: - 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' }} + if: ${{ env.IS_ACT != 'true' }} uses: actions/upload-artifact@v4 with: name: jest-coverage @@ -67,28 +55,16 @@ jobs: 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: | @@ -109,28 +85,16 @@ jobs: with: fetch-depth: 0 - - 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 }} @@ -140,21 +104,44 @@ jobs: -H "Authorization: Bearer ${RENDER_API_KEY}" \ -d '' + notify: + name: 📢 Telegram Notification + runs-on: ubuntu-latest + needs: [test, release, deploy] + if: always() + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Send Telegram notification - if: always() run: | + if [ "${IS_ACT}" = "true" ]; then + TEST_RESULT="success" + RELEASE_RESULT="success" + DEPLOY_RESULT="success" + else + TEST_RESULT="${{ needs.test.result }}" + RELEASE_RESULT="${{ needs.release.result }}" + DEPLOY_RESULT="${{ needs.deploy.result }}" + fi + + STATUS="✅ *Pipeline completed successfully*" + if [ "$TEST_RESULT" != "success" ]; then + STATUS="❌ *Tests failed*" + elif [ "$RELEASE_RESULT" != "success" ]; then + STATUS="❌ *Release failed*" + elif [ "$DEPLOY_RESULT" != "success" ]; then + STATUS="❌ *Deploy failed*" + fi + VERSION=$(git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD) BRANCH=$(git rev-parse --abbrev-ref HEAD) COMMIT=$(git rev-parse --short HEAD) REPO_URL="https://github.com/$GITHUB_REPOSITORY" LAST_AUTHOR=$(git log -1 --pretty=format:'%an') - - if [ "${{ job.status }}" = "success" ]; then - STATUS="✅ *Deployment succeeded*" - else - STATUS="❌ *Deployment failed*" - fi - + MESSAGE="$STATUS 🕓 *Date:* $(date) 🏷️ *Version/Tag:* $VERSION @@ -162,8 +149,9 @@ jobs: 🔀 *Commit:* $COMMIT 👤 *Author:* $LAST_AUTHOR 🔗 *Repo:* $REPO_URL" - + curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \ -d "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \ -d "text=$MESSAGE" \ -d "parse_mode=Markdown" + \ No newline at end of file diff --git a/package.json b/package.json index fe22f6a..1dd165f 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,10 @@ "test:watch": "jest --watch", "lint": "eslint . --ext .js" }, + "repository": { + "type": "git", + "url": "https://github.com/cs-internship/CS-Queue-Bot.git" + }, "keywords": [ "telegram-bot", "cs-queue", From 405a8c90546663eb4c35ce93e187d92aa723f525 Mon Sep 17 00:00:00 2001 From: Ali Sadeghi Date: Fri, 17 Oct 2025 23:28:49 +0330 Subject: [PATCH 3/3] fix: add support for feature branches in CI pipeline --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb6c252..87c9b59 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - feature/** pull_request: branches: - main