|
| 1 | +name: Spanner Build, Test, and Push |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize] |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - "master" |
| 9 | + tags: |
| 10 | + - "**" |
| 11 | + workflow_dispatch: {} |
| 12 | + |
| 13 | +env: |
| 14 | + RUST_VERSION: "1.89" # RUST_VER |
| 15 | + PYTHON_VERSION: "3.12" # PY_VER |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-and-test-spanner: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + services: |
| 22 | + spanner-emulator: |
| 23 | + image: gcr.io/cloud-spanner-emulator/emulator:1.4.0 |
| 24 | + ports: |
| 25 | + - 9010:9010 |
| 26 | + - 9020:9020 |
| 27 | + |
| 28 | + env: |
| 29 | + # The code expects a spanner URL like: |
| 30 | + SYNC_SYNCSTORAGE__DATABASE_URL: spanner://projects/test-project/instances/test-instance/databases/test-database |
| 31 | + RUST_BACKTRACE: 1 |
| 32 | + RUST_TEST_THREADS: 1 |
| 33 | + |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v6 |
| 36 | + |
| 37 | + - uses: ./.github/actions/setup-rust |
| 38 | + with: |
| 39 | + workspace-path: workflow/test-results |
| 40 | + |
| 41 | + - uses: ./.github/actions/setup-python |
| 42 | + with: |
| 43 | + workspace-path: workflow/test-results |
| 44 | + |
| 45 | + - name: Create version.json |
| 46 | + run: | |
| 47 | + printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n' \ |
| 48 | + "${{ github.sha }}" \ |
| 49 | + "${{ github.ref_name }}" \ |
| 50 | + "${{ github.repository_owner }}" \ |
| 51 | + "${{ github.event.repository.name }}" \ |
| 52 | + "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \ |
| 53 | + > syncserver/version.json |
| 54 | +
|
| 55 | + - name: Install test dependencies |
| 56 | + run: cargo install --locked cargo-nextest cargo-llvm-cov |
| 57 | + |
| 58 | + - name: Build workspace (spanner feature) |
| 59 | + run: | |
| 60 | + # Build with the spanner feature so any compile-time issues surface early |
| 61 | + cargo build --workspace --no-default-features --features=syncstorage-db/spanner --features=py_verifier |
| 62 | +
|
| 63 | + - name: Wait for Spanner Emulator to be ready |
| 64 | + run: | |
| 65 | + echo "Waiting for Spanner emulator to be ready..." |
| 66 | + for i in {1..30}; do |
| 67 | + if curl -s http://localhost:9020/ > /dev/null 2>&1; then |
| 68 | + echo "Spanner emulator is ready (REST port 9020 responding)" |
| 69 | + break |
| 70 | + fi |
| 71 | + echo "Attempt $i/30: Spanner emulator not ready yet, waiting..." |
| 72 | + sleep 2 |
| 73 | + done |
| 74 | + # Verify both ports are accessible |
| 75 | + if ! curl -s http://localhost:9020/ > /dev/null 2>&1; then |
| 76 | + echo "ERROR: Cannot connect to Spanner emulator REST API at localhost:9020" |
| 77 | + exit 1 |
| 78 | + fi |
| 79 | + echo "Spanner emulator is fully ready" |
| 80 | +
|
| 81 | + - name: Setup Spanner schema & instance (prepare-spanner.sh) |
| 82 | + env: |
| 83 | + SYNC_SYNCSTORAGE__DATABASE_URL: spanner://projects/test-project/instances/test-instance/databases/test-database |
| 84 | + SYNC_SYNCSTORAGE__SPANNER_EMULATOR_HOST: http://localhost:9020 |
| 85 | + run: | |
| 86 | + # prepare-spanner.sh uses the REST API (port 9020) |
| 87 | + scripts/prepare-spanner.sh |
| 88 | +
|
| 89 | + - name: Run Spanner unit tests with coverage |
| 90 | + env: |
| 91 | + SYNC_SYNCSTORAGE__DATABASE_URL: spanner://projects/test-project/instances/test-instance/databases/test-database |
| 92 | + SYNC_SYNCSTORAGE__SPANNER_EMULATOR_HOST: localhost:9010 |
| 93 | + RUST_TEST_THREADS: 1 |
| 94 | + run: make spanner_test_with_coverage |
| 95 | + |
| 96 | + - name: Upload test results |
| 97 | + if: always() |
| 98 | + uses: actions/upload-artifact@v6 |
| 99 | + with: |
| 100 | + name: spanner-test-results |
| 101 | + path: workflow/test-results/ |
| 102 | + |
| 103 | + # Upload to GCS on master |
| 104 | + - name: Authenticate to Google Cloud |
| 105 | + if: github.ref == 'refs/heads/master' && env.GCP_AUTH_KEY != '' |
| 106 | + env: |
| 107 | + GCP_AUTH_KEY: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }} |
| 108 | + uses: google-github-actions/auth@v3 |
| 109 | + with: |
| 110 | + credentials_json: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }} |
| 111 | + |
| 112 | + - name: Upload JUnit results to GCS |
| 113 | + if: github.ref == 'refs/heads/master' && env.GCP_AUTH_KEY != '' |
| 114 | + env: |
| 115 | + GCP_AUTH_KEY: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }} |
| 116 | + uses: google-github-actions/upload-cloud-storage@v2 |
| 117 | + with: |
| 118 | + path: workflow/test-results |
| 119 | + destination: ecosystem-test-eng-metrics/syncstorage-rs/junit |
| 120 | + glob: "*.xml" |
| 121 | + parent: false |
| 122 | + process_gcloudignore: false |
| 123 | + |
| 124 | + - name: Upload coverage results to GCS |
| 125 | + if: github.ref == 'refs/heads/master' && env.GCP_AUTH_KEY != '' |
| 126 | + env: |
| 127 | + GCP_AUTH_KEY: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }} |
| 128 | + uses: google-github-actions/upload-cloud-storage@v2 |
| 129 | + with: |
| 130 | + path: workflow/test-results |
| 131 | + destination: ecosystem-test-eng-metrics/syncstorage-rs/coverage |
| 132 | + glob: "*.json" |
| 133 | + parent: false |
| 134 | + process_gcloudignore: false |
| 135 | + |
| 136 | + build-spanner-image: |
| 137 | + runs-on: ubuntu-latest |
| 138 | + needs: build-and-test-spanner |
| 139 | + |
| 140 | + steps: |
| 141 | + - uses: actions/checkout@v6 |
| 142 | + |
| 143 | + - name: Create version.json |
| 144 | + run: | |
| 145 | + printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n' \ |
| 146 | + "${{ github.sha }}" \ |
| 147 | + "${{ github.ref_name }}" \ |
| 148 | + "${{ github.repository_owner }}" \ |
| 149 | + "${{ github.event.repository.name }}" \ |
| 150 | + "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \ |
| 151 | + > syncserver/version.json |
| 152 | +
|
| 153 | + - name: Set up Docker Buildx |
| 154 | + uses: docker/setup-buildx-action@v3 |
| 155 | + |
| 156 | + - name: Build Spanner Docker image (local artifact) |
| 157 | + uses: docker/build-push-action@v6 |
| 158 | + with: |
| 159 | + context: . |
| 160 | + push: false |
| 161 | + tags: app:build |
| 162 | + build-args: | |
| 163 | + SYNCSTORAGE_DATABASE_BACKEND=spanner |
| 164 | + MYSQLCLIENT_PKG=libmysqlclient-dev |
| 165 | + outputs: type=docker,dest=/tmp/spanner-image.tar |
| 166 | + cache-from: type=gha |
| 167 | + cache-to: type=gha,mode=max |
| 168 | + |
| 169 | + - name: Upload Docker image artifact |
| 170 | + uses: actions/upload-artifact@v6 |
| 171 | + with: |
| 172 | + name: spanner-docker-image |
| 173 | + path: /tmp/spanner-image.tar |
| 174 | + retention-days: 1 |
| 175 | + |
| 176 | + spanner-e2e-tests: |
| 177 | + runs-on: ubuntu-latest |
| 178 | + needs: build-spanner-image |
| 179 | + |
| 180 | + steps: |
| 181 | + - uses: actions/checkout@v6 |
| 182 | + |
| 183 | + - name: Download Docker image |
| 184 | + uses: actions/download-artifact@v6 |
| 185 | + with: |
| 186 | + name: spanner-docker-image |
| 187 | + path: /tmp |
| 188 | + |
| 189 | + - name: Load Docker image |
| 190 | + run: docker load --input /tmp/spanner-image.tar |
| 191 | + |
| 192 | + - name: Create test results directory |
| 193 | + run: mkdir -p workflow/test-results |
| 194 | + |
| 195 | + - name: Run Spanner e2e tests |
| 196 | + run: make docker_run_spanner_e2e_tests |
| 197 | + env: |
| 198 | + SYNCSTORAGE_RS_IMAGE: app:build |
| 199 | + |
| 200 | + - name: Upload e2e test results |
| 201 | + if: always() |
| 202 | + uses: actions/upload-artifact@v6 |
| 203 | + with: |
| 204 | + name: spanner-e2e-test-results |
| 205 | + path: workflow/test-results/ |
| 206 | + |
| 207 | + # Upload to GCS on master |
| 208 | + - name: Authenticate to Google Cloud |
| 209 | + if: github.ref == 'refs/heads/master' && env.GCP_AUTH_KEY != '' |
| 210 | + env: |
| 211 | + GCP_AUTH_KEY: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }} |
| 212 | + uses: google-github-actions/auth@v3 |
| 213 | + with: |
| 214 | + credentials_json: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }} |
| 215 | + |
| 216 | + - name: Upload e2e test results to GCS |
| 217 | + if: github.ref == 'refs/heads/master' && env.GCP_AUTH_KEY != '' |
| 218 | + env: |
| 219 | + GCP_AUTH_KEY: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }} |
| 220 | + uses: google-github-actions/upload-cloud-storage@v2 |
| 221 | + with: |
| 222 | + path: workflow/test-results |
| 223 | + destination: ecosystem-test-eng-metrics/syncstorage-rs/junit |
| 224 | + glob: "*.xml" |
| 225 | + parent: false |
| 226 | + process_gcloudignore: false |
| 227 | + |
| 228 | + deploy-spanner: |
| 229 | + runs-on: ubuntu-latest |
| 230 | + needs: spanner-e2e-tests |
| 231 | + if: | |
| 232 | + github.ref == 'refs/heads/master' || |
| 233 | + startsWith(github.ref, 'refs/tags/') || |
| 234 | + startsWith(github.ref, 'refs/heads/feature.') |
| 235 | +
|
| 236 | + steps: |
| 237 | + - name: Download Docker image |
| 238 | + uses: actions/download-artifact@v6 |
| 239 | + with: |
| 240 | + name: spanner-docker-image |
| 241 | + path: /tmp |
| 242 | + |
| 243 | + - name: Load Docker image |
| 244 | + run: docker load --input /tmp/spanner-image.tar |
| 245 | + |
| 246 | + - name: Log in to Docker Hub |
| 247 | + uses: docker/login-action@v3 |
| 248 | + with: |
| 249 | + username: ${{ secrets.DOCKER_USER }} |
| 250 | + password: ${{ secrets.DOCKER_PASS }} |
| 251 | + |
| 252 | + - name: Determine Docker tag |
| 253 | + id: docker-tag |
| 254 | + run: | |
| 255 | + if [ "${{ github.ref }}" == "refs/heads/master" ]; then |
| 256 | + DOCKER_TAG="${{ github.sha }}" |
| 257 | + elif [[ "${{ github.ref }}" == refs/tags/* ]]; then |
| 258 | + DOCKER_TAG="${{ github.ref_name }}" |
| 259 | + elif [[ "${{ github.ref }}" == refs/heads/feature.* ]]; then |
| 260 | + DOCKER_TAG="${{ github.ref_name }}" |
| 261 | + else |
| 262 | + echo "Not pushing to DockerHub for ref=${{ github.ref }}" |
| 263 | + exit 0 |
| 264 | + fi |
| 265 | + echo "tag=${DOCKER_TAG}" >> $GITHUB_OUTPUT |
| 266 | + echo "full_tag=${{ secrets.DOCKERHUB_REPO }}:${DOCKER_TAG}-spanner" >> $GITHUB_OUTPUT |
| 267 | +
|
| 268 | + - name: Tag and push Docker image |
| 269 | + if: steps.docker-tag.outputs.tag != '' |
| 270 | + run: | |
| 271 | + docker tag app:build ${{ steps.docker-tag.outputs.full_tag }} |
| 272 | + docker images |
| 273 | + docker push ${{ steps.docker-tag.outputs.full_tag }} |
0 commit comments