|
| 1 | +name: Test and Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master, main ] |
| 6 | + pull_request: |
| 7 | + branches: [ master, main ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Set up Go |
| 16 | + uses: actions/setup-go@v4 |
| 17 | + with: |
| 18 | + go-version: '1.21' |
| 19 | + |
| 20 | + - name: Cache Go modules |
| 21 | + uses: actions/cache@v3 |
| 22 | + with: |
| 23 | + path: ~/go/pkg/mod |
| 24 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 25 | + restore-keys: | |
| 26 | + ${{ runner.os }}-go- |
| 27 | +
|
| 28 | + - name: Download dependencies |
| 29 | + run: go mod download |
| 30 | + |
| 31 | + - name: Verify dependencies |
| 32 | + run: go mod verify |
| 33 | + |
| 34 | + - name: Build |
| 35 | + run: go build -v ./... |
| 36 | + |
| 37 | + - name: Run tests |
| 38 | + run: go test -race -coverprofile=coverage.out -covermode=atomic ./... |
| 39 | + |
| 40 | + - name: Run go vet |
| 41 | + run: go vet ./... |
| 42 | + |
| 43 | + - name: Run go fmt |
| 44 | + run: | |
| 45 | + if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then |
| 46 | + echo "Code is not formatted properly:" |
| 47 | + gofmt -s -l . |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | +
|
| 51 | + docker_and_integration_tests: |
| 52 | + runs-on: ubuntu-latest |
| 53 | + needs: test |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v4 |
| 56 | + |
| 57 | + - name: Set up Docker Buildx |
| 58 | + uses: docker/setup-buildx-action@v3 |
| 59 | + |
| 60 | + - name: Build Docker image |
| 61 | + uses: docker/build-push-action@v5 |
| 62 | + with: |
| 63 | + context: . |
| 64 | + load: true |
| 65 | + tags: git-mirror-server:dev |
| 66 | + cache-from: type=gha |
| 67 | + cache-to: type=gha,mode=max |
| 68 | + |
| 69 | + - name: Test Docker image |
| 70 | + run: | |
| 71 | + # Start the container in background |
| 72 | + docker run -d --name git-mirror-test \ |
| 73 | + -v ${{ github.workspace }}/example-config.toml:/config.toml \ |
| 74 | + git-mirror-server:dev /config.toml |
| 75 | +
|
| 76 | + # Wait a bit for the server to start |
| 77 | + sleep 5 |
| 78 | +
|
| 79 | + # Check if container is still running |
| 80 | + if ! docker ps | grep git-mirror-test; then |
| 81 | + echo "Container failed to start" |
| 82 | + docker logs git-mirror-test |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | +
|
| 86 | + # Stop the container |
| 87 | + docker stop git-mirror-test |
| 88 | + docker rm git-mirror-test |
| 89 | +
|
| 90 | + - name: Create test config for integration |
| 91 | + run: | |
| 92 | + cat > test-config.toml << EOF |
| 93 | + ListenAddr = ":8080" |
| 94 | + BasePath = "/srv/git" |
| 95 | + Interval = "10s" # Default update interval for repos |
| 96 | +
|
| 97 | + [[repo]] |
| 98 | + Name = "github.com/espressif/git-mirror-server.git" # Explicitly set name |
| 99 | + Origin = "https://github.com/espressif/git-mirror-server.git" |
| 100 | + # Interval = "10s" # Specific interval for this repo (optional) |
| 101 | + EOF |
| 102 | +
|
| 103 | + - name: Run integration test |
| 104 | + run: | |
| 105 | + # Start git-mirror-server |
| 106 | + docker run -d --name git-mirror-integration \ |
| 107 | + -p 8080:8080 \ |
| 108 | + -v ${{ github.workspace }}/test-config.toml:/config.toml \ |
| 109 | + -v ${{ github.workspace }}/test-git-repos:/srv/git \ |
| 110 | + git-mirror-server:dev /config.toml |
| 111 | +
|
| 112 | + # Wait for server to start and first sync |
| 113 | + echo "Waiting for server to start and initial sync..." |
| 114 | + sleep 30 # Increased sleep to allow for cloning and initial setup |
| 115 | +
|
| 116 | + # Check container logs for any immediate errors |
| 117 | + echo "Git mirror server logs:" |
| 118 | + docker logs git-mirror-integration |
| 119 | +
|
| 120 | + # Test git clone |
| 121 | + echo "Testing git clone..." |
| 122 | + GIT_TRACE_PACKET=1 GIT_TRACE=1 GIT_CURL_VERBOSE=1 git clone --depth 1 http://localhost:8080/github.com/espressif/git-mirror-server.git test-clone |
| 123 | + cd test-clone |
| 124 | + git log -1 --oneline |
0 commit comments