-
Notifications
You must be signed in to change notification settings - Fork 0
73 lines (64 loc) · 2.45 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: CI
on:
push:
branches:
- "**"
jobs:
eslint:
name: Eslint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "18.x"
cache: "yarn"
- run: yarn install
- run: npx eslint .
prettier:
name: Prettier
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "18.x"
cache: "yarn"
- run: yarn install
- run: npx prettier --check .
tests:
name: Run unit tests
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "18.x"
cache: "yarn"
- run: yarn install
- run: yarn test
notification:
name: Slack notification
runs-on: ubuntu-latest
if: ${{ always() && github.actor != 'dependabot[bot]' }}
needs: [eslint, prettier, tests]
steps:
- name: Send notification
run: |
webhookUrl="${{ secrets.SLACK_WEBHOOK_URL }}"
successText=":octocat: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Build #${{ github.run_number }}> of *${{ github.repository }}@${{ github.ref_name }}* by *${{ github.actor }}* completed successfully."
failureText=":octocat: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Build #${{ github.run_number }}> of *${{ github.repository }}@${{ github.ref_name }}* by *${{ github.actor }}* failed."
cancelledText=":octocat: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Build #${{ github.run_number }}> of *${{ github.repository }}@${{ github.ref_name }}* by *${{ github.actor }}* was cancelled.😥"
status="${{ (contains(needs.*.result, 'cancelled') && 'cancelled') || (contains(needs.*.result, 'failure') && 'failure') || 'success' }}"
if [ "$status" = 'success' ]; then
color='good'
text=$successText
elif [ "$status" = 'failure' ]; then
color='danger'
text=$failureText
elif [ "$status" = "cancelled" ]; then
color='warning'
text=$cancelledText
fi
curl "$webhookUrl" -X "POST" --header "Content-Type: application/json" \
--data "{attachments: [{text: \"$text\", color: \"$color\"}]}"