-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (117 loc) · 4 KB
/
build.yaml
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: Build & Test
on: [ push ]
jobs:
tests:
name: Build & Test on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest ]
go-version: [ 1.19.x ]
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Get dependencies
run: go get -v -t -d ./...
- name: Build project
run: go build ./...
- name: Run tests
run: go test ./...
- name: Prepare Results
id: results
if: always()
shell: bash
env:
FULL_REVISION: ${{ github.event.after }}
run: |
echo "rev=${FULL_REVISION:0:8}" >> $GITHUB_OUTPUT
echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
echo "os=$(uname -sr)" >> $GITHUB_OUTPUT
echo "go_version=$(go version | cut -d " " -f 3-)" >> $GITHUB_OUTPUT
if [[ "${{ job.status }}" == "success" ]]; then
echo "status=:moneybag: SUCCESS" >> $GITHUB_OUTPUT
else
echo "status=:hankey: FAILURE" >> $GITHUB_OUTPUT
fi
- name: Post to Slack
id: slack
if: always()
uses: slackapi/slack-github-action@v1.24.0
with:
# Slack channel id, channel name, or user id to post message.
# See also: https://api.slack.com/methods/chat.postMessage#channels
channel-id: '${{ secrets.SLACK_CHANNEL }}'
# For posting a rich message using Block Kit
payload: |
{
"text": "GitHub Action build result: ${{ job.status }}\n${{ github.event.head_commit.url }}",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "${{ steps.results.outputs.status }}"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Repository:* `${{ github.repository }}`"
},
{
"type": "mrkdwn",
"text": "*Branch:* `${{ steps.results.outputs.branch }}`"
},
{
"type": "mrkdwn",
"text": "*Revision:* `${{ steps.results.outputs.rev }}`"
},
{
"type": "mrkdwn",
"text": "*Committer:* `${{ github.actor }}`"
},
{
"type": "mrkdwn",
"text": "*Go Version:* `${{ steps.results.outputs.go_version }}`"
},
{
"type": "mrkdwn",
"text": "*OS:* `${{ steps.results.outputs.os }}`"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Build log",
"emoji": true
},
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Commit Details",
"emoji": true
},
"url": "${{ github.event.head_commit.url }}"
}
]
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}