Skip to content

Commit 3012f47

Browse files
committed
ci: add tests and update CI file
1 parent d918956 commit 3012f47

File tree

20 files changed

+873
-186
lines changed

20 files changed

+873
-186
lines changed

.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
DATABASE_URL=sqlite:data/bot.db
1+
DATABASE_URL=sqlite:data/bot.db
2+
CONFIG_PATH=data/config.yaml

.github/workflows/ci.yml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ on:
99

1010
env:
1111
CARGO_TERM_COLOR: always
12-
DATABASE_URL: sqlite:data/bot.db
12+
DATABASE_URL: sqlite:/tmp/bot.db
13+
CONFIG_PATH: /tmp/config.yaml
1314
REGISTRY: ghcr.io
1415
IMAGE_NAME: ${{ github.repository }}
1516

@@ -28,12 +29,12 @@ jobs:
2829
- name: Cache dependencies
2930
uses: Swatinem/rust-cache@v2
3031

31-
- name: Create data directory
32-
run: mkdir -p data
32+
- name: Copy config
33+
run: cp config.example.yaml /tmp/config.yaml
3334

3435
- name: Install sqlx-cli
3536
run: cargo install sqlx-cli
36-
37+
3738
- name: Create database
3839
run: |
3940
sqlx database create
@@ -59,15 +60,26 @@ jobs:
5960

6061
- name: Cache dependencies
6162
uses: Swatinem/rust-cache@v2
63+
64+
- name: Copy config
65+
run: cp config.example.yaml /tmp/config.yaml
66+
67+
- name: Install sqlx-cli
68+
run: cargo install sqlx-cli
69+
70+
- name: Create database
71+
run: |
72+
sqlx database create
73+
sqlx migrate run
6274
6375
- name: Build
6476
run: cargo build --release
6577

6678
- name: Upload artifacts
6779
uses: actions/upload-artifact@v4
6880
with:
69-
name: invitationbot
70-
path: target/release/invitationbot
81+
name: InvitationBot
82+
path: target/release/InvitationBot
7183

7284
release:
7385
name: Release
@@ -82,20 +94,17 @@ jobs:
8294
- name: Download artifact
8395
uses: actions/download-artifact@v4
8496
with:
85-
name: invitationbot
97+
name: InvitationBot
8698
path: ./
8799

88100
- name: Make binary executable
89-
run: chmod +x invitationbot
101+
run: chmod +x InvitationBot
90102

91103
- name: Create Release
92104
uses: softprops/action-gh-release@v1
93105
with:
94106
files: |
95-
invitationbot
96-
LICENSE
97-
README.md
98-
config.example.yaml
107+
InvitationBot
99108
generate_release_notes: true
100109

101110
docker:

Cargo.lock

Lines changed: 38 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@ axum = "0.8.1"
1515
tower-http = { version = "0.6.2", features = ["cors"] }
1616
chrono = { version = "0.4", features = ["serde"] }
1717
once_cell = "1.20.2"
18-
rust-embed = "8.0"
18+
rust-embed = "8.0"
19+
20+
[dev-dependencies]
21+
tempfile = "3.9"
22+
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
23+
uuid = { version = "1.0", features = ["v4"] }
24+
tower = { version = "0.4", features = ["util"] }

Dockerfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM rust:1.75-slim-bookworm as builder
1+
FROM rust:1.83-slim-bookworm as builder
22

33
WORKDIR /usr/src/app
44
COPY . .
@@ -8,18 +8,24 @@ RUN apt-get update && apt-get install -y \
88
libssl-dev \
99
&& rm -rf /var/lib/apt/lists/*
1010

11+
ENV DATABASE_URL=sqlite:/tmp/bot.db
12+
RUN cargo install sqlx-cli && \
13+
sqlx database create && \
14+
sqlx migrate run
15+
1116
RUN cargo build --release
1217

1318
# Use distroless as runtime image
1419
FROM gcr.io/distroless/cc-debian12
1520

1621
WORKDIR /app
1722

18-
COPY --from=builder /usr/src/app/target/release/invitationbot /app/
23+
COPY --from=builder /usr/src/app/target/release/InvitationBot /app/
1924
COPY --from=builder /usr/src/app/migrations /app/migrations
2025

2126
ENV DATABASE_URL=sqlite:data/bot.db
27+
ENV CONFIG_PATH=data/config.yaml
2228

2329
VOLUME ["/app/data"]
2430
USER nonroot
25-
ENTRYPOINT ["/app/invitationbot"]
31+
ENTRYPOINT ["/app/InvitationBot"]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ cp config.example.yaml data/config.yaml
3535

3636
# Set up the database
3737
echo "DATABASE_URL=sqlite:data/bot.db" > .env
38+
echo "CONFIG_PATH=data/config.yaml" >> .env
3839
cargo install sqlx-cli
3940
sqlx database create
4041
sqlx migrate run

src/handlers/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use poise::serenity_prelude::{self as serenity};
21
use crate::Data;
2+
use poise::serenity_prelude::{self as serenity};
33

44
pub async fn handle_guild_member_addition(
55
ctx: &serenity::Context,
@@ -11,7 +11,9 @@ pub async fn handle_guild_member_addition(
1111
if let Ok(invites) = guild_id.invites(&ctx.http).await {
1212
for invite in invites {
1313
// Check if this is our invite code
14-
if let Ok(Some(invite_id)) = crate::utils::db::find_invite_by_code(&data.db, &invite.code).await {
14+
if let Ok(Some(invite_id)) =
15+
crate::utils::db::find_invite_by_code(&data.db, &invite.code).await
16+
{
1517
// Check if this invite is set to 2 uses, has been used once, and was created by us
1618
// If these conditions are met, we can assume this invite was used by the new member
1719
if invite.max_uses == 2 && invite.uses == 1 {
@@ -20,13 +22,14 @@ pub async fn handle_guild_member_addition(
2022
&data.db,
2123
&invite_id,
2224
&new_member.user.id.to_string(),
23-
).await;
24-
25+
)
26+
.await;
27+
2528
// Delete the invite link
2629
let _ = invite.delete(&ctx.http).await;
2730
break;
2831
}
2932
}
3033
}
3134
}
32-
}
35+
}

0 commit comments

Comments
 (0)