Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ch3: health check endpoint #1

Merged
merged 9 commits into from Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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