Skip to content

Commit

Permalink
ch3: health check endpoint (#1)
Browse files Browse the repository at this point in the history
* ch3: health check endpoint

Signed-off-by: Jin Dong <jin.dong@databricks.com>

* ch3: db creation and migration (for UT/CI)

Signed-off-by: Jin Dong <jin.dong@databricks.com>

* ch3: add sqlx dep

Signed-off-by: Jin Dong <jin.dong@databricks.com>

* refactor to sub modules

Signed-off-by: Jin Dong <jin.dong@databricks.com>

* ch3: add config file

Signed-off-by: Jin Dong <jin.dong@databricks.com>

* ch3: add db connection and related tests

Signed-off-by: Jin Dong <jin.dong@databricks.com>

* ch3: update CI to enable db setup

Signed-off-by: Jin Dong <jin.dong@databricks.com>

* ch3: enable DB setup in test/CI

Signed-off-by: Jin Dong <jin.dong@databricks.com>

* ch3: update actions

Signed-off-by: Jin Dong <jin.dong@databricks.com>

---------

Signed-off-by: Jin Dong <jin.dong@databricks.com>
  • Loading branch information
djdongjin committed Mar 25, 2024
1 parent 0b11e0e commit 294e736
Show file tree
Hide file tree
Showing 16 changed files with 3,469 additions and 84 deletions.
1 change: 1 addition & 0 deletions .env
@@ -0,0 +1 @@
DATABASE_URL="postgres://postgres:password@localhost:5432/newsletter"
160 changes: 79 additions & 81 deletions .github/workflows/general.yaml
Expand Up @@ -21,122 +21,120 @@ jobs:
test:
name: Test
runs-on: ubuntu-latest
# services:
# postgres:
# image: postgres:14
# env:
# POSTGRES_USER: postgres
# POSTGRES_PASSWORD: password
# POSTGRES_DB: postgres
# ports:
# - 5432:5432
# redis:
# image: redis:7
# ports:
# - 6379:6379
services:
postgres:
image: postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres
# When you map ports using the ports keyword, GitHub uses the --publish command to publish the container’s ports to the Docker host
# Opens tcp port 5432 on the host and service container
ports:
- 5432:5432
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
# An additional cache key that is added alongside the automatic `job`-based cache key and can be used to further differentiate jobs. default: empty
key: sqlx-${{ env.SQLX_VERSION }}
# - name: Install sqlx-cli
# run:
# cargo install sqlx-cli
# --version=${{ env.SQLX_VERSION }}
# --features ${{ env.SQLX_FEATURES }}
# --no-default-features
# --locked
# - name: Migrate database
# run: |
# sudo apt-get install libpq-dev -y
# SKIP_DOCKER=true ./scripts/init_db.sh
# - name: Check sqlx-data.json is up-to-date
# run: |
# cargo sqlx prepare --workspace --check

- name: Install sqlx-cli
run:
cargo install sqlx-cli
--version=${{ env.SQLX_VERSION }}
--features ${{ env.SQLX_FEATURES }}
--no-default-features
--locked
# The --locked flag can be used to force Cargo to use the packaged Cargo.lock file if it is available.
# This may be useful for ensuring reproducible builds, to use the exact same set of dependencies that were available when the package was published.
# It may also be useful if a newer version of a dependency is published that no longer builds on your system, or has other problems

- name: Install postgresql-client
run: sudo apt-get update && sudo apt-get install postgresql-client -y

- name: Migrate database
run: SKIP_DOCKER=true ./scripts/init_db.sh

- name: Run tests
run: cargo test

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
# Specific to dtolnay/rust-toolchain: Comma-separated string of additional components to install
components: rustfmt
- name: Enforce formatting
run: cargo fmt --check

clippy:
name: Clippy
runs-on: ubuntu-latest
# services:
# postgres:
# image: postgres:14
# env:
# POSTGRES_USER: postgres
# POSTGRES_PASSWORD: password
# POSTGRES_DB: postgres
# ports:
# - 5432:5432
services:
postgres:
image: postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres
ports:
- 5432:5432
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
with:
key: sqlx-${{ env.SQLX_VERSION }}
# - name: Install sqlx-cli
# run:
# cargo install sqlx-cli
# --version=${{ env.SQLX_VERSION }}
# --features ${{ env.SQLX_FEATURES }}
# --no-default-features
# --locked
# - name: Migrate database
# run: |
# sudo apt-get install libpq-dev -y
# SKIP_DOCKER=true ./scripts/init_db.sh
- name: Install sqlx-cli
run:
cargo install sqlx-cli
--version=${{ env.SQLX_VERSION }}
--features ${{ env.SQLX_FEATURES }}
--no-default-features
--locked
- name: Install postgresql-client
run: sudo apt-get update && sudo apt-get install postgresql-client -y
- name: Migrate database
run: SKIP_DOCKER=true ./scripts/init_db.sh
- name: Linting
run: cargo clippy -- -D warnings

coverage:
name: Code coverage
runs-on: ubuntu-latest
# services:
# postgres:
# image: postgres:14
# env:
# POSTGRES_USER: postgres
# POSTGRES_PASSWORD: password
# POSTGRES_DB: postgres
# ports:
# - 5432:5432
# redis:
# image: redis:7
# ports:
# - 6379:6379
services:
postgres:
image: postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres
ports:
- 5432:5432
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
# - name: Install libpq
# run: sudo apt-get update && sudo apt-get install postgresql-client -y
# - uses: Swatinem/rust-cache@v2
# with:
# key: sqlx-${{ env.SQLX_VERSION }}
- name: Install tarpaulin
run: cargo install cargo-tarpaulin
# - name: Install sqlx-cli
# run:
# cargo install sqlx-cli
# --version=${{ env.SQLX_VERSION }}
# --features ${{ env.SQLX_FEATURES }}
# --no-default-features
# --locked
# - name: Migrate database
# run: SKIP_DOCKER=true ./scripts/init_db.sh
- name: Install postgresql-client
run: sudo apt-get update && sudo apt-get install postgresql-client -y
- uses: Swatinem/rust-cache@v2
with:
key: sqlx-${{ env.SQLX_VERSION }}
- name: Install sqlx-cli
run:
cargo install sqlx-cli
--version=${{ env.SQLX_VERSION }}
--features ${{ env.SQLX_FEATURES }}
--no-default-features
--locked
- name: Migrate database
run: SKIP_DOCKER=true ./scripts/init_db.sh
- name: Generate code coverage
run: cargo tarpaulin --verbose --workspace
run: cargo install cargo-tarpaulin && cargo tarpaulin --verbose --workspace

0 comments on commit 294e736

Please sign in to comment.