Skip to content

Update README.md

Update README.md #1

name: Notify Discord
on:
push:
branches:
- '**'
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
- name: Install dependencies
run: npm install
- name: Run tests and coverage
id: run_tests
run: |
set -e
npm run coverage:frontend > frontend_coverage.log
npm run coverage:backend > backend_coverage.log
FRONTEND_COVERAGE=$(grep "All files" frontend_coverage.log | awk '{print $4}')
BACKEND_COVERAGE=$(grep "All files" backend_coverage.log | awk '{print $4}')
echo "FRONTEND_COVERAGE=$FRONTEND_COVERAGE" >> $GITHUB_ENV
echo "BACKEND_COVERAGE=$BACKEND_COVERAGE" >> $GITHUB_ENV
- name: Get commit message
id: get_commit_message
run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=format:'%s')" >> $GITHUB_ENV
- name: Get committer name
id: get_committer_name
run: echo "COMMITTER_NAME=$(git log -1 --pretty=format:'%cn')" >> $GITHUB_ENV
- name: Send notification to Discord
if: success()
run: |
curl -H "Content-Type: application/json" \
-X POST \
-d "{\"content\": \"New commit in the repository: https://github.com/${{ github.repository }}/commit/${{ github.sha }}\nBranch: ${{ github.ref }}\nCommit Message: ${{ env.COMMIT_MESSAGE }}\nPushed by: ${{ env.COMMITTER_NAME }}\n✅ Tests passed\n- **Frontend Coverage**: ${{ env.FRONTEND_COVERAGE }}%\n- **Backend Coverage**: ${{ env.BACKEND_COVERAGE }}%\"}" \
https://discord.com/api/webhooks/1242309341743415397/X0_-KdpBWi2dmjxv-wW5n4wntguXxl_DDWt0XuUt4lbN1Vef_klmZQVFoOpoZhZgU2IT
- name: Send notification to Discord on Failure
if: failure()
run: |
curl -H "Content-Type: application/json" \
-X POST \
-d "{\"content\": \"New commit in the repository: https://github.com/${{ github.repository }}/commit/${{ github.sha }}\nBranch: ${{ github.ref }}\nCommit Message: ${{ env.COMMIT_MESSAGE }}\nPushed by: ${{ env.COMMITTER_NAME }}\n❌ Tests failed\"}" \
https://discord.com/api/webhooks/1242309341743415397/X0_-KdpBWi2dmjxv-wW5n4wntguXxl_DDWt0XuUt4lbN1Vef_klmZQVFoOpoZhZgU2IT