Skip to content

Commit 8f171b2

Browse files
Feature/reusable workflow (#13)
* reusable workflow for Slack notifications
1 parent daa3257 commit 8f171b2

File tree

4 files changed

+90
-26
lines changed

4 files changed

+90
-26
lines changed

.github/workflows/auto-simple-suite-reusable.yaml

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,17 @@ jobs:
2828
retention-days: 7
2929

3030
post-slack-notification-started:
31-
runs-on: ubuntu-latest
32-
steps:
33-
- name: Post a start message in a Slack channel
34-
env:
35-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
36-
run: |
37-
curl -X POST -H 'Content-type: application/json' \
38-
--data '{"text":"The simple suite pipeline started"}' \
39-
$SLACK_WEBHOOK_URL
31+
uses: ./.github/workflows/slack-notification.yaml
32+
with:
33+
job_status: started
34+
secrets:
35+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
4036

4137
post-slack-notification-results:
42-
runs-on: ubuntu-latest
43-
needs: run-simple-suite
38+
needs: run-simple-suite
4439
if: always()
45-
steps:
46-
- name: Post a result message in a Slack channel
47-
env:
48-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
49-
run: |
50-
if [ "${{ needs.run-simple-suite.result }}" == "success" ]; then
51-
MESSAGE="The simple suite pipeline succeeded"
52-
elif [ "${{ needs.run-simple-suite.result }}" == "failure" ]; then
53-
MESSAGE="The simple suite pipeline failed"
54-
fi
55-
56-
curl -X POST -H 'Content-type: application/json' \
57-
--data "{\"text\":\"$MESSAGE\"}" \
58-
$SLACK_WEBHOOK_URL
40+
uses: ./.github/workflows/slack-notification.yaml
41+
with:
42+
job_status: ${{ needs.run-simple-suite.result }}
43+
secrets:
44+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Run P0 tests
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
8+
jobs:
9+
run-p0-tests:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Node.js and Playwright
16+
uses: ./.github/actions/setup-playwright
17+
18+
- name: Run P0 tests
19+
run: yarn playwright test --project=chromium --grep @p0
20+
21+
- name: Upload test results
22+
if: ${{ !cancelled() }}
23+
uses: actions/upload-artifact@v4
24+
with:
25+
name: p0-tests-results-${{ github.run_id }}
26+
path: playwright-report/
27+
retention-days: 7
28+
29+
post-slack-notification-started:
30+
uses: ./.github/workflows/slack-notification.yaml
31+
with:
32+
job_status: started
33+
secrets:
34+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
35+
36+
post-slack-notification-results:
37+
needs: run-p0-tests
38+
if: always()
39+
uses: ./.github/workflows/slack-notification.yaml
40+
with:
41+
job_status: ${{ needs.run-p0-tests.result }}
42+
secrets:
43+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Slack Notification
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
job_status:
7+
description: 'Status: started, success, failure, cancelled, skipped'
8+
required: true
9+
type: string
10+
secrets:
11+
SLACK_WEBHOOK_URL:
12+
required: true
13+
14+
jobs:
15+
send-notification:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Post message to Slack
19+
env:
20+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
21+
run: |
22+
PIPELINE_NAME="${{ github.workflow }}"
23+
24+
case "${{ inputs.job_status }}" in
25+
"started") MESSAGE="🚀 $PIPELINE_NAME started" ;;
26+
"success") MESSAGE="✅ $PIPELINE_NAME succeeded" ;;
27+
"failure") MESSAGE="❌ $PIPELINE_NAME failed" ;;
28+
"cancelled") MESSAGE="🚫 $PIPELINE_NAME was cancelled" ;;
29+
"skipped") MESSAGE="⏭️ $PIPELINE_NAME was skipped" ;;
30+
*) MESSAGE="⚠️ $PIPELINE_NAME - status: ${{ inputs.job_status }}" ;;
31+
esac
32+
33+
curl -X POST -H 'Content-type: application/json' \
34+
--data "{\"text\":\"$MESSAGE\"}" \
35+
$SLACK_WEBHOOK_URL

tests/example.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test, expect } from '@playwright/test';
22

3-
test('has title', { tag: ['@smoke'] }, async ({ page }) => {
3+
test('has title', { tag: ['@smoke', '@p0'] }, async ({ page }) => {
44
await page.goto('https://playwright.dev/');
55

66
// Expect a title "to contain" a substring.

0 commit comments

Comments
 (0)