-
Notifications
You must be signed in to change notification settings - Fork 6
121 lines (117 loc) · 4.13 KB
/
ci.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
name: CI
on:
push:
branches:
- main
- release-*
pull_request: {}
workflow_dispatch: {}
jobs:
golangci-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
- uses: golangci/golangci-lint-action@v3
with:
args: --verbose
version: v1.47.3
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-ut-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-ut-
- name: Check Go modules
run: |
go mod tidy && git add go.* &&
git diff --cached --exit-code || (echo 'Please run "go mod tidy" to sync Go modules' && exit 1);
- name: Check manifests
run: |
make manifests && git add config &&
git diff --cached --exit-code || (echo 'Please run "make manifests" to generate manifests' && exit 1);
- name: Check auto-generated codes
run: |
make generate && git add pkg apis &&
git diff --cached --exit-code || (echo 'Please run "make generate" to generate Go codes' && exit 1);
- name: Verify gofmt
run: |
make fmt && git add apis pkg cmd &&
git diff --cached --exit-code || (echo 'Please run "make fmt" to verify gofmt' && exit 1);
- name: Verify govet
run: |
make vet && git add apis pkg cmd &&
git diff --cached --exit-code || (echo 'Please run "make vet" to verify govet' && exit 1);
- name: Run Go build
run: make build
- name: Run Go test
run: make fast-test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
flags: unittests
file: cover.out
fail_ci_if_error: true
verbose: true
build-and-push:
needs: [golangci-lint, unit-tests]
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: [interference-manager]
env:
GITHUB_REG: ghcr.io
ALIYUN_BJ_REG: registry.cn-beijing.aliyuncs.com
ALIYUN_HZ_REG: registry.cn-hangzhou.aliyuncs.com
steps:
- uses: docker/setup-buildx-action@v2
- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ${{ env.GITHUB_REG }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to AliyunCS_BJ
uses: docker/login-action@v2
with:
registry: ${{ env.ALIYUN_BJ_REG }}
username: ${{ secrets.ALIYUN_USERNAME }}
password: ${{ secrets.ALIYUN_PWD }}
- name: Login to AliyunCS_HZ
uses: docker/login-action@v2
with:
registry: ${{ env.ALIYUN_HZ_REG }}
username: ${{ secrets.ALIYUN_USERNAME }}
password: ${{ secrets.ALIYUN_PWD }}
- name: Build and push
uses: docker/build-push-action@v4
with:
platforms: linux/amd64
push: true
pull: true
file: docker/${{ matrix.target }}.dockerfile
labels: |
org.opencontainers.image.title=${{ matrix.target }}
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ github.event.repository.updated_at}}
org.opencontainers.image.licenses=Apache-2.0
tags: |
${{ env.GITHUB_REG }}/${{ github.repository_owner }}/${{ matrix.target }}:latest
${{ env.ALIYUN_BJ_REG }}/${{ github.repository_owner }}/${{ matrix.target }}:latest
${{ env.ALIYUN_HZ_REG }}/${{ github.repository_owner }}/${{ matrix.target }}:latest
cache-from: type=gha,scope=build-${{ matrix.target }}
cache-to: type=gha,mode=max,scope=build-${{ matrix.target }}