Skip to content

Commit c0401b1

Browse files
jyn514Joshua Nelson
authored and
Joshua Nelson
committed
Use docker for CI
This gives a consistent environment and means we only have to update things in one place. It also makes sure that we're testing the commands that new contributors run.
1 parent 6127c87 commit c0401b1

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,39 @@ jobs:
4949
restore-key: |
5050
${{ runner.os }}-cargo-build-target-${{ env.CURRENT_RUSTC_VERSION }}-
5151
52-
- name: Install PostgreSQL
52+
- name: Prepare the test environment
5353
run: |
54-
sudo apt-get update && DEBIAN_FRONTEND=noninteractive sudo apt-get install -y postgresql
55-
sudo systemctl start postgresql
56-
sudo -u postgres createuser $(whoami) -w
57-
sudo -u postgres createdb $(whoami) -O $(whoami)
58-
echo "::set-env name=CRATESFYI_DATABASE_URL::postgresql://$(whoami)@%2Fvar%2Frun%2Fpostgresql/$(whoami)"
54+
prefix=$(pwd)/ignored/prefix
55+
mkdir -p ${prefix}/public-html
56+
echo "::set-env name=CRATESFYI_PREFIX::${prefix}"
5957
60-
- name: Build docs.rs
61-
run: cargo build --locked
58+
- name: Launch the postgres image
59+
run: |
60+
touch .env
61+
docker-compose up -d db
62+
# TODO: try to avoid hard-coding this username/password
63+
export CRATESFYI_DATABASE_URL="postgresql://cratesfyi:password@localhost:5432/"
64+
# Make sure the database is actually working
65+
# Give the database enough time to start up
66+
sleep 5
67+
psql "$CRATESFYI_DATABASE_URL"
68+
echo "::set-env name=CRATESFYI_DATABASE_URL::${CRATESFYI_DATABASE_URL}"
6269
6370
- name: Run rustfmt
6471
run: cargo fmt -- --check
6572

6673
- name: Run clippy
67-
run: cargo clippy -- -D warnings
74+
run: cargo clippy --locked -- -D warnings
6875

69-
- name: Prepare the test environment
70-
run: |
71-
prefix=$(pwd)/ignored/prefix
72-
mkdir -p ${prefix}/public-html
73-
echo "::set-env name=CRATESFYI_PREFIX::${prefix}"
76+
- name: Build docs.rs
77+
run: cargo build --locked
7478

7579
- name: Test docs.rs
7680
run: cargo test --locked -- --test-threads=1
7781

82+
- name: Clean up the database
83+
run: docker-compose down --volumes
84+
7885
docker:
7986
name: Docker
8087
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)