Skip to content

Commit c5172a9

Browse files
committed
Chapter 5
1 parent bd8bf50 commit c5172a9

20 files changed

+536
-234
lines changed

.dockerignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.env
2+
target/
3+
tests/
4+
Dockerfile
5+
scripts/
6+
migrations/

.github/workflows/general.yaml

+7-39
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,60 @@
1-
# The name of your workflow. GitHub displays the names of your workflows on your repository's "Actions" tab
21
name: Rust
32

4-
# To automatically trigger the workflow
5-
on: [push, pull_request]
3+
on: [ push, pull_request ]
64

75
env:
86
CARGO_TERM_COLOR: always
97
SQLX_VERSION: 0.7.1
108
SQLX_FEATURES: "rustls,postgres"
119

12-
# A workflow run is made up of one or more jobs, which run in parallel by default
13-
# Each job runs in a runner environment specified by runs-on
1410
jobs:
15-
# Unique identifier of our job (`job_id`)
1611
test:
17-
# Sets the name `Test` for the job, which is displayed in the GitHub UI
1812
name: Test
19-
# Containers must run in Linux based operating systems
2013
runs-on: ubuntu-latest
21-
# Service containers to run with the `test` container job
2214
services:
23-
# Label used to access the service container
2415
postgres:
25-
# Docker Hub image
2616
image: postgres:14
27-
# Environment variables scoped only for the `postgres` element
2817
env:
2918
POSTGRES_USER: postgres
3019
POSTGRES_PASSWORD: password
3120
POSTGRES_DB: postgres
32-
# When you map ports using the ports keyword, GitHub uses the --publish command to publish the container’s ports to the Docker host
33-
# Opens tcp port 5432 on the host and service container
3421
ports:
3522
- 5432:5432
3623
steps:
37-
# Downloads a copy of the code in your repository before running CI tests
3824
- name: Check out repository code
39-
# The uses keyword specifies that this step will run v3 of the actions/checkout action.
40-
# This is an action that checks out your repository onto the runner, allowing you to run scripts or other actions against your code (such as build and test tools).
41-
# You should use the checkout action any time your workflow will run against the repository's code.
4225
uses: actions/checkout@v3
43-
44-
# This GitHub Action installs a Rust toolchain using rustup. It is designed for one-line concise usage and good defaults.
4526
- name: Install the Rust toolchain
4627
uses: dtolnay/rust-toolchain@stable
47-
48-
# A GitHub Action that implements smart caching for rust/cargo projects with sensible defaults.
4928
- name: Rust Cache Action
5029
uses: Swatinem/rust-cache@v2
5130
with:
52-
# An additional cache key that is added alongside the automatic `job`-based cache key and can be used to further differentiate jobs. default: empty
5331
key: sqlx-${{ env.SQLX_VERSION }}
54-
5532
- name: Install sqlx-cli
5633
run:
5734
cargo install sqlx-cli
5835
--version=${{ env.SQLX_VERSION }}
5936
--features ${{ env.SQLX_FEATURES }}
6037
--no-default-features
6138
--locked
62-
# The --locked flag can be used to force Cargo to use the packaged Cargo.lock file if it is available.
63-
# This may be useful for ensuring reproducible builds, to use the exact same set of dependencies that were available when the package was published.
64-
# 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
65-
66-
- name: Install postgresql-client
67-
run: sudo apt-get update && sudo apt-get install postgresql-client -y
68-
6939
- name: Migrate database
7040
run: SKIP_DOCKER=true ./scripts/init_db.sh
71-
41+
- name: Check sqlx-data.json is up-to-date
42+
run: |
43+
cargo sqlx prepare --workspace --check
7244
- name: Run tests
7345
run: cargo test
7446

75-
# `fmt` container job
7647
fmt:
7748
name: Rustfmt
7849
runs-on: ubuntu-latest
7950
steps:
8051
- uses: actions/checkout@v3
8152
- uses: dtolnay/rust-toolchain@stable
8253
with:
83-
# Specific to dtolnay/rust-toolchain: Comma-separated string of additional components to install
8454
components: rustfmt
8555
- name: Enforce formatting
8656
run: cargo fmt --check
8757

88-
# `clippy` container job
8958
clippy:
9059
name: Clippy
9160
runs-on: ubuntu-latest
@@ -113,14 +82,11 @@ jobs:
11382
--features ${{ env.SQLX_FEATURES }}
11483
--no-default-features
11584
--locked
116-
- name: Install postgresql-client
117-
run: sudo apt-get update && sudo apt-get install postgresql-client -y
11885
- name: Migrate database
11986
run: SKIP_DOCKER=true ./scripts/init_db.sh
12087
- name: Linting
12188
run: cargo clippy -- -D warnings
12289

123-
# `coverage` container job
12490
coverage:
12591
name: Code coverage
12692
runs-on: ubuntu-latest
@@ -142,6 +108,8 @@ jobs:
142108
- uses: Swatinem/rust-cache@v2
143109
with:
144110
key: sqlx-${{ env.SQLX_VERSION }}
111+
- name: Install tarpaulin
112+
run: cargo install cargo-tarpaulin
145113
- name: Install sqlx-cli
146114
run:
147115
cargo install sqlx-cli
@@ -152,4 +120,4 @@ jobs:
152120
- name: Migrate database
153121
run: SKIP_DOCKER=true ./scripts/init_db.sh
154122
- name: Generate code coverage
155-
run: cargo install cargo-tarpaulin && cargo tarpaulin --verbose --workspace
123+
run: cargo tarpaulin --verbose --workspace

.idea/.gitignore

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/zero2prod.iml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.sqlx/query-bcfcfebc6f5e8ffbf97d97c5a209be78b46d703924482cf8b43842705fcb7714.json

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)