ci: finalize ci implementation

This commit is contained in:
Tyler Wilding
2025-02-26 20:22:02 -05:00
parent 3bcc24cc3b
commit 2befe7c462
13 changed files with 80 additions and 23 deletions

4
.gitattributes vendored Normal file
View File

@@ -0,0 +1,4 @@
# Ensure line endings are consistently 'LF'
* text=auto
.sqlx/**/* linguist-generated

View File

@@ -27,9 +27,7 @@ jobs:
shared-key: web-api-build-ubuntu-latest
- name: Check Rust formatting
run: |
cd src-tauri/
cargo fmt --all --check
run: cargo fmt --all --check
linter:
name: Linter

View File

@@ -0,0 +1,20 @@
{
"db_name": "SQLite",
"query": "\n SELECT version FROM releases;\n ",
"describe": {
"columns": [
{
"name": "version",
"ordinal": 0,
"type_info": "Text"
}
],
"parameters": {
"Right": 0
},
"nullable": [
false
]
},
"hash": "2dd2301f84c890ffe8af5abc5822cf6a712213bf06aa1bf744d4ebc69636a2c2"
}

View File

@@ -1,6 +1,6 @@
# PCSX2 API
TODO
TODO
## Development

View File

@@ -3,7 +3,7 @@ version: '3'
services:
pcsx2-api:
container_name: api
image: pcsx2-api:latest
image: ghcr.io/PCSX2/web-api:latest
ports:
- "8000:8000"
volumes:

View File

@@ -97,7 +97,10 @@ impl ReleaseV1 {
}
cleaned_tags = cleaned_tags
.into_iter()
.filter(|tag| !tag.to_lowercase().contains("32bit") && !tag.to_lowercase().contains("64"))
.filter(|tag| {
!tag.to_lowercase().contains("32bit")
&& !tag.to_lowercase().contains("64")
})
.collect();
} else if k.clone().to_lowercase().contains("linux") {
display_name = "Linux".to_owned();

View File

@@ -1,13 +1,25 @@
pub async fn get_latest_official_version() -> Result<String, octocrab::Error> {
let octocrab = octocrab::instance();
// TODO - probably handle potential errors
let release = octocrab.repos("PCSX2", "pcsx2").releases().list().per_page(1).send().await?;
let release = octocrab
.repos("PCSX2", "pcsx2")
.releases()
.list()
.per_page(1)
.send()
.await?;
return Ok(release.items.first().unwrap().tag_name.clone());
}
pub async fn get_latest_archive_version() -> Result<String, octocrab::Error> {
let octocrab = octocrab::instance();
// TODO - probably handle potential errors
let release = octocrab.repos("PCSX2", "archive").releases().list().per_page(1).send().await?;
let release = octocrab
.repos("PCSX2", "archive")
.releases()
.list()
.per_page(1)
.send()
.await?;
return Ok(release.items.first().unwrap().tag_name.clone());
}
}

2
src/external/mod.rs vendored
View File

@@ -1 +1 @@
pub mod github;
pub mod github;

View File

@@ -26,7 +26,11 @@ impl Fairing for CORSHeaderFairing {
async fn on_response<'r>(&self, request: &'r Request<'_>, response: &mut Response<'r>) {
if let Some(origin) = request.headers().get_one("Origin") {
if origin == "https://pcsx2.net" || origin.starts_with("http://localhost") || origin.starts_with("https://localhost") || CF_PAGES_REGEX.is_match(origin) {
if origin == "https://pcsx2.net"
|| origin.starts_with("http://localhost")
|| origin.starts_with("https://localhost")
|| CF_PAGES_REGEX.is_match(origin)
{
response.set_raw_header("Access-Control-Allow-Origin", "*");
} else {
info!("Rejecting request from origin: {}", origin);

View File

@@ -1,10 +1,10 @@
mod api;
mod external;
mod fairings;
mod guards;
mod responders;
mod storage;
mod util;
mod external;
use fern::colors::{Color, ColoredLevelConfig};
#[macro_use]
@@ -59,7 +59,8 @@ impl RateLimiterCache {
}
fn setup_logging() {
let verbose_logging = dotenvy::var("VERBOSE_LOGGING").map_or(false, |val| val.to_lowercase().eq("true"));
let verbose_logging =
dotenvy::var("VERBOSE_LOGGING").map_or(false, |val| val.to_lowercase().eq("true"));
let error_log_path = dotenvy::var("ERROR_LOG_PATH").expect("ERROR_LOG_PATH must be set");
let app_log_path = dotenvy::var("APP_LOG_PATH").expect("APP_LOG_PATH must be set");
let mut log_level = log::LevelFilter::Warn;
@@ -86,7 +87,7 @@ fn setup_logging() {
color_line = format_args!(
"\x1B[{}m",
colors_line.get_color(&record.level()).to_fg_str()
),
),
date = chrono::Utc::now().to_rfc3339_opts(SecondsFormat::Millis, true),
level = record.level(),
target = record.target(),
@@ -126,7 +127,9 @@ async fn main() -> Result<(), rocket::Error> {
// Check to see if the database is out of date (pull latest releases)
// do this only if we have the github api credential set
if dotenvy::var("GITHUB_API_TOKEN").is_ok() {
let octocrab = octocrab::Octocrab::builder().personal_token(dotenvy::var("GITHUB_API_TOKEN").unwrap()).build();
let octocrab = octocrab::Octocrab::builder()
.personal_token(dotenvy::var("GITHUB_API_TOKEN").unwrap())
.build();
octocrab::initialise(octocrab.unwrap());
storage::sync::sync_database(&db).await;
}

View File

@@ -1,4 +1,4 @@
pub mod models;
pub mod sqlite;
pub mod sync;
pub mod v1;
pub mod sync;

View File

@@ -82,7 +82,8 @@ impl ReleaseRow {
if github_release.body.is_some() && github_release.body.contains("DATE_OVERRIDE") {
let regexp = Regex::new(r"DATE_OVERRIDE:\s?(\d{4}-\d{2}-\d{2})").unwrap();
let release_body = github_release.body.clone().unwrap_or("".to_string());
let matches: Vec<&str> = regexp.captures_iter(&release_body)
let matches: Vec<&str> = regexp
.captures_iter(&release_body)
.filter_map(|cap| cap.get(1).map(|m| m.as_str()))
.collect();
if let Some(first_match) = matches.first() {
@@ -101,7 +102,9 @@ impl ReleaseRow {
version: github_release.tag_name.clone(),
version_integral: semver_integral.unwrap(),
published_timestamp: match &github_release.published_at {
Some(published_at) => Some(published_at.to_rfc3339_opts(SecondsFormat::Millis, true)),
Some(published_at) => {
Some(published_at.to_rfc3339_opts(SecondsFormat::Millis, true))
}
None => None,
},
created_timestamp: match &github_release.created_at {
@@ -111,7 +114,7 @@ impl ReleaseRow {
} else {
Some(created_at.to_rfc3339_opts(SecondsFormat::Millis, true))
}
},
}
None => None,
},
github_release_id: github_release.id.0 as i64,
@@ -121,7 +124,8 @@ impl ReleaseRow {
} else {
"stable".to_owned()
},
next_audit: (Utc::now() + Duration::days(7)).to_rfc3339_opts(SecondsFormat::Millis, true),
next_audit: (Utc::now() + Duration::days(7))
.to_rfc3339_opts(SecondsFormat::Millis, true),
next_audit_days: 7,
archived: 0,
notes: github_release.body.clone(),

View File

@@ -14,7 +14,10 @@ pub async fn sync_database(db: &SqlitePool) -> bool {
// 0. Get a list of all current version numbers (tags)
let current_version_data = storage::sqlite::list_all_release_tags(db).await;
if current_version_data.is_err() {
log::error!("unable to fetch current version data: {:?}", current_version_data.err());
log::error!(
"unable to fetch current version data: {:?}",
current_version_data.err()
);
return false;
}
let current_versions = current_version_data
@@ -56,7 +59,10 @@ pub async fn sync_database(db: &SqlitePool) -> bool {
.send()
.await;
if main_release_stream_req.is_err() {
log::error!("unable to retrieve PCSX2/pcsx2 releases: {:?}", main_release_stream_req.err());
log::error!(
"unable to retrieve PCSX2/pcsx2 releases: {:?}",
main_release_stream_req.err()
);
return false;
}
let main_release_stream = main_release_stream_req.unwrap().into_stream(&octocrab);
@@ -91,7 +97,10 @@ pub async fn sync_database(db: &SqlitePool) -> bool {
.send()
.await;
if archive_release_stream_req.is_err() {
log::error!("unable to retrieve PCSX2/archive releases: {:?}", archive_release_stream_req.err());
log::error!(
"unable to retrieve PCSX2/archive releases: {:?}",
archive_release_stream_req.err()
);
return false;
}
let archive_release_stream = archive_release_stream_req.unwrap().into_stream(&octocrab);