Skip to content

Commit

Permalink
feature(ci): simpler json webhook to discord (onejs#10)
Browse files Browse the repository at this point in the history
* feature(ci): simpler json webhook to discord

* ci(workflows): optimize GitHub Actions workflow

- Modified checks.yml to prevent redundant runs of checks and tests

Implementation reason: This change improves the efficiency of the CI pipeline by avoiding duplicate executions of checks and tests when both a pull request and a commit are made simultaneously. This optimization reduces unnecessary resource usage and speeds up the overall development process.

- File changed: .github/workflows/checks.yml
  • Loading branch information
jonsherrard authored Sep 25, 2024
1 parent 67f64d0 commit f2320a9
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
name: Checks
name: Checks and Tests

on: [pull_request, push]
on:
push:
branches: [main] # Adjust this to your main branch name
pull_request:
branches: [main] # Adjust this to your main branch name

jobs:
checks:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -20,6 +25,7 @@ jobs:

tests:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -32,16 +38,22 @@ jobs:

- name: Build vxrn
run: cd packages/vxrn && yarn build

- name: Test
run: yarn test

notify:
needs: [checks, tests]
runs-on: ubuntu-latest
if: failure()
steps:
- name: Notify Discord on failure
if: failure()
run: |
echo "Tests failed, sending message to Discord..."
echo "Checks or tests failed, sending message to Discord..."
curl -H "Content-Type: application/json" \
-X POST \
-d "$(echo '{}' | jq --arg content "🚨 Tests failed for commit [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) in [${{ github.repository }}](https://github.com/${{ github.repository }})." \
--arg url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
'{ "embeds": [ { "title": $content, "url": $url, "color": 15158332 } ] }')" \
-d '{
"content": "🚨 Checks or tests failed for commit `${{ github.sha }}` in [${{ github.repository }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}).\nSee the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})."
}' \
${{ secrets.DISCORD_WEBHOOK_URL }}

0 comments on commit f2320a9

Please sign in to comment.