-
Notifications
You must be signed in to change notification settings - Fork 8
146 lines (121 loc) · 4.14 KB
/
main.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: main
on:
pull_request:
push:
branches:
- 'main'
env:
go-version: "1.20"
filename: 'main.yaml'
jobs:
unit-test:
name: Unit Test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup golang
uses: actions/setup-go@v3
with:
go-version: ${{ env.go-version }}
- name: Start etcd container
run: docker run -d --network host gcr.io/etcd-development/etcd:v3.5.7
- name: Install test tools
run: make SUDO="sudo" test-tools
- name: Check auto-generated files
run: make check-generate
- name: Run code check tools
run: make code-check
- name: Build binaries
run: make build
- name: Run test
run: make test
e2e-test:
name: e2e Test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup golang
uses: actions/setup-go@v3
with:
go-version: ${{ env.go-version }}
- name: Install test tools
run: make SUDO="sudo" test-tools
- name: Check auto-generated files
run: make check-generate
- name: Run code check tools
run: make code-check
- name: Build binaries
run: make build
- name: Run test
run: make e2e
mtest:
name: Multi-host test
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup golang
uses: actions/setup-go@v3
with:
go-version: ${{ env.go-version }}
- id: auth
uses: google-github-actions/auth@v1
with:
credentials_json: '${{ secrets.NECO_TEST_SERVICE_ACCOUNT }}'
- name: Set up Cloud SDK for sabakan
uses: google-github-actions/setup-gcloud@v1
- name: Set GCP instance name
run: echo "INSTANCE_NAME=sabakan-${{ github.run_number }}-$(TZ=Asia/Tokyo date +%H%M%S)" >> $GITHUB_ENV
- name: Watch sabakan logs
run: ./bin/watch_service sabakan > sabakan-service.log &
- name: Run mtest
run: |
if [ ${{ github.event_name }} = "pull_request" ]; then
GITHUB_SHA=$(cat ${GITHUB_EVENT_PATH} | jq -r '.pull_request.head.sha')
fi
./bin/run-mtest.sh
- name: Show sabakan logs
if: ${{ always() }}
run: cat sabakan-service.log
- name: Set the GCP instance lifetime
if: ${{ failure() || cancelled() }}
run: |
. ./bin/env
$GCLOUD compute instances add-metadata ${INSTANCE_NAME} --zone ${ZONE} \
--metadata shutdown-at=$(date -Iseconds -d+30minutes)
- name: Notify to Slack if failed or cancelled
if: ${{ failure() || cancelled() }}
run: |
. ./bin/env
if [[ ${{ github.event_name }} == 'pull_request' ]]; then
BRANCH_NAME=${GITHUB_HEAD_REF}
else
BRANCH_NAME=${GITHUB_REF#refs/heads/}
fi
curl -X POST -H 'Content-type: application/json' --data "{
\"blocks\": [
{
\"type\": \"section\",
\"text\": {
\"type\": \"mrkdwn\",
\"text\": \"Failed: ${{ github.actor }}'s workflow (${{ github.workflow }}) in <https://github.com/${{ github.repository }}/actions/workflows/${{ env.filename }}|${{ github.repository }}> (<https://github.com/${{ github.repository }}/actions/workflows/${{ env.filename }}?query=branch%3A${BRANCH_NAME}|${BRANCH_NAME}>) \n Do you extend the lifetime of ${INSTANCE_NAME}?\"
},
\"accessory\": {
\"type\": \"button\",
\"text\": {
\"type\": \"plain_text\",
\"text\": \"Extend\",
\"emoji\": true
},
\"value\": \"${INSTANCE_NAME}\"
}
}
]
}" ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Delete CI instance if succeeded
if: ${{ success() }}
run: |
. ./bin/env
$GCLOUD compute instances delete ${INSTANCE_NAME} --zone ${ZONE}