1
+ ---
2
+
3
+ name : Build and Test using containerized environment
4
+
5
+ on :
6
+ push :
7
+ paths-ignore :
8
+ - ' docs/**'
9
+ - ' **/*.md'
10
+ - ' **/*.rst'
11
+ branches :
12
+ - master
13
+ - ' [0-9].*'
14
+ pull_request :
15
+ branches :
16
+ - master
17
+ - ' [0-9].*'
18
+ schedule :
19
+ - cron : ' 0 1 * * *' # nightly build
20
+
21
+ jobs :
22
+
23
+ build :
24
+ name : Build and Test
25
+ runs-on : ubuntu-latest
26
+ env :
27
+ REDIS_ENV_WORK_DIR : ${{ github.workspace }}/redis-env-work
28
+ REDIS_ENV_CONF_DIR : ${{ github.workspace }}/src/test/resources/env
29
+ CLIENT_LIBS_IMAGE_PREFIX : " redislabs/client-libs-test"
30
+ strategy :
31
+ fail-fast : false
32
+ matrix :
33
+ redis_version :
34
+ - " 7.4.1"
35
+ - " 7.2.6"
36
+ - " 6.2.16"
37
+ go_version :
38
+ - " 1.19.x"
39
+ - " 1.20.x"
40
+ - " 1.21.x"
41
+ steps :
42
+ - name : Set up ${{ matrix.go_version }}
43
+ uses : actions/setup-go@v5
44
+ with :
45
+ go-version : ${{ matrix.go_version }}
46
+
47
+ - name : Checkout code
48
+ uses : actions/checkout@v4
49
+
50
+ # Set up Docker Compose environment
51
+ - name : Set up Docker Compose environment
52
+ run : |
53
+ mkdir -m 777 $REDIS_ENV_WORK_DIR
54
+ export REDIS_VERSION="${{ matrix.redis_version }}"
55
+ export COMPOSE_ENV_FILES="src/test/resources/env/.env"
56
+ if [[ "${{ matrix.redis_version }}" == "6.2.16" ]]; then
57
+ COMPOSE_ENV_FILES+=",src/test/resources/env/.env.v${{ matrix.redis_version }}"
58
+ fi
59
+ docker compose -f src/test/resources/env/docker-compose.yml up -d
60
+
61
+ - name: Run tests
62
+ env:
63
+ GO_VERSION: ${{ matrix.go_version }}
64
+ run: |
65
+ set -e
66
+ GO_MOD_DIRS=$(find . -type d -name go.mod | xargs -n 1 dirname)
67
+ for dir in $GO_MOD_DIRS; do
68
+ if echo "$dir" | grep -q "./example" && [ "$GO_VERSION" = "19" ]; then
69
+ echo "Skipping go test in $dir due to Go version 1.19 and dir contains ./example"
70
+ continue
71
+ fi
72
+ echo "Running tests in $dir"
73
+ (
74
+ cd "$dir"
75
+ go mod tidy -compat=1.18
76
+ go test ./... -short -race
77
+ go test ./... -run=NONE -bench=. -benchmem
78
+ env GOOS=linux GOARCH=386 go test ./...
79
+ go test -coverprofile=coverage.txt -covermode=atomic ./...
80
+ go vet
81
+ )
82
+ done
83
+
84
+ - name : Build custom vet tool
85
+ run : |
86
+ cd internal/customvet && go build .
87
+ go vet -vettool ./internal/customvet/customvet
88
+
89
+ # Collect logs on failure
90
+ - name : Collect logs on failure
91
+ if : failure() # This runs only if the previous steps failed
92
+ run : |
93
+ echo "Collecting logs from $WORK_DIR..."
94
+ ls -la $REDIS_ENV_WORK_DIR
95
+ # Upload logs as artifacts
96
+ - name : Upload logs on failure
97
+ if : failure()
98
+ uses : actions/upload-artifact@v3
99
+ with :
100
+ name : redis-env-work-logs
101
+ path : ${{ env.REDIS_ENV_WORK_DIR }}
102
+ # Bring down the Docker Compose test environment
103
+ - name : Tear down Docker Compose environment
104
+ if : always()
105
+ run : |
106
+ docker compose $COMPOSE_ENV_FILES -f src/test/resources/env/docker-compose.yml down
107
+ continue-on-error : true
108
+ # Upload code coverage
109
+ - name : Upload coverage to Codecov
110
+ uses : codecov/codecov-action@v4
111
+ with :
112
+ fail_ci_if_error : false
113
+ token : ${{ secrets.CODECOV_TOKEN }}
114
+ - name : Upload test results to Codecov
115
+ if : ${{ github.event_name == 'schedule' || (github.event_name == 'push') || github.event_name == 'workflow_dispatch'}}
116
+ uses : codecov/test-results-action@v1
117
+ with :
118
+ fail_ci_if_error : false
119
+ files : ./target/surefire-reports/TEST*
120
+ token : ${{ secrets.CODECOV_TOKEN }}
0 commit comments