-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (102 loc) · 3.17 KB
/
Copy pathci.yaml
File metadata and controls
116 lines (102 loc) · 3.17 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
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
permissions:
contents: read
pull-requests: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version: stable
cache: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
only-new-issues: true
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version: stable
cache: true
- name: Run tests
run: go test ./... -v -race -coverprofile=coverage.out
- name: Display coverage
run: go tool cover -func=coverage.out
- name: Check coverage threshold
run: |
coverage=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
threshold=70
if (( $(echo "$coverage < $threshold" | bc -l) )); then
echo "Coverage $coverage% is below threshold $threshold%"
exit 1
fi
echo "Coverage $coverage% meets threshold $threshold%"
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: [golangci, test]
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Collect Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
flavor: latest=false
images: ghcr.io/${{ github.repository }}
tags: |
# Tag as 'latest' only on main branch
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
# Tag as 'pr-123' for PRs (useful for local testing, won't be pushed to registry)
type=ref,event=pr
# Tag with short SHA
type=sha
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: amd64 ,arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and publish Docker image
uses: docker/build-push-action@v6
with:
context: .
# Push only on main branch or tags, skip push on PRs
push: ${{ github.event_name != 'pull_request' }}
platforms: ${{ github.event_name == 'pull_request' && 'linux/amd64' || 'linux/amd64,linux/arm64' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-to: type=gha,mode=max
cache-from: type=gha
build-args: |
BUILDKIT_INLINE_CACHE=1