-
Notifications
You must be signed in to change notification settings - Fork 3
155 lines (128 loc) · 4.67 KB
/
Copy pathci.yml
File metadata and controls
155 lines (128 loc) · 4.67 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
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
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
checks: write
pull-requests: write
env:
GO_VERSION: "1.26"
jobs:
changes:
name: Detect changed modules
runs-on: ubuntu-latest
outputs:
modules: ${{ steps.filter.outputs.modules }}
steps:
- uses: actions/checkout@v6
- name: Determine changed modules
id: filter
run: |
# On push to main, compare against the previous commit.
# On pull_request, compare against the base branch.
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE=${{ github.event.pull_request.base.sha }}
else
BASE=${{ github.event.before }}
fi
ALL_MODULES='["internal/pkg","internal/service/userservice","internal/service/catalogservice","internal/service/paymentservice","internal/service/spotservice","internal/service/errandservice"]'
# Fall back to running everything when BASE is unknown or unreachable
# (first push, force-push that rewrote history, shallow clone missing the object).
if [ "$BASE" = "0000000000000000000000000000000000000000" ] || [ -z "$BASE" ]; then
echo "modules=$ALL_MODULES" >> "$GITHUB_OUTPUT"
exit 0
fi
if ! git cat-file -e "$BASE^{commit}" 2>/dev/null; then
echo "modules=$ALL_MODULES" >> "$GITHUB_OUTPUT"
exit 0
fi
CHANGED=$(git diff --name-only "$BASE" HEAD)
PKG_CHANGED=false
MODULES='[]'
# Check if shared lib changed — if so, all modules must run.
if echo "$CHANGED" | grep -qE '^internal/pkg/|^\.golangci\.yml|^go\.work|^proto/|^buf\.gen\.yaml|^buf\.lock|^buf\.yaml'; then
PKG_CHANGED=true
fi
# Also run everything when CI config itself changes.
if echo "$CHANGED" | grep -qE '^\.github/workflows/ci\.yml'; then
PKG_CHANGED=true
fi
if [ "$PKG_CHANGED" = "true" ]; then
echo "modules=$ALL_MODULES" >> "$GITHUB_OUTPUT"
exit 0
fi
# Otherwise collect only the services that changed, always including pkg.
RESULT='["internal/pkg"'
for SVC in userservice catalogservice paymentservice spotservice errandservice; do
if echo "$CHANGED" | grep -qE "^internal/service/$SVC/"; then
RESULT="$RESULT,\"internal/service/$SVC\""
fi
done
RESULT="$RESULT]"
# If nothing service-specific changed (e.g. only proto/docs), still run pkg.
echo "modules=$RESULT" >> "$GITHUB_OUTPUT"
lint:
name: Lint (${{ matrix.module }})
needs: changes
if: ${{ needs.changes.outputs.modules != '[]' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
module: ${{ fromJson(needs.changes.outputs.modules) }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: |
internal/pkg/go.sum
internal/service/userservice/go.sum
internal/service/catalogservice/go.sum
internal/service/paymentservice/go.sum
internal/service/spotservice/go.sum
internal/service/errandservice/go.sum
- uses: bufbuild/buf-setup-action@v1
with:
github_token: ${{ github.token }}
- name: Generate proto
run: make proto
- name: Lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.12.2
working-directory: ${{ matrix.module }}
build:
name: Build (${{ matrix.module }})
needs: changes
if: ${{ needs.changes.outputs.modules != '[]' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
module: ${{ fromJson(needs.changes.outputs.modules) }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: ${{ matrix.module }}/go.sum
- uses: bufbuild/buf-setup-action@v1
with:
github_token: ${{ github.token }}
- name: Generate proto
run: make proto
- name: Build
working-directory: ${{ matrix.module }}
run: go build ./...
# TODO: uncomment after tests are added
# - name: Test
# working-directory: ${{ matrix.module }}
# run: go test -race -count=1 ./...
# For integration tests (PostgreSQL/Redis), consider testcontainers-go