|
| 1 | +name: MySQL Build and Test |
| 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" |
| 15 | + PYTHON_VERSION: "3.12" |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-and-test-mysql: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + services: |
| 22 | + mysql: |
| 23 | + image: mysql:8.0 |
| 24 | + env: |
| 25 | + MYSQL_ROOT_PASSWORD: password |
| 26 | + MYSQL_USER: test |
| 27 | + MYSQL_PASSWORD: test |
| 28 | + MYSQL_DATABASE: syncstorage |
| 29 | + ports: |
| 30 | + - 3306:3306 |
| 31 | + options: >- |
| 32 | + --health-cmd="mysqladmin ping" |
| 33 | + --health-interval=10s |
| 34 | + --health-timeout=5s |
| 35 | + --health-retries=5 |
| 36 | +
|
| 37 | + env: |
| 38 | + SYNC_SYNCSTORAGE__DATABASE_URL: mysql://test:test@127.0.0.1/syncstorage |
| 39 | + SYNC_TOKENSERVER__DATABASE_URL: mysql://test:test@127.0.0.1/tokenserver |
| 40 | + RUST_BACKTRACE: 1 |
| 41 | + RUST_TEST_THREADS: 1 |
| 42 | + |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@v6 |
| 45 | + |
| 46 | + - uses: ./.github/actions/setup-rust |
| 47 | + with: |
| 48 | + workspace-path: workflow/test-results |
| 49 | + |
| 50 | + - uses: ./.github/actions/setup-python |
| 51 | + with: |
| 52 | + workspace-path: workflow/test-results |
| 53 | + |
| 54 | + - name: Install MySQL client |
| 55 | + run: sudo apt-get update && sudo apt-get install -y default-mysql-client |
| 56 | + |
| 57 | + - name: Create Tokenserver database |
| 58 | + run: | |
| 59 | + mysql -u root -ppassword -h 127.0.0.1 -e 'CREATE DATABASE tokenserver;' |
| 60 | + mysql -u root -ppassword -h 127.0.0.1 -e "GRANT ALL ON tokenserver.* to 'test'@'%';" |
| 61 | +
|
| 62 | + - name: Create version.json |
| 63 | + run: | |
| 64 | + printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n' \ |
| 65 | + "${{ github.sha }}" \ |
| 66 | + "${{ github.ref_name }}" \ |
| 67 | + "${{ github.repository_owner }}" \ |
| 68 | + "${{ github.event.repository.name }}" \ |
| 69 | + "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \ |
| 70 | + > syncserver/version.json |
| 71 | +
|
| 72 | + - name: Install test dependencies |
| 73 | + run: cargo install --locked cargo-nextest cargo-llvm-cov |
| 74 | + |
| 75 | + - name: Run unit tests with coverage |
| 76 | + run: make test_with_coverage |
| 77 | + |
| 78 | + - name: Run unit tests with coverage (quota enforced) |
| 79 | + run: make test_with_coverage |
| 80 | + env: |
| 81 | + SYNC_SYNCSTORAGE__ENFORCE_QUOTA: 1 |
| 82 | + |
| 83 | + - name: Upload test results |
| 84 | + if: always() |
| 85 | + uses: actions/upload-artifact@v6 |
| 86 | + with: |
| 87 | + name: mysql-test-results |
| 88 | + path: workflow/test-results/ |
| 89 | + |
| 90 | + # Upload to GCS on master |
| 91 | + - name: Authenticate to Google Cloud |
| 92 | + if: github.ref == 'refs/heads/master' && env.GCP_AUTH_KEY != '' |
| 93 | + env: |
| 94 | + GCP_AUTH_KEY: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }} |
| 95 | + uses: google-github-actions/auth@v3 |
| 96 | + with: |
| 97 | + credentials_json: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }} |
| 98 | + |
| 99 | + - name: Upload JUnit results to GCS |
| 100 | + if: github.ref == 'refs/heads/master' && env.GCP_AUTH_KEY != '' |
| 101 | + env: |
| 102 | + GCP_AUTH_KEY: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }} |
| 103 | + uses: google-github-actions/upload-cloud-storage@v2 |
| 104 | + with: |
| 105 | + path: workflow/test-results |
| 106 | + destination: ecosystem-test-eng-metrics/syncstorage-rs/junit |
| 107 | + glob: "*.xml" |
| 108 | + parent: false |
| 109 | + process_gcloudignore: false |
| 110 | + |
| 111 | + - name: Upload coverage results to GCS |
| 112 | + if: github.ref == 'refs/heads/master' && env.GCP_AUTH_KEY != '' |
| 113 | + env: |
| 114 | + GCP_AUTH_KEY: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }} |
| 115 | + uses: google-github-actions/upload-cloud-storage@v2 |
| 116 | + with: |
| 117 | + path: workflow/test-results |
| 118 | + destination: ecosystem-test-eng-metrics/syncstorage-rs/coverage |
| 119 | + glob: "*.json" |
| 120 | + parent: false |
| 121 | + process_gcloudignore: false |
| 122 | + |
| 123 | + build-mysql-image: |
| 124 | + runs-on: ubuntu-latest |
| 125 | + needs: build-and-test-mysql |
| 126 | + |
| 127 | + steps: |
| 128 | + - uses: actions/checkout@v6 |
| 129 | + |
| 130 | + - name: Create version.json |
| 131 | + run: | |
| 132 | + printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n' \ |
| 133 | + "${{ github.sha }}" \ |
| 134 | + "${{ github.ref_name }}" \ |
| 135 | + "${{ github.repository_owner }}" \ |
| 136 | + "${{ github.event.repository.name }}" \ |
| 137 | + "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \ |
| 138 | + > syncserver/version.json |
| 139 | +
|
| 140 | + - name: Set up Docker Buildx |
| 141 | + uses: docker/setup-buildx-action@v3 |
| 142 | + |
| 143 | + - name: Build MySQL Docker image |
| 144 | + uses: docker/build-push-action@v6 |
| 145 | + with: |
| 146 | + context: . |
| 147 | + push: false |
| 148 | + tags: app:build |
| 149 | + build-args: | |
| 150 | + SYNCSTORAGE_DATABASE_BACKEND=mysql |
| 151 | + TOKENSERVER_DATABASE_BACKEND=mysql |
| 152 | + outputs: type=docker,dest=/tmp/mysql-image.tar |
| 153 | + cache-from: type=gha |
| 154 | + cache-to: type=gha,mode=max |
| 155 | + |
| 156 | + - name: Upload Docker image artifact |
| 157 | + uses: actions/upload-artifact@v6 |
| 158 | + with: |
| 159 | + name: mysql-docker-image |
| 160 | + path: /tmp/mysql-image.tar |
| 161 | + retention-days: 1 |
| 162 | + |
| 163 | + mysql-e2e-tests: |
| 164 | + runs-on: ubuntu-latest |
| 165 | + needs: build-mysql-image |
| 166 | + |
| 167 | + steps: |
| 168 | + - uses: actions/checkout@v6 |
| 169 | + |
| 170 | + - name: Download Docker image |
| 171 | + uses: actions/download-artifact@v6 |
| 172 | + with: |
| 173 | + name: mysql-docker-image |
| 174 | + path: /tmp |
| 175 | + |
| 176 | + - name: Load Docker image |
| 177 | + run: docker load --input /tmp/mysql-image.tar |
| 178 | + |
| 179 | + - name: Create test results directory |
| 180 | + run: mkdir -p workflow/test-results |
| 181 | + |
| 182 | + - name: Run MySQL e2e tests |
| 183 | + run: make docker_run_mysql_e2e_tests |
| 184 | + env: |
| 185 | + SYNCSTORAGE_RS_IMAGE: app:build |
| 186 | + |
| 187 | + - name: Upload e2e test results |
| 188 | + if: always() |
| 189 | + uses: actions/upload-artifact@v6 |
| 190 | + with: |
| 191 | + name: mysql-e2e-test-results |
| 192 | + path: workflow/test-results/ |
| 193 | + |
| 194 | + # Upload to GCS on master |
| 195 | + - name: Authenticate to Google Cloud |
| 196 | + if: github.ref == 'refs/heads/master' && env.GCP_AUTH_KEY != '' |
| 197 | + env: |
| 198 | + GCP_AUTH_KEY: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }} |
| 199 | + uses: google-github-actions/auth@v3 |
| 200 | + with: |
| 201 | + credentials_json: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }} |
| 202 | + |
| 203 | + - name: Upload e2e test results to GCS |
| 204 | + if: github.ref == 'refs/heads/master' && env.GCP_AUTH_KEY != '' |
| 205 | + env: |
| 206 | + GCP_AUTH_KEY: ${{ secrets.ETE_GCLOUD_SERVICE_KEY }} |
| 207 | + uses: google-github-actions/upload-cloud-storage@v2 |
| 208 | + with: |
| 209 | + path: workflow/test-results |
| 210 | + destination: ecosystem-test-eng-metrics/syncstorage-rs/junit |
| 211 | + glob: "*.xml" |
| 212 | + parent: false |
| 213 | + process_gcloudignore: false |
0 commit comments