-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (154 loc) · 5.51 KB
/
release.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
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
name: Publish new release
on:
push:
branches: [ main ]
tags:
- '*'
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: true
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
# Optional: golangci-lint command line arguments.
args: --issues-exit-code=1 --timeout=5m --disable typecheck
- name: go vet
run: go vet ./...
scan-code:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
scanners: 'vuln,secret,config'
ignore-unfixed: true
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
# exit-code: '1'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'
category: 'code'
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
with:
path: ./.cache # Note that this path is not influenced by working-directory set in defaults, for example
key: multena-rbac-collector-${{ github.run_id }}
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: true
- name: Install dependencies
run: go get .
- name: Build
run: CGO_ENABLED=0 GOOS=linux go build -ldflags="-X github.com/gepaplexx/multena-rbac-collector/cmd.Commit=$(git rev-parse HEAD)" -o . -v ./...
- name: Change permissions
run: |
sudo chgrp -R 0 multena-rbac-collector
sudo chmod -R g=u multena-rbac-collector
- name: Copy build
run: mkdir ./.cache && cp ./multena-rbac-collector ./.cache/multena-rbac-collector
- name: Test
run: go test -v ./...
push:
needs: [ build-and-test, scan-code, lint ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
with:
path: ./.cache # Note that this path is not influenced by working-directory set in defaults, for example
key: multena-rbac-collector-${{ github.run_id }}
fail-on-cache-miss: true
- name: move from cache
run: mv ./.cache/multena-rbac-collector ./multena-rbac-collector
- name: Set image name
run: echo "IMAGE_ID=$(echo ${{ github.repository }} | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV
- name: Get tag version
id: tag_version
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
DRY_RUN: true
DEFAULT_BUMP: patch
VERBOSE: true
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/${{ env.IMAGE_ID }}
tags: |
type=schedule
type=ref,event=branch
type=raw,value=${{ github.head_ref }}-${{ steps.tag_version.outputs.new_tag }}, enable=${{ github.ref != 'refs/heads/main' }}
type=raw,value=${{ github.head_ref }}-${{ steps.tag_version.outputs.new_tag }}-${{github.sha}}, enable=${{ github.ref != 'refs/heads/main' }}
type=raw,value=${{github.sha}}
type=semver,pattern={{version}},value=${{ steps.tag_version.outputs.new_tag }},enable={{is_default_branch}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Buildah Action
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.IMAGE_NAME }}
tags: ${{ steps.meta.outputs.tags }}
containerfiles: |
./build/Containerfile
- name: Log in to the GitHub Container registry
uses: redhat-actions/podman-login@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: push image to trivy
run: |
buildah push ${{ steps.build-image.outputs.image-with-tag }} oci:./multena-rbac-collector-oci
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
input: 'multena-rbac-collector-oci'
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'
category: 'container'
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
- name: Push to GitHub Container Repository
id: push-to-ghcr
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: ${{ env.REGISTRY }}
- name: Get tag version
if: ${{ github.event_name != 'pull_request' }}
id: tag_version_final
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
DEFAULT_BUMP: patch