Skip to content

Commit d4516d3

Browse files
feat(app): configurable Modrinth endpoints through .env files (#4015)
1 parent 87de47f commit d4516d3

File tree

15 files changed

+95
-49
lines changed

15 files changed

+95
-49
lines changed

.github/workflows/theseus-build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
rename-to: ${{ startsWith(matrix.platform, 'windows') && 'dasel.exe' || 'dasel' }}
7676
chmod: 0755
7777

78-
- name: ⚙️ Set application version
78+
- name: ⚙️ Set application version and environment
7979
shell: bash
8080
run: |
8181
APP_VERSION="$(git describe --tags --always | sed -E 's/-([0-9]+)-(g[0-9a-fA-F]+)$/-canary+\1.\2/')"
@@ -84,6 +84,8 @@ jobs:
8484
dasel put -f packages/app-lib/Cargo.toml -t string -v "${APP_VERSION#v}" 'package.version'
8585
dasel put -f apps/app-frontend/package.json -t string -v "${APP_VERSION#v}" 'version'
8686
87+
cp packages/app-lib/.env.prod packages/app-lib/.env
88+
8789
- name: 💨 Setup Turbo cache
8890
uses: rharkor/[email protected]
8991

.github/workflows/turbo-ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ jobs:
7474
cp .env.local .env
7575
sqlx database setup
7676
77+
- name: ⚙️ Set app environment
78+
working-directory: packages/app-lib
79+
run: cp .env.staging .env
80+
7781
- name: 🔍 Lint and test
7882
run: pnpm run ci
7983

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/app-lib/.env.local

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1-
# SQLite database file location
2-
DATABASE_URL=sqlite:///tmp/Modrinth/code/packages/app-lib/.sqlx/generated/state.db
1+
MODRINTH_URL=http://localhost:3000/
2+
MODRINTH_API_URL=http://127.0.0.1:8000/v2/
3+
MODRINTH_API_URL_V3=http://127.0.0.1:8000/v3/
4+
MODRINTH_SOCKET_URL=ws://127.0.0.1:8000/
5+
MODRINTH_LAUNCHER_META_URL=https://launcher-meta.modrinth.com/
6+
7+
# SQLite database file used by sqlx for type checking. Uncomment this to a valid path
8+
# in your system and run `cargo sqlx database setup` to generate an empty database that
9+
# can be used for developing the app DB schema
10+
#DATABASE_URL=sqlite:///tmp/Modrinth/code/packages/app-lib/.sqlx/generated/state.db

packages/app-lib/.env.prod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
MODRINTH_URL=https://modrinth.com/
2+
MODRINTH_API_URL=https://api.modrinth.com/v2/
3+
MODRINTH_API_URL_V3=https://api.modrinth.com/v3/
4+
MODRINTH_SOCKET_URL=wss://api.modrinth.com/
5+
MODRINTH_LAUNCHER_META_URL=https://launcher-meta.modrinth.com/
6+
7+
# SQLite database file used by sqlx for type checking. Uncomment this to a valid path
8+
# in your system and run `cargo sqlx database setup` to generate an empty database that
9+
# can be used for developing the app DB schema
10+
#DATABASE_URL=sqlite:///tmp/Modrinth/code/packages/app-lib/.sqlx/generated/state.db

packages/app-lib/.env.staging

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
MODRINTH_URL=https://staging.modrinth.com/
2+
MODRINTH_API_URL=https://staging-api.modrinth.com/v2/
3+
MODRINTH_API_URL_V3=https://staging-api.modrinth.com/v3/
4+
MODRINTH_SOCKET_URL=wss://staging-api.modrinth.com/
5+
MODRINTH_LAUNCHER_META_URL=https://launcher-meta.modrinth.com/
6+
7+
# SQLite database file used by sqlx for type checking. Uncomment this to a valid path
8+
# in your system and run `cargo sqlx database setup` to generate an empty database that
9+
# can be used for developing the app DB schema
10+
#DATABASE_URL=sqlite:///tmp/Modrinth/code/packages/app-lib/.sqlx/generated/state.db

packages/app-lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ ariadne.workspace = true
8282
winreg.workspace = true
8383

8484
[build-dependencies]
85+
dotenvy.workspace = true
8586
dunce.workspace = true
8687

8788
[features]

packages/app-lib/build.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,31 @@ use std::process::{Command, exit};
44
use std::{env, fs};
55

66
fn main() {
7+
println!("cargo::rerun-if-changed=.env");
78
println!("cargo::rerun-if-changed=java/gradle");
89
println!("cargo::rerun-if-changed=java/src");
910
println!("cargo::rerun-if-changed=java/build.gradle.kts");
1011
println!("cargo::rerun-if-changed=java/settings.gradle.kts");
1112
println!("cargo::rerun-if-changed=java/gradle.properties");
1213

14+
set_env();
15+
build_java_jars();
16+
}
17+
18+
fn set_env() {
19+
for (var_name, var_value) in
20+
dotenvy::dotenv_iter().into_iter().flatten().flatten()
21+
{
22+
if var_name == "DATABASE_URL" {
23+
// The sqlx database URL is a build-time detail that should not be exposed to the crate
24+
continue;
25+
}
26+
27+
println!("cargo::rustc-env={var_name}={var_value}");
28+
}
29+
}
30+
31+
fn build_java_jars() {
1332
let out_dir =
1433
dunce::canonicalize(PathBuf::from(env::var_os("OUT_DIR").unwrap()))
1534
.unwrap();
@@ -37,6 +56,7 @@ fn main() {
3756
.current_dir(dunce::canonicalize("java").unwrap())
3857
.status()
3958
.expect("Failed to wait on Gradle build");
59+
4060
if !exit_status.success() {
4161
println!("cargo::error=Gradle build failed with {exit_status}");
4262
exit(exit_status.code().unwrap_or(1));

packages/app-lib/src/api/mr_auth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::state::ModrinthCredentials;
22

33
#[tracing::instrument]
4-
pub fn authenticate_begin_flow() -> String {
4+
pub fn authenticate_begin_flow() -> &'static str {
55
crate::state::get_login_url()
66
}
77

packages/app-lib/src/config.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)