This repository has been archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (131 loc) · 4.32 KB
/
ci.yml
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
name: kubernetes-svc-dependencies
on:
push:
branches:
- '*'
tags:
- v*
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
runs-on: ubuntu-latest
env:
REGISTRY: ${{ secrets.REGISTRY }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache vendor
uses: actions/cache@v2
env:
cache-name: cache-vendor
with:
path: vendor
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('go.mod') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
- name: Prepare
id: prep
run: |
TAG=pr
if [[ $GITHUB_REF == refs/tags/v* ]]; then
TAG=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
TAG=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
fi
echo ::set-output name=tag::${TAG}
echo "Build with tag=${TAG}"
- name: Setup Go environment
uses: actions/setup-go@v2.1.3
with:
go-version: 1.18
- name: Build binary
shell: bash
run:
make -e REGISTRY=$REGISTRY -e TAG="${{ steps.prep.outputs.tag }}" build-in-docker
# Directory created with a docker run having user root
- name: Fix directory owner
shell: bash
run: sudo chown -R $USER out vendor
- name: Output
if: startsWith(github.ref, 'refs/tags/v')
uses: actions/upload-artifact@v2.2.3
with:
name: binaries
path: out
if-no-files-found: error
sonarcloud:
if: startsWith(github.ref, 'refs/heads/')
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# Directory created with a docker run having user root
- name: Prepare SonarCloud
shell: bash
run: sudo chown -R $USER .scannerwork
deploy:
if: startsWith(github.ref, 'refs/tags/v')
needs: build
runs-on: ubuntu-latest
env:
REGISTRY: ${{ secrets.REGISTRY }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Prepare
id: prep
run: |
TAG=pr
if [[ $GITHUB_REF == refs/tags/v* ]]; then
TAG=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
TAG=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
fi
echo ::set-output name=tag::${TAG}
echo "Build with tag=${TAG}"
# echo ::set-env name=RELEASE_VERSION::${TAG}
- name: Setup Go environment
uses: actions/setup-go@v2.1.3
with:
go-version: 1.16
- name: Setup docker buildx
uses: docker/setup-buildx-action@v1.3.0
- name: Download binaries
uses: actions/download-artifact@v2
with:
name: binaries
path: out
- name: Prepare docker buildx
shell: bash
run: |
docker buildx version;
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin;
docker buildx create --use
- name: Build docker image
shell: bash
run: |
make -e REGISTRY=$REGISTRY -e TAG="${{ steps.prep.outputs.tag }}" push-manifest
- name: Prepare Release
shell: bash
run: |
cp out/linux/amd64/kubernetes-svc-dependencies kubernetes-svc-dependencies-amd64
cp out/linux/arm64/kubernetes-svc-dependencies kubernetes-svc-dependencies-arm64
- name: Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.prep.outputs.tag }}
# release_name: Release ${{ steps.prep.outputs.tag }}
draft: false
files: |
kubernetes-svc-dependencies-amd64
kubernetes-svc-dependencies-arm64
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # You don't need to add this in secrets it's by default.