Skip to content

Commit 32e566c

Browse files
committed
more clean
1 parent 8077680 commit 32e566c

File tree

6 files changed

+69
-37
lines changed

6 files changed

+69
-37
lines changed

.env.tests

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# environment variables to run our tests
2+
# when running tests outside docker, locally or in CI,
3+
# makes the test use the needed resources defined in our docker-compose file
4+
DOCSRS_DATABASE_URL=postgresql://cratesfyi:password@localhost:15432
5+
AWS_ACCESS_KEY_ID=cratesfyi
6+
AWS_SECRET_ACCESS_KEY=secret_key
7+
S3_ENDPOINT=http://localhost:9000

.github/workflows/ci.yml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,7 @@ on:
99
- cron: "0 0 * * *"
1010

1111
env:
12-
RUST_BACKTRACE: 1
1312
RUST_CACHE_KEY: rust-cache-20241114
14-
DOCSRS_PREFIX: ignored/cratesfyi-prefix
15-
DOCSRS_DATABASE_URL: postgresql://cratesfyi:password@localhost:15432
16-
DOCSRS_LOG: docs_rs=debug,rustwide=info
17-
AWS_ACCESS_KEY_ID: cratesfyi
18-
AWS_SECRET_ACCESS_KEY: secret_key
19-
S3_ENDPOINT: http://localhost:9000
20-
DOCSRS_INCLUDE_DEFAULT_TARGETS: false
21-
DOCSRS_DOCKER_IMAGE: ghcr.io/rust-lang/crates-build-env/linux-micro
22-
SENTRY_ENVIRONMENT: dev
2313

2414
jobs:
2515
sqlx:
@@ -48,7 +38,7 @@ jobs:
4838
uses: docker/setup-buildx-action@v3
4939

5040
- name: Launch postgres
51-
run: just ensure_db_and_s3_are_running
41+
run: just _ensure_db_and_s3_are_running
5242

5343
- name: install SQLX CLI
5444
run: cargo binstall sqlx-cli
@@ -98,11 +88,6 @@ jobs:
9888
steps:
9989
- uses: actions/checkout@v5
10090

101-
- name: restore build & cargo cache
102-
uses: Swatinem/rust-cache@v2
103-
with:
104-
prefix-key: ${{ env.RUST_CACHE_KEY }}
105-
10691
- name: Set up Docker Buildx
10792
uses: docker/setup-buildx-action@v3
10893

@@ -116,7 +101,7 @@ jobs:
116101
if: ${{ always() }}
117102
run: just compose-down-and-wipe
118103

119-
rslint:
104+
lint-rs:
120105
name: rust linters
121106
runs-on: ubuntu-latest
122107

@@ -136,11 +121,14 @@ jobs:
136121

137122
- run: just lint
138123

139-
eslint:
124+
lint-js:
140125
runs-on: ubuntu-latest
141126
steps:
142127
- uses: actions/checkout@v5
128+
143129
- uses: denoland/setup-deno@v2
130+
144131
- name: install `just`
145132
run: sudo snap install --edge --classic just
133+
146134
- run: just lint-js

justfiles/cli.just

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88

99
# low-level helper to run any CLI command in its own one-off docker container,
1010
# ensuring that `db` and `s3` are running.
11-
_cli service_name *args: _touch-docker-env ensure_db_and_s3_are_running
11+
_cli service_name *args: _touch-docker-env _ensure_db_and_s3_are_running
1212
# dependencies in the docker-compose file are ignored
1313
# when running a one-off service with `docker compose run`.
1414
# Instead we explicitly start any dependent services first via
15-
# `ensure_db_and_s3_are_running`.
15+
# `_ensure_db_and_s3_are_running`.
1616

1717
docker compose run --build --rm {{ service_name }} {{ args }}
1818

1919
# run any CLI command in its own one-off `cli` docker container. Args are passed to the container.
2020
# Only for commands that just need `db` and `s3` and minimal system dependencies.
2121
[group('cli')]
22-
cli +args: _touch-docker-env cli-db-migrate
22+
cli +args: _touch-docker-env cli-db-migrate
2323
just _cli cli {{ args }}
2424

2525
# Initialize the `docs.rs` database
@@ -36,48 +36,51 @@ cli-db-migrate:
3636
# add a release to the build queue
3737
[group('cli')]
3838
[group('queue')]
39-
cli-queue-add +args:
39+
cli-queue-add crate_name crate_version:
4040
# only does things with the database, so can use the lightweight `cli` container.
41-
just cli queue add {{ args }}
41+
just cli queue add {{ crate_name }} {{ crate_version }}
4242

4343
# run builder CLI command in its own one-off `build-server` docker container.
4444
# Uses a separate builder-cli container & workspace that doesn't conflict
4545
# with the continiously running build-servers.
4646
[group('cli')]
47-
[group('build')]
47+
[group('builder')]
4848
cli-build +args: _touch-docker-env cli-db-migrate
4949
just _cli builder-cli {{ args }}
5050

5151
# set the nightly rust version to be used for builds. Format: `nightly-YYYY-MM-DD`
5252
# or just `nightly` for always using the latest nightly.
5353
[group('cli')]
54-
[group('build')]
54+
[group('builder')]
5555
cli-build-set-toolchain name only_first_time="false":
56+
#!/usr/bin/env bash
57+
set -euo pipefail
58+
5659
FLAG=""
5760
if [ "{{only_first_time}}" = "true" ]; then FLAG="--only-first-time"; fi
5861
just cli-build build set-toolchain {{ name }} $FLAG
5962

6063
# update the toolchain in the builders
6164
[group('cli')]
62-
[group('build')]
65+
[group('builder')]
6366
cli-build-update-toolchain:
6467
just cli-build build update-toolchain
6568

6669
# build & upload toolchain shared static resources
6770
[group('cli')]
68-
[group('build')]
71+
[group('builder')]
6972
cli-build-add-essential-files:
7073
just cli-build build add-essential-files
7174

7275
# build a release
7376
[group('cli')]
74-
[group('build')]
77+
[group('builder')]
7578
cli-build-crate name version:
7679
just cli-build build crate {{ name }} {{ version }}
7780

7881
# run registry-watcher CLI command in its own one-off `registry-watcher` docker container.
7982
[group('cli')]
80-
[group('registry-watcher')]
83+
[group('watcher')]
8184
cli-watcher +args: _touch-docker-env cli-db-migrate
8285
just _cli registry-watcher-cli {{ args }}
8386

justfiles/services.just

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ compose-up-web:
1010

1111
# Launch two build servers in the background
1212
[group('compose')]
13+
[group('builder')]
1314
compose-up-builder:
1415
just compose-up builder
1516

1617
# Launch registry watcher in the background
1718
[group('compose')]
19+
[group('watcher')]
1820
compose-up-watcher:
1921
just compose-up watcher
2022

@@ -37,6 +39,7 @@ compose-down:
3739
[group('compose')]
3840
compose-down-and-wipe:
3941
#!/usr/bin/env bash
42+
set -euo pipefail
4043

4144
docker compose --profile full --profile manual down --volumes --remove-orphans --rmi local
4245

@@ -58,4 +61,4 @@ compose-down-and-wipe:
5861
# stream logs from all services running in docker-compose. Optionally specify services to tail logs from.
5962
[group('compose')]
6063
compose-logs *services:
61-
docker compose --profile full --profile manual logs -f {{ services }}
64+
docker compose --profile full logs -f {{ services }}

justfiles/testing.just

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
# just commands for CI & local development
22

3+
4+
5+
[group('testing')]
36
sqlx-prepare *args:
47
cargo sqlx prepare \
58
--database-url $DOCSRS_DATABASE_URL \
69
--workspace {{ args }} \
710
-- --all-targets --all-features
811

12+
[group('testing')]
913
sqlx-check:
1014
just sqlx-prepare -check
1115

1216
# Format the code using `cargo fmt`.
17+
[group('testing')]
1318
format:
1419
rustup component add rustfmt
1520
# like this we get both the non-zero exit code, and the local code is
1621
# formatted.
1722
cargo fmt --all -- --check || { cargo fmt --all && exit 1; }
1823

24+
# run clippy, in our config
25+
[group('testing')]
1926
clippy *args:
2027
rustup component add clippy
2128
cargo clippy \
@@ -26,23 +33,30 @@ clippy *args:
2633
{{ args }} \
2734
-- -D warnings
2835

36+
# run clippy --fix
37+
[group('testing')]
2938
clippy-fix:
3039
just clippy --fix --allow-dirty --allow-staged
3140

3241
# run all linters, for local development & CI
42+
[group('testing')]
3343
lint: format
3444
#!/usr/bin/env bash
45+
set -euo pipefail
46+
3547
if [ "$GITHUB_ACTIONS" = "true" ]; then
3648
just clippy
3749
else
3850
just clippy_fix
3951
fi
4052

4153

54+
[group('testing')]
4255
lint-js *args:
4356
deno run -A npm:eslint@9 static templates gui-tests eslint.config.js {{ args }}
4457

45-
run-gui-tests: ensure_db_and_s3_are_running cli-db-migrate compose-up-web
58+
[group('testing')]
59+
run-gui-tests: _ensure_db_and_s3_are_running cli-db-migrate compose-up-web
4660
just cli-build-update-toolchain
4761
just cli-build-crate sysinfo 0.23.4
4862
just cli-build-crate sysinfo 0.23.5
@@ -51,18 +65,35 @@ run-gui-tests: ensure_db_and_s3_are_running cli-db-migrate compose-up-web
5165

5266
just _cli gui_tests
5367

54-
# build binaries for all tests
55-
build-tests:
68+
_build-test-binaries:
69+
#!/usr/bin/env bash
70+
set -euo pipefail
71+
72+
export SQLX_OFFLINE=1
5673
cargo test --no-run --workspace --locked
5774

75+
[group('testing')]
76+
run-tests: _ensure_db_and_s3_are_running _build-test-binaries
77+
#!/usr/bin/env bash
78+
set -euo pipefail
79+
80+
export $(grep -v '^#' .env.tests | xargs)
81+
export DOCSRS_INCLUDE_DEFAULT_TARGETS=false
82+
export DOCSRS_LOG=docs_rs=debug,rustwide=info
83+
export RUST_BACKTRACE=1
5884

59-
run-tests: ensure_db_and_s3_are_running build-tests
6085
cargo test --workspace --locked --no-fail-fast
6186

62-
run-builder-tests: ensure_db_and_s3_are_running build-tests
63-
#!/bin/bash
87+
[group('testing')]
88+
[group('builder')]
89+
run-builder-tests: _ensure_db_and_s3_are_running _build-test-binaries
90+
#!/usr/bin/env bash
6491
set -euo pipefail
6592

93+
export $(grep -v '^#' .env.tests | xargs)
6694
export DOCSRS_INCLUDE_DEFAULT_TARGETS=true
95+
export DOCSRS_DOCKER_IMAGE=ghcr.io/rust-lang/crates-build-env/linux-micro
96+
export DOCSRS_LOG=docs_rs=debug,rustwide=info
97+
export RUST_BACKTRACE=1
6798

6899
cargo test --locked -- --ignored --test-threads=1

justfiles/utils.just

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
ensure_db_and_s3_are_running: _touch-docker-env
2+
_ensure_db_and_s3_are_running: _touch-docker-env
33
# dependencies in the docker-cli file are ignored
44
# here. Instead we explicitly start any dependent services first.
55
docker compose up -d db s3 --wait

0 commit comments

Comments
 (0)