-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Anthony M. Bonafide <AnthonyMBonafide@gmail.com>
- Loading branch information
1 parent
46a65a8
commit ae2b978
Showing
1 changed file
with
116 additions
and
122 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,145 +1,139 @@ | ||
# Based on https://github.com/actions-rs/meta/blob/master/recipes/msrv.md | ||
|
||
on: [push, pull_request] | ||
|
||
name: MSRV | ||
name: Rust | ||
|
||
on: | ||
# NB: this differs from the book's project! | ||
# These settings allow us to run this specific CI pipeline for PRs against | ||
# this specific branch (a.k.a. book chapter). | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
branches: | ||
- main | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
SQLX_VERSION: 0.7.1 | ||
SQLX_FEATURES: "rustls,postgres" | ||
|
||
jobs: | ||
# Label of the container job | ||
container-job: | ||
# Containers must run in Linux based operating systems | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
# Docker Hub image that `container-job` executes in | ||
container: node:10.18-jessie | ||
|
||
# Service containers to run with `container-job` | ||
services: | ||
# Label used to access the service container | ||
postgres: | ||
# Docker Hub image | ||
image: postgres | ||
# Provide the password for postgres | ||
image: postgres:14 | ||
env: | ||
POSTGRES_PASSWORD: passowrd | ||
POSTGRES_USERNAME: postgres | ||
POSTGRES_DB: newsletter | ||
# Set health checks to wait until postgres has started | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: password | ||
POSTGRES_DB: postgres | ||
ports: | ||
# Maps tcp port 5432 on service container to the host | ||
- 5432:5432 | ||
check: | ||
name: Check | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
rust: | ||
- stable | ||
- 1.76.0 | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: ${{ matrix.rust }} | ||
override: true | ||
|
||
- name: Run cargo check | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: check | ||
|
||
test: | ||
name: Test Suite | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
rust: | ||
- stable | ||
- 1.76.0 | ||
redis: | ||
image: redis:7 | ||
ports: | ||
- 6379:6379 | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: ${{ matrix.rust }} | ||
override: true | ||
|
||
- name: Run cargo-tarpaulin | ||
uses: actions-rs/tarpaulin@v0.1 | ||
with: | ||
version: "0.15.0" | ||
args: "-- --test-threads 1" | ||
|
||
- name: Upload to codecov.io | ||
uses: codecov/codecov-action@v1.0.2 | ||
with: | ||
token: ${{secrets.CODECOV_TOKEN}} | ||
|
||
- name: Archive code coverage results | ||
uses: actions/upload-artifact@v1 | ||
- uses: actions/checkout@v3 | ||
- uses: dtolnay/rust-toolchain@stable | ||
- uses: Swatinem/rust-cache@v2 | ||
with: | ||
name: code-coverage-report | ||
path: cobertura.xml | ||
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: Run tests | ||
run: cargo test | ||
|
||
fmt: | ||
name: Rustfmt | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
rust: | ||
- stable | ||
- 1.76.0 | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: ${{ matrix.rust }} | ||
override: true | ||
|
||
- name: Install rustfmt | ||
run: rustup component add rustfmt | ||
|
||
- name: Run cargo fmt | ||
uses: actions-rs/cargo@v1 | ||
- uses: actions/checkout@v3 | ||
- uses: dtolnay/rust-toolchain@stable | ||
with: | ||
command: fmt | ||
args: --all -- --check | ||
components: rustfmt | ||
- name: Enforce formatting | ||
run: cargo fmt --check | ||
|
||
clippy: | ||
name: Clippy | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
rust: | ||
- stable | ||
- 1.76.0 | ||
services: | ||
postgres: | ||
image: postgres:14 | ||
env: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: password | ||
POSTGRES_DB: postgres | ||
ports: | ||
- 5432:5432 | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install toolchain | ||
uses: actions-rs/toolchain@v1 | ||
- uses: actions/checkout@v3 | ||
- uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: ${{ matrix.rust }} | ||
override: true | ||
|
||
- name: Install clippy | ||
run: rustup component add clippy | ||
|
||
- name: Run cargo clippy | ||
uses: actions-rs/cargo@v1 | ||
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: 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 | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- 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: | ||
command: clippy | ||
args: -- -D warnings | ||
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: Generate code coverage | ||
run: cargo tarpaulin --verbose --workspace |