mirror of
https://gitlab.com/Anson-Projects/wiki-location-bot.git
synced 2025-06-15 14:46:39 +00:00
Add CI/CD to project
This commit is contained in:
parent
e92f593c80
commit
33847a2008
30
.gitlab-ci.yml
Normal file
30
.gitlab-ci.yml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
build:main:
|
||||||
|
stage: build
|
||||||
|
image:
|
||||||
|
name: gcr.io/kaniko-project/executor:v1.9.0-debug
|
||||||
|
entrypoint: [""]
|
||||||
|
script:
|
||||||
|
- /kaniko/executor
|
||||||
|
--context "${CI_PROJECT_DIR}"
|
||||||
|
--dockerfile "${CI_PROJECT_DIR}/Dockerfile"
|
||||||
|
--destination "${CI_REGISTRY_IMAGE}:latest"
|
||||||
|
--destination "${CI_REGISTRY_IMAGE}:stable"
|
||||||
|
--destination "${CI_REGISTRY_IMAGE}:dev"
|
||||||
|
rules:
|
||||||
|
- if: '$CI_COMMIT_BRANCH == "main"'
|
||||||
|
|
||||||
|
|
||||||
|
build:branch:
|
||||||
|
stage: build
|
||||||
|
image:
|
||||||
|
name: gcr.io/kaniko-project/executor:v1.9.0-debug
|
||||||
|
entrypoint: [""]
|
||||||
|
script:
|
||||||
|
- /kaniko/executor
|
||||||
|
--context "${CI_PROJECT_DIR}"
|
||||||
|
--dockerfile "${CI_PROJECT_DIR}/Dockerfile"
|
||||||
|
--destination "${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}"
|
||||||
|
--destination "${CI_REGISTRY_IMAGE}:${CI_COMMIT_BRANCH}"
|
||||||
|
--destination "${CI_REGISTRY_IMAGE}:dev"
|
||||||
|
rules:
|
||||||
|
- if: '$CI_COMMIT_BRANCH != "main"'
|
26
Cargo.lock
generated
26
Cargo.lock
generated
@ -993,19 +993,6 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rust"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"log",
|
|
||||||
"pretty_env_logger",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"teloxide",
|
|
||||||
"tokio",
|
|
||||||
"ureq",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-demangle"
|
name = "rustc-demangle"
|
||||||
version = "0.1.23"
|
version = "0.1.23"
|
||||||
@ -1693,6 +1680,19 @@ dependencies = [
|
|||||||
"rustls-webpki 0.100.1",
|
"rustls-webpki 0.100.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wiki_location_bot"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"pretty_env_logger",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"teloxide",
|
||||||
|
"tokio",
|
||||||
|
"ureq",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rust"
|
name = "wiki_location_bot"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
teloxide = { version = "0.12", features = ["macros"] }
|
teloxide = { version = "0.12.2", features = ["macros"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
pretty_env_logger = "0.5.0"
|
pretty_env_logger = "0.5.0"
|
||||||
tokio = { version = "1.8", features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "1.8", features = ["rt-multi-thread", "macros"] }
|
||||||
|
14
Dockerfile
Normal file
14
Dockerfile
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
FROM rust:1.70 as builder
|
||||||
|
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN cargo build --release
|
||||||
|
|
||||||
|
FROM debian:bullseye-slim
|
||||||
|
|
||||||
|
COPY --from=builder /usr/src/app/target/release/wiki_location_bot .
|
||||||
|
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
|
||||||
|
CMD ["./wiki_location_bot"]
|
6
docker-compose.yml
Normal file
6
docker-compose.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
version: "3"
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
build: .
|
||||||
|
|
||||||
|
# docker-compose up --build app
|
16
src/main.rs
16
src/main.rs
@ -21,9 +21,9 @@ pub struct GeoSearch {
|
|||||||
pageid: usize,
|
pageid: usize,
|
||||||
ns: usize,
|
ns: usize,
|
||||||
title: String,
|
title: String,
|
||||||
lat: Option<f64>,
|
lat: f64,
|
||||||
lon: Option<f64>,
|
lon: f64,
|
||||||
dist: Option<f32>,
|
dist: f32,
|
||||||
primary: Option<bool>,
|
primary: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,28 +52,24 @@ async fn main() {
|
|||||||
match msg.location() {
|
match msg.location() {
|
||||||
Some(user_location) => {
|
Some(user_location) => {
|
||||||
log::info!("Location received.");
|
log::info!("Location received.");
|
||||||
bot.send_message(msg.chat.id, "Searching for nearby locations...");
|
bot.send_message(msg.chat.id, "Searching for nearby locations...").await?;
|
||||||
|
|
||||||
let nearby_locations =
|
let nearby_locations =
|
||||||
ureq::get(&format!("https://en.wikipedia.org/w/api.php?action=query&format=json&list=geosearch&formatversion=2&gscoord={}|{}&gsradius=10000&gslimit=5",user_location.latitude,user_location.longitude))
|
ureq::get(&format!("https://en.wikipedia.org/w/api.php?action=query&format=json&list=geosearch&formatversion=2&gscoord={}|{}&gsradius=10000&gslimit=5",user_location.latitude,user_location.longitude))
|
||||||
.call()
|
.call()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into_json::<Root>().unwrap().query.geosearch.unwrap();
|
.into_json::<Root>().unwrap().query.geosearch.unwrap();
|
||||||
|
|
||||||
|
|
||||||
// Not working, and also the wikipedia API is so fast its not necessary.
|
// Not working, and also the wikipedia API is so fast its not necessary.
|
||||||
// bot.send_chat_action(msg.chat.id,teloxide::types::ChatAction::FindLocation).await?;
|
// bot.send_chat_action(msg.chat.id,teloxide::types::ChatAction::FindLocation).await?;
|
||||||
for location in nearby_locations {
|
for location in nearby_locations {
|
||||||
|
|
||||||
bot.send_location(msg.chat.id,location.lat.unwrap(),location.lon.unwrap()).await?;
|
bot.send_location(msg.chat.id,location.lat,location.lon).await?;
|
||||||
|
|
||||||
let url = teloxide::utils::markdown::link(&format!("http://en.wikipedia.org/?curid={}",location.pageid),&location.title);
|
let url = teloxide::utils::markdown::link(&format!("http://en.wikipedia.org/?curid={}",location.pageid),&location.title);
|
||||||
let bold_url = teloxide::utils::markdown::bold(&url);
|
let bold_url = teloxide::utils::markdown::bold(&url);
|
||||||
|
|
||||||
bot.send_message(msg.chat.id, bold_url).parse_mode(teloxide::types::ParseMode::MarkdownV2).await?;
|
bot.send_message(msg.chat.id, bold_url).parse_mode(teloxide::types::ParseMode::MarkdownV2).await?;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user