chore: include the .sqlx folder for deployment #119
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tests and formatting | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
on: | |
push: | |
branches: | |
- main | |
- develop | |
pull_request: | |
types: [ opened, synchronize, reopened ] | |
branches: | |
- develop | |
env: | |
CARGO_TERM_COLOR: always | |
SQLX_VERSION: 0.8.2 # When changing ensure the cache is invalidated | |
APP_USER: db_user | |
APP_USER_PWD: password | |
APP_DB_NAME: chat_demo | |
jobs: | |
test_stand_alone_mysql: | |
name: Test (Standalone MySQL) | |
runs-on: ubuntu-latest | |
services: | |
mysql: | |
image: mysql | |
env: | |
MYSQL_USER: ${{ env.APP_USER }} | |
MYSQL_PASSWORD: ${{ env.APP_USER_PWD }} | |
MYSQL_DATABASE: ${{ env.APP_DB_NAME }} | |
MYSQL_ROOT_PASSWORD: password | |
MYSQL_ROOT_HOST: "%" | |
ports: | |
- 3306:3306 | |
redis: | |
image: redis:7 | |
ports: | |
- 6379:6379 | |
steps: | |
- uses: wykies/checkout@main | |
with: | |
submodules: recursive | |
- uses: wykies/setup-rust-toolchain@main | |
- name: Install sqlx-cli | |
run: | |
cargo install sqlx-cli | |
--version=${{ env.SQLX_VERSION }} | |
--features rustls,mysql | |
--no-default-features | |
--locked | |
- name: Migrate database | |
run: | | |
sudo apt-get install mysql-client -y | |
cd crates/chat-app-server && SKIP_DOCKER=true ./scripts/init_db_mysql.sh | |
- name: Load sqlx query files for mysql | |
run: cargo run --bin switch-db -- standalone | |
- name: Check sqlx prepared queries for mysql are is up-to-date | |
run: | | |
cargo sqlx prepare --check --workspace -- --bins --tests --all-features | |
- name: Run tests | |
run: cargo test | |
test_stand_alone_postgres: | |
name: Test (Standalone Postgres) | |
runs-on: ubuntu-latest | |
services: | |
mysql: | |
image: postgres | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: password | |
POSTGRES_DB: postgres | |
ports: | |
- 5432:5432 | |
redis: | |
image: redis:7 | |
ports: | |
- 6379:6379 | |
steps: | |
- uses: wykies/checkout@main | |
with: | |
submodules: recursive | |
- uses: wykies/setup-rust-toolchain@main | |
- name: Install sqlx-cli | |
run: | |
cargo install sqlx-cli | |
--version=${{ env.SQLX_VERSION }} | |
--features rustls,postgres | |
--no-default-features | |
--locked | |
- name: Create app user in Postgres | |
run: | | |
sudo apt-get install postgresql-client | |
# Create the application user | |
CREATE_QUERY="CREATE USER ${APP_USER} WITH PASSWORD '${APP_USER_PWD}';" | |
PGPASSWORD="password" psql -U "postgres" -h "localhost" -c "${CREATE_QUERY}" | |
# Grant create db privileges to the app user | |
GRANT_QUERY="ALTER USER ${APP_USER} CREATEDB;" | |
PGPASSWORD="password" psql -U "postgres" -h "localhost" -c "${GRANT_QUERY}" | |
- name: Migrate database | |
run: | | |
cd crates/chat-app-server && SKIP_DOCKER=true ./scripts/init_db_pg.sh | |
- name: Load sqlx query files for postgres | |
run: cargo run --bin switch-db -- shuttle | |
- name: Check sqlx prepared queries for postgres are is up-to-date | |
run: | | |
cargo sqlx prepare --check --workspace -- --bins --tests --no-default-features --features postgres,standalone | |
- name: Run tests | |
run: cargo test --package chat-app-server --no-default-features --features standalone,postgres | |
fmt: | |
name: Rustfmt | |
runs-on: ubuntu-latest | |
steps: | |
- uses: wykies/checkout@main | |
with: | |
submodules: recursive | |
- uses: wykies/setup-rust-toolchain@main | |
with: | |
components: rustfmt | |
cache: false | |
- name: Enforce formatting | |
run: cargo fmt --check | |
clippy: | |
name: Clippy (Standalone) | |
runs-on: ubuntu-latest | |
steps: | |
- uses: wykies/checkout@main | |
with: | |
submodules: recursive | |
- uses: wykies/setup-rust-toolchain@main | |
with: | |
components: clippy | |
- name: Load sqlx query files for standalone version | |
run: cargo run --bin switch-db -- standalone | |
- name: Linting | |
run: cargo clippy --all-features -- -D warnings | |
wasm: | |
name: Clippy WASM | |
runs-on: ubuntu-latest | |
steps: | |
- uses: wykies/checkout@main | |
with: | |
submodules: recursive | |
- uses: wykies/setup-rust-toolchain@main | |
with: | |
target: wasm32-unknown-unknown | |
components: clippy | |
- name: Linting | |
run: cargo clippy --target="wasm32-unknown-unknown" --package chat-app-client -- -D warnings |