From 6ba22b3056bff5b506b303b29b4dcc76e37e34ba Mon Sep 17 00:00:00 2001 From: Garry O'Donnell Date: Wed, 8 Jan 2025 16:22:21 +0000 Subject: [PATCH] Pre-prepare SQLX queries to simplify bundler CI --- .github/workflows/_bundler_container.yaml | 20 +++------- .github/workflows/_bundler_docs.yaml | 19 +++------ .github/workflows/_bundler_lint.yaml | 19 +++------ .github/workflows/_bundler_sqlx.yaml | 47 +++++++++++++++++++++++ .github/workflows/ci.yaml | 8 ++++ 5 files changed, 73 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/_bundler_sqlx.yaml diff --git a/.github/workflows/_bundler_container.yaml b/.github/workflows/_bundler_container.yaml index 1e78ceb..f45e8e6 100644 --- a/.github/workflows/_bundler_container.yaml +++ b/.github/workflows/_bundler_container.yaml @@ -9,21 +9,16 @@ jobs: permissions: contents: read packages: write - services: - ispyb: - image: ghcr.io/diamondlightsource/ispyb-database:v3.0.0 - ports: - - 3306:3306 - env: - MARIADB_ROOT_PASSWORD: rootpassword - options: >- - --health-cmd "/usr/local/bin/healthcheck.sh --defaults-file=/ispyb/.my.cnf --connect" - --health-interval 1s - --health-retries 60 steps: - name: Checkout source uses: actions/checkout@v4.2.2 + - name: Download Prepared Queries Artifact + uses: actions/download-artifact@v4.1.8 + with: + name: prepared-queries + path: bundler/.sqlx + - name: Generate Image Name run: echo IMAGE_REPOSITORY=ghcr.io/$(echo "${{ github.repository }}-bundler" | tr '[:upper:]' '[:lower:]' | tr '[_]' '[\-]') >> $GITHUB_ENV @@ -46,13 +41,10 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3.8.0 - with: - driver-opts: network=host - name: Build & Publish Image uses: docker/build-push-action@v6.10.0 with: - build-args: DATABASE_URL=mysql://root:rootpassword@localhost:3306/ispyb_build context: bundler/ push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }} load: ${{ !(github.event_name == 'push' && startsWith(github.ref, 'refs/tags')) }} diff --git a/.github/workflows/_bundler_docs.yaml b/.github/workflows/_bundler_docs.yaml index 1e484bb..ef278cc 100644 --- a/.github/workflows/_bundler_docs.yaml +++ b/.github/workflows/_bundler_docs.yaml @@ -6,23 +6,16 @@ on: jobs: build: runs-on: ubuntu-latest - services: - ispyb: - image: ghcr.io/diamondlightsource/ispyb-database:v3.0.0 - ports: - - 3306:3306 - env: - MARIADB_ROOT_PASSWORD: rootpassword - options: >- - --health-cmd "/usr/local/bin/healthcheck.sh --defaults-file=/ispyb/.my.cnf --connect" - --health-interval 1s - --health-retries 60 - env: - DATABASE_URL: mysql://root:rootpassword@localhost/ispyb_build steps: - name: Checkout source uses: actions/checkout@v4.2.2 + - name: Download Prepared Queries Artifact + uses: actions/download-artifact@v4.1.8 + with: + name: prepared-queries + path: bundler/.sqlx + - name: Install stable toolchain uses: actions-rs/toolchain@v1.0.7 with: diff --git a/.github/workflows/_bundler_lint.yaml b/.github/workflows/_bundler_lint.yaml index dbd6175..d9871a0 100644 --- a/.github/workflows/_bundler_lint.yaml +++ b/.github/workflows/_bundler_lint.yaml @@ -6,23 +6,16 @@ on: jobs: lint: runs-on: ubuntu-latest - services: - ispyb: - image: ghcr.io/diamondlightsource/ispyb-database:v3.0.0 - ports: - - 3306:3306 - env: - MARIADB_ROOT_PASSWORD: rootpassword - options: >- - --health-cmd "/usr/local/bin/healthcheck.sh --defaults-file=/ispyb/.my.cnf --connect" - --health-interval 1s - --health-retries 60 - env: - DATABASE_URL: mysql://root:rootpassword@localhost/ispyb_build steps: - name: Checkout source uses: actions/checkout@v4.2.2 + - name: Download Prepared Queries Artifact + uses: actions/download-artifact@v4.1.8 + with: + name: prepared-queries + path: bundler/.sqlx + - name: Install stable toolchain uses: actions-rs/toolchain@v1.0.7 with: diff --git a/.github/workflows/_bundler_sqlx.yaml b/.github/workflows/_bundler_sqlx.yaml new file mode 100644 index 0000000..caaa286 --- /dev/null +++ b/.github/workflows/_bundler_sqlx.yaml @@ -0,0 +1,47 @@ +name: Bundler SQLX + +on: + workflow_call: + +jobs: + prepare: + runs-on: ubuntu-latest + services: + ispyb: + image: ghcr.io/diamondlightsource/ispyb-database:v3.0.0 + ports: + - 3306:3306 + env: + MARIADB_ROOT_PASSWORD: rootpassword + options: >- + --health-cmd "/usr/local/bin/healthcheck.sh --defaults-file=/ispyb/.my.cnf --connect" + --health-interval 1s + --health-retries 60 + env: + DATABASE_URL: mysql://root:rootpassword@localhost/ispyb_build + steps: + - name: Checkout source + uses: actions/checkout@v4.2.2 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1.0.7 + with: + toolchain: stable + default: true + + - name: Cache Rust Build + uses: Swatinem/rust-cache@v2.7.7 + + - name: Install SQLX CLI + run: cargo install sqlx-cli + + - name: Prepare SQLX Query + working-directory: bundler + run: cargo sqlx prepare + + - name: Upload Prepared Queries Artifact + uses: actions/upload-artifact@v4.5.0 + with: + name: prepared-queries + path: bundler/.sqlx + include-hidden-files: true diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ee7be52..92e6117 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -10,9 +10,15 @@ jobs: if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository uses: ./.github/workflows/_devcontainer.yaml + bundler_sqlx: + # Deduplicate jobs from pull requests and branch pushes within the same repo. + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository + uses: ./.github/workflows/_bundler_sqlx.yaml + bundler_lint: # Deduplicate jobs from pull requests and branch pushes within the same repo. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository + needs: bundler_sqlx uses: ./.github/workflows/_bundler_lint.yaml bundler_test: @@ -24,6 +30,7 @@ jobs: # Deduplicate jobs from pull requests and branch pushes within the same repo. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository needs: + - bundler_sqlx - bundler_lint - bundler_test permissions: @@ -34,6 +41,7 @@ jobs: bundler_docs: # Deduplicate jobs from pull requests and branch pushes within the same repo. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository + needs: bundler_sqlx uses: ./.github/workflows/_bundler_docs.yaml policy_lint: