forked from doitintl/kubeip
-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (117 loc) · 3.81 KB
/
build.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
name: build
on:
workflow_dispatch:
push:
branches:
- 'master'
# tags:
# - '*'
# paths-ignore:
# - 'docs/**'
# - 'deploy/**'
# - '*.md'
# - '*.yaml'
# - '*.sh'
# pull_request:
# branches:
# - '*'
permissions:
packages: write
contents: read
jobs:
validate:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message,'[skip ci]') }}
container: golang:1.21-alpine
steps:
- name: checkout
uses: actions/checkout@v4
- name: test
shell: sh
env:
CGO_ENABLED: 0
run: |
apk --update add ca-certificates tzdata make git bash
make lint
make test-json
- name: upload test results
uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: test-reports
if-no-files-found: ignore
path: |
golangci-lint.out
test-report.out
coverage.out
# - name: SonarCloud scan
# uses: SonarSource/sonarcloud-github-action@master
# if: ${{ always() }}
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
docker-build:
runs-on: ubuntu-latest
needs: validate
# build only on master branch and tags
if: ${{
!contains(github.event.head_commit.message, '[skip ci]') &&
(
(github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))) ||
(github.event_name == 'pull_request' && github.event.pull_request.draft == false)
)
}}
steps:
- name: checkout
uses: actions/checkout@v4
- name: get short sha
id: short_sha
run: echo ::set-output name=sha::$(git rev-parse --short HEAD)
- name: get version
id: version
run: echo ::set-output name=version::$([[ -z "${{ github.event.pull_request.number }}" ]] && echo "sha-${{ steps.short_sha.outputs.sha }}" || echo "pr-${{ github.event.pull_request.number }}")
- name: set up QEMU
uses: docker/setup-qemu-action@v3
- name: set up Docker buildx
id: buildx
uses: docker/setup-buildx-action@v3
# - name: login to DockerHub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
- id: login
name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: prepare meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}/agent
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
labels: |
github.run.id=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
org.opencontainers.image.title=kubeip-agent
org.opencontainers.image.description=kubeip agent
org.opencontainers.image.vendor=DoiT International
- name: build and push
uses: docker/build-push-action@v5
with:
build-args: |
VERSION=${{ steps.version.outputs.version }}
COMMIT=${{ steps.short_sha.outputs.sha }}
BRANCH=${{ github.ref_name }}
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}