-
Notifications
You must be signed in to change notification settings - Fork 7
130 lines (111 loc) · 3.72 KB
/
ci-build.yml
File metadata and controls
130 lines (111 loc) · 3.72 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: CI Build App
on:
workflow_dispatch:
push:
branches: [main]
paths:
- "cmd/**"
- "web/**"
- ".github/workflows/**"
pull_request:
branches: [main]
permissions:
contents: read
packages: write
checks: write
env:
VERSION: 0.8.6
BUILD_INFO: "Build:development / Workflow:${{ github.workflow }} / RunId:${{ github.run_id }} / Ref:${{ github.ref }} / SHA:${{ github.sha }} / ImageTag:${{ github.run_id }}"
IMAGE_REG: ghcr.io
IMAGE_TAG: ${{ github.run_id }}
jobs:
# ===== Testing & code checking ======
tests-linting:
name: "Run Lint & All Tests"
runs-on: ubuntu-latest
outputs:
imageTag: ${{ steps.createTag.outputs.IMAGE_TAG }}
steps:
- name: "Checkout source"
uses: actions/checkout@v4
- name: "Set Go version and paths"
uses: actions/setup-go@v5
with:
go-version: "^1.24.0"
- name: "Install extra Go tools"
run: |
go install github.com/jstemmer/go-junit-report@latest
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
- name: "Check code & lint"
run: |
go get ./...
make lint
- name: "Run all unit tests and generate reports"
run: |
make test-report
- name: "Test Report (Frontend)"
uses: phoenix-actions/test-reporting@v15
if: success() || failure()
with:
name: Frontend Tests
path: test-reports/frontend.xml
reporter: java-junit
- name: "Test Report (Unit Tests)"
uses: phoenix-actions/test-reporting@v15
if: success() || failure()
with:
name: Unit Tests
path: test-reports/unit.xml
reporter: java-junit
- name: "Dapr tool installer"
uses: dapr/setup-dapr@v1
with:
version: "1.15.1"
- name: "Initialize Dapr"
run: |
dapr init
- name: "Run API integration tests, with report"
run: |
make run &
for i in {1..60}; do
if curl -s http://localhost:8080/health | grep "healthy" > /dev/null; then
echo "Service is ready!"
break
fi
echo "Waiting for service to be ready..."
sleep 1
done
if [ $i -eq 60 ]; then
echo "Service failed to start within 60 seconds."
exit 1
fi
make test-api-report
- name: "Test Report (API)"
uses: phoenix-actions/test-reporting@v15
if: success() || failure()
with:
name: API Integration Tests
path: test-reports/api.xml
reporter: java-junit
# ===== Build container images ======
build-images:
name: "Build & Push Images"
runs-on: ubuntu-latest
needs: tests-linting
strategy:
matrix:
serviceName: [cart, orders, users, products, frontend]
steps:
- name: "Checkout source"
uses: actions/checkout@v3
- name: "Run build"
run: |
make docker-build-${{ matrix.serviceName }} IMAGE_TAG=$IMAGE_TAG VERSION=$VERSION BUILD_INFO="$BUILD_INFO"
make docker-build-${{ matrix.serviceName }} IMAGE_TAG=latest VERSION=$VERSION BUILD_INFO="$BUILD_INFO"
# Steps after this are only run when merging or pushing into main
- name: "Push to container registry"
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login $IMAGE_REG -u $GITHUB_ACTOR --password-stdin
make docker-push-${{ matrix.serviceName }} IMAGE_TAG=$IMAGE_TAG
make docker-push-${{ matrix.serviceName }} IMAGE_TAG=latest