-
Notifications
You must be signed in to change notification settings - Fork 14
117 lines (94 loc) · 3.49 KB
/
build.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
name: build
on:
push:
branches: [ master, dev ]
pull_request:
branches: [ master, dev ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
- name: setup go
uses: actions/setup-go@v4
with:
go-version: '1.20.x'
cache: true
- name: Get branch name (merge)
if: github.event_name != 'pull_request'
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV
- name: Get branch name (pull request)
if: github.event_name == 'pull_request'
run: |
git fetch -a
echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF} | tr / -)" >> $GITHUB_ENV
- name: Build binary
run: |
make build
- name: Running ElasticSearch
run: |
docker run -itd --name elasticsearch -p 9200:9200 -e "discovery.type=single-node" -e "xpack.security.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:8.3.3
sleep 20
timeout 120 sh -c 'until nc -z $0 $1; do echo "waiting for elasticsearch to start on port 9200"; sleep 5; done' localhost 9200
- name: run test
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
run: |
echo "
go 1.20
use (
.
./api
./pkg/logger
./pkg/opa-core
./pkg/policy-core
./pkg/uuid-go
)" >> go.work
make test
bash <(curl -s https://codecov.io/bash) -F unit
- name: Build docker image
run: |
COMMIT_COUNT=$(git rev-list --count HEAD)
SHORT_HASH=$(git rev-parse --short HEAD)
VERSION=${{ env.BRANCH_NAME }}-${COMMIT_COUNT}-${SHORT_HASH}
if [[ ${{ env.BRANCH_NAME }} == "master" ]]; then
export VERSION=master
fi
if [[ ${{ env.BRANCH_NAME }} == "dev" ]]; then
export VERSION=dev
fi
make image VERSION=$VERSION
- name: Scan The Image
run: |
REPO=policy-agent
COMMIT_COUNT=$(git rev-list --count HEAD)
SHORT_HASH=$(git rev-parse --short HEAD)
VERSION=${{ env.BRANCH_NAME }}-${COMMIT_COUNT}-${SHORT_HASH}
if [[ ${{ env.BRANCH_NAME }} == "master" ]]; then
export VERSION=master
fi
if [[ ${{ env.BRANCH_NAME }} == "dev" ]]; then
export VERSION=dev
fi
echo scanning ${REPO}:${VERSION}
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sudo sh -s -- -b /usr/local/bin
grype "${REPO}:${VERSION}" --scope all-layers > /tmp/report.txt #--fail-on high to fail on sev high
- name: Login to Docker Hub
if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/master'
uses: docker/login-action@v1
with:
registry: docker.io
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Create image and push to Docker Registry
if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/master'
run: |
if [[ ${{ env.BRANCH_NAME }} == "master" ]]; then
export VERSION=master
fi
if [[ ${{ env.BRANCH_NAME }} == "dev" ]]; then
export VERSION=dev
fi
make push@weaveworks tag-file=new-tag version-file=new-version VERSION=$VERSION