Add Docker Compose-Based Redis Environment for go-redis CI #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Build and Test using containerized environment | |
on: | |
push: | |
paths-ignore: | |
- 'docs/**' | |
- '**/*.md' | |
- '**/*.rst' | |
branches: | |
- master | |
- '[0-9].*' | |
pull_request: | |
branches: | |
- master | |
- '[0-9].*' | |
schedule: | |
- cron: '0 1 * * *' # nightly build | |
jobs: | |
build: | |
name: Build and Test | |
runs-on: ubuntu-latest | |
env: | |
REDIS_ENV_WORK_DIR: ${{ github.workspace }}/redis-env-work | |
REDIS_ENV_CONF_DIR: ${{ github.workspace }}/src/test/resources/env | |
CLIENT_LIBS_IMAGE_PREFIX: "redislabs/client-libs-test" | |
strategy: | |
fail-fast: false | |
matrix: | |
redis_version: | |
- "7.4.1" | |
- "7.2.6" | |
- "6.2.16" | |
- "8.0-M01" | |
go_version: | |
- "1.19.x" | |
- "1.20.x" | |
- "1.21.x" | |
steps: | |
- name: Set up ${{ matrix.go_version }} | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ matrix.go_version }} | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
# Set up Docker Compose environment | |
- name: Set up Docker Compose environment | |
run: | | |
mkdir -m 777 $REDIS_ENV_WORK_DIR | |
export REDIS_VERSION="${{ matrix.redis_version }}" | |
export COMPOSE_ENV_FILES="src/test/resources/env/.env" | |
if [[ "${{ matrix.redis_version }}" == "6.2.16" ]]; then | |
COMPOSE_ENV_FILES+=",src/test/resources/env/.env.v${{ matrix.redis_version }}" | |
fi | |
docker compose -f src/test/resources/env/docker-compose.yml up -d | |
- name: Run tests | |
env: | |
GO_VERSION: ${{ matrix.go_version }} | |
run: | | |
set -e | |
GO_MOD_DIRS=$(find . -type d -name go.mod | xargs -n 1 dirname) | |
for dir in $GO_MOD_DIRS; do | |
if echo "$dir" | grep -q "./example" && [ "$GO_VERSION" = "19" ]; then | |
echo "Skipping go test in $dir due to Go version 1.19 and dir contains ./example" | |
continue | |
fi | |
echo "Running tests in $dir" | |
( | |
cd "$dir" | |
go mod tidy -compat=1.18 | |
go test ./... -short -race | |
go test ./... -run=NONE -bench=. -benchmem | |
env GOOS=linux GOARCH=386 go test ./... | |
go test -coverprofile=coverage.txt -covermode=atomic ./... | |
go vet | |
) | |
done | |
- name: Build custom vet tool | |
run: | | |
cd internal/customvet && go build . | |
go vet -vettool ./internal/customvet/customvet | |
# Collect logs on failure | |
- name: Collect logs on failure | |
if: failure() # This runs only if the previous steps failed | |
run: | | |
echo "Collecting logs from $WORK_DIR..." | |
ls -la $REDIS_ENV_WORK_DIR | |
# Upload logs as artifacts | |
- name: Upload logs on failure | |
if: failure() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: redis-env-work-logs | |
path: ${{ env.REDIS_ENV_WORK_DIR }} | |
# Bring down the Docker Compose test environment | |
- name: Tear down Docker Compose environment | |
if: always() | |
run: | | |
docker compose $COMPOSE_ENV_FILES -f src/test/resources/env/docker-compose.yml down | |
continue-on-error: true | |
# Upload code coverage | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v4 | |
with: | |
fail_ci_if_error: false | |
token: ${{ secrets.CODECOV_TOKEN }} | |
- name: Upload test results to Codecov | |
if: ${{ github.event_name == 'schedule' || (github.event_name == 'push') || github.event_name == 'workflow_dispatch'}} | |
uses: codecov/test-results-action@v1 | |
with: | |
fail_ci_if_error: false | |
files: ./target/surefire-reports/TEST* | |
token: ${{ secrets.CODECOV_TOKEN }} |