-
Notifications
You must be signed in to change notification settings - Fork 0
187 lines (164 loc) · 5.39 KB
/
Copy pathpr.yaml
File metadata and controls
187 lines (164 loc) · 5.39 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: Unit Tests and Build Docker Image
on:
schedule:
- cron: '0 14 * * *'
pull_request:
branches:
- develop
- v*.*
push:
branches:
- develop
merge_group:
types: [checks_requested]
jobs:
build-and-test:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
image-tag: ${{ steps.meta.outcome == 'success' && fromJSON(steps.meta.outputs.json).tags[0] || '' }}
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 'stable'
- uses: actions/checkout@v6
with:
path: ./ibm-finops-agent
# Saves us from having to redownload all modules
- name: Go Mod cache
uses: actions/cache@v5
with:
path: |
~/.cache/go-build
~/go/pkg/mod
# The directory is important. We cover both OC and KCM with the
# ./kubecost/**/go.sum hash. Critically important because of the
# "replace" in KCM's go.mod
key: ${{ runner.os }}-go-${{ hashFiles('./ibm-finops-agent/**/go.sum') }}
- name: Test
working-directory: ./ibm-finops-agent
run: |
make test
- name: Lint
working-directory: ./ibm-finops-agent
run: |
make ci-lint
- name: get-pr-info
shell: bash
env:
PR_NUM: ${{ github.event.number }}
run: |
echo $PR_NUM > pr_num.txt
echo $GITHUB_BASE_REF > base.txt
echo $GITHUB_HEAD_REF > head.txt
mv ./ibm-finops-agent/coverage.out coverage.out
- name: save coverage file
uses: actions/upload-artifact@v4
with:
name: code-coverage
retention-days: 5
path: |
coverage.out
pr_num.txt
base.txt
head.txt
- name: Build Go binary
working-directory: ./ibm-finops-agent
run: |
go build -o ibm-finops-agent ./cmd/finops-agent/main.go
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}/ibm-finops-agent
tags: |
type=sha,prefix=pr-
type=ref,event=pr
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and Push Docker image
uses: docker/build-push-action@v5
with:
context: ./ibm-finops-agent
file: ./ibm-finops-agent/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
DUCK_VERSION=v0.9.2
version=${{ steps.meta.outputs.version }}
commit=${{ github.sha }}
e2e-test:
needs: build-and-test
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
strategy:
fail-fast: false
matrix:
k8s-version: ['v1.34.0', 'v1.33.0', 'v1.32.0', 'v1.31.0']
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 'stable'
- uses: actions/checkout@v6
with:
path: ./ibm-finops-agent
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull Docker image
run: docker pull ${{ needs.build-and-test.outputs.image-tag }}
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: 3.18.4
- name: E2E testing for ${{ matrix.k8s-version }}
working-directory: ./ibm-finops-agent
run: |
helm repo add ibm-finops https://kubecost.github.io/finops-agent-chart
helm repo add localstack https://helm.localstack.cloud
KUBERNETES_VERSION=${{ matrix.k8s-version }} IMAGE=${{ needs.build-and-test.outputs.image-tag }} TEMP_DIR=$(mktemp -d) e2e/e2e.sh
set-labels:
needs: [build-and-test, e2e-test]
runs-on: ubuntu-latest
# Run this job even if tests fail (to label the PR accordingly)
# Skip only if workflow was manually cancelled or not a PR
if: always() && !cancelled() && github.event_name == 'pull_request'
permissions:
pull-requests: write
steps:
- name: Label based on test results
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
gh pr edit "$PR_NUMBER" --repo "$REPO" \
--add-label "unit tests failed" \
--remove-label "unit tests passed"
else
gh pr edit "$PR_NUMBER" --repo "$REPO" \
--add-label "unit tests passed" \
--remove-label "unit tests failed"
fi