forked from koordinator-sh/koordinator
-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (147 loc) · 5.98 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
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
147
148
149
150
151
name: CI
on:
push:
branches:
- main
- release-*
pull_request: { }
workflow_dispatch: { }
jobs:
golangci-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
cache: false
go-version-file: go.mod
- run: sudo apt update && sudo apt install -y libpfm4 libpfm4-dev
- uses: golangci/golangci-lint-action@v3
with:
version: v1.47.3
unit-tests:
strategy:
fail-fast: false
matrix:
include:
- step: mod
name: Check Go modules
command: go mod tidy && git add go.* && git diff --cached --exit-code || (echo 'Please run "go mod tidy" to sync Go modules' && exit 1);
- step: manifests
name: Check manifests
command: make manifests && git add config && git diff --cached --exit-code || (echo 'Please run "make manifests" to generate manifests' && exit 1);
- step: generate
name: Check auto-generated codes
command: make generate && git add pkg apis && git diff --cached --exit-code || (echo 'Please run "make generate" to generate Go codes' && exit 1);
- step: gofmt
name: Verify gofmt
command: make fmt && git add apis pkg cmd && git diff --cached --exit-code || (echo 'Please run "make fmt" to verify gofmt' && exit 1);
- step: govet
name: Verify govet
command: make vet && git add apis pkg cmd && git diff --cached --exit-code || (echo 'Please run "make vet" to verify govet' && exit 1);
- step: build
name: Run Go build
command: make build
- step: test
name: Run Go test
command: make fast-test
name: unit-tests(${{ matrix.name }})
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
cache: false
go-version-file: go.mod
- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-ut-${{ matrix.step }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-ut-${{ matrix.step }}-
- name: ${{ matrix.name }}
run: |
sudo apt update && sudo apt install -y libpfm4 libpfm4-dev
${{ matrix.command }}
- if: matrix.step == 'test'
name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
flags: unittests
file: cover.out
fail_ci_if_error: true
build-and-push:
needs: [ golangci-lint, unit-tests ]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: [ koordlet, koord-manager, koord-scheduler, koord-descheduler ]
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@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.GITHUB_REG }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build the image
uses: docker/build-push-action@v5
with:
platforms: linux/amd64
push: false
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 }}:${{ github.sha }}
cache-from: type=gha,scope=build-${{ matrix.target }}
cache-to: type=gha,mode=max,scope=build-${{ matrix.target }}
- if: github.ref == 'refs/heads/main'
name: Login to AliyunCS_BJ
uses: docker/login-action@v3
with:
registry: ${{ env.ALIYUN_BJ_REG }}
username: ${{ secrets.ALIYUN_USERNAME }}
password: ${{ secrets.ALIYUN_PWD }}
- if: github.ref == 'refs/heads/main'
name: Login to AliyunCS_HZ
uses: docker/login-action@v3
with:
registry: ${{ env.ALIYUN_HZ_REG }}
username: ${{ secrets.ALIYUN_USERNAME }}
password: ${{ secrets.ALIYUN_PWD }}
- if: github.ref == 'refs/heads/main'
name: Build and push the multi-arch images
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
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.GITHUB_REG }}/${{ github.repository_owner }}/${{ matrix.target }}:${{ github.sha }}
${{ env.ALIYUN_BJ_REG }}/${{ github.repository_owner }}/${{ matrix.target }}:latest
${{ env.ALIYUN_BJ_REG }}/${{ github.repository_owner }}/${{ matrix.target }}:${{ github.sha }}
${{ env.ALIYUN_HZ_REG }}/${{ github.repository_owner }}/${{ matrix.target }}:latest
${{ env.ALIYUN_HZ_REG }}/${{ github.repository_owner }}/${{ matrix.target }}:${{ github.sha }}
cache-from: type=gha,scope=build-${{ matrix.target }}
cache-to: type=gha,mode=max,scope=build-${{ matrix.target }}