Merge pull request #628 from vbrandl/fix/rust-ci
Remove usage of outdated actions
This commit is contained in:
commit
e3ed0a2417
2
.github/workflows/audit.yml
vendored
2
.github/workflows/audit.yml
vendored
@ -16,6 +16,6 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions-rs/audit-check@v1
|
- uses: rustsec/audit-check@v1
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
41
.github/workflows/rust.yml
vendored
41
.github/workflows/rust.yml
vendored
@ -16,18 +16,11 @@ jobs:
|
|||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install stable toolchain
|
- name: Install stable toolchain
|
||||||
uses: actions-rs/toolchain@v1
|
uses: dtolnay/rust-toolchain@stable
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
profile: minimal
|
|
||||||
override: true
|
|
||||||
components: rustfmt
|
|
||||||
|
|
||||||
- name: Check Formatting
|
- name: Check Formatting
|
||||||
uses: actions-rs/cargo@v1
|
run: cargo fmt --all -- --check
|
||||||
with:
|
|
||||||
command: fmt
|
|
||||||
args: --all -- --check
|
|
||||||
|
|
||||||
clippy:
|
clippy:
|
||||||
name: Clippy
|
name: Clippy
|
||||||
@ -37,12 +30,7 @@ jobs:
|
|||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install stable toolchain
|
- name: Install stable toolchain
|
||||||
uses: actions-rs/toolchain@v1
|
uses: dtolnay/rust-toolchain@stable
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
profile: minimal
|
|
||||||
override: true
|
|
||||||
components: rustfmt
|
|
||||||
|
|
||||||
- name: Cache cargo registry, index and build directory
|
- name: Cache cargo registry, index and build directory
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
@ -54,10 +42,13 @@ jobs:
|
|||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
|
||||||
- name: Clippy Linting
|
- name: Clippy Linting
|
||||||
uses: actions-rs/cargo@v1
|
run: cargo clippy --all-features -- -Dclippy::all
|
||||||
with:
|
# TODO
|
||||||
command: clippy
|
# run: cargo clippy --all-features -- -Dclippy::all -Dclippy::pedantic
|
||||||
args: -- -D warnings
|
- name: Clippy Test Linting
|
||||||
|
run: cargo clippy --tests -- -Dclippy::all
|
||||||
|
# TODO
|
||||||
|
# run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic
|
||||||
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
@ -74,11 +65,7 @@ jobs:
|
|||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install stable toolchain
|
- name: Install stable toolchain
|
||||||
uses: actions-rs/toolchain@v1
|
uses: dtolnay/rust-toolchain@stable
|
||||||
with:
|
|
||||||
toolchain: stable
|
|
||||||
profile: minimal
|
|
||||||
override: true
|
|
||||||
|
|
||||||
- name: Cache cargo registry, index and build directory
|
- name: Cache cargo registry, index and build directory
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
@ -90,6 +77,4 @@ jobs:
|
|||||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
||||||
|
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
uses: actions-rs/cargo@v1
|
run: cargo test
|
||||||
with:
|
|
||||||
command: test
|
|
||||||
|
13
src/cache.rs
13
src/cache.rs
@ -36,10 +36,10 @@ impl<'a> CacheState<'a> {
|
|||||||
trace!("Reading cache");
|
trace!("Reading cache");
|
||||||
if path.as_ref().exists() {
|
if path.as_ref().exists() {
|
||||||
let cache: Cache = serde_json::from_reader(BufReader::new(File::open(path)?))?;
|
let cache: Cache = serde_json::from_reader(BufReader::new(File::open(path)?))?;
|
||||||
Ok(cache
|
Ok(cache.entries.get(branch).map_or_else(
|
||||||
.entries
|
// TODO: get rid of clone
|
||||||
.get(branch)
|
|| CacheState::NoneForBranch(cache.clone()),
|
||||||
.map(|c| {
|
|c| {
|
||||||
if c.head == head {
|
if c.head == head {
|
||||||
trace!("Cache is up to date");
|
trace!("Cache is up to date");
|
||||||
CacheState::Current {
|
CacheState::Current {
|
||||||
@ -56,9 +56,8 @@ impl<'a> CacheState<'a> {
|
|||||||
cache: cache.clone(),
|
cache: cache.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
},
|
||||||
// TODO: get rid of clone
|
))
|
||||||
.unwrap_or_else(|| CacheState::NoneForBranch(cache.clone())))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(CacheState::No)
|
Ok(CacheState::No)
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,12 @@ pub struct Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
|
/// Load the configuration from file and environment.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// * File cannot be read or parsed
|
||||||
|
/// * Environment variables cannot be parsed
|
||||||
pub fn load() -> Result<Self, ConfigError> {
|
pub fn load() -> Result<Self, ConfigError> {
|
||||||
Config::builder()
|
Config::builder()
|
||||||
.add_source(File::with_name("hoc.toml").required(false))
|
.add_source(File::with_name("hoc.toml").required(false))
|
||||||
|
31
src/lib.rs
31
src/lib.rs
@ -22,7 +22,7 @@ use crate::{
|
|||||||
cache::CacheState,
|
cache::CacheState,
|
||||||
config::Settings,
|
config::Settings,
|
||||||
error::{Error, Result},
|
error::{Error, Result},
|
||||||
service::{Bitbucket, FormService, GitHub, Gitlab, Service, Sourcehut},
|
service::{Bitbucket, FormValue, GitHub, Gitlab, Service, Sourcehut},
|
||||||
statics::{CLIENT, VERSION_INFO},
|
statics::{CLIENT, VERSION_INFO},
|
||||||
template::{RepoGeneratorInfo, RepoInfo},
|
template::{RepoGeneratorInfo, RepoInfo},
|
||||||
};
|
};
|
||||||
@ -53,7 +53,7 @@ include!(concat!(env!("OUT_DIR"), "/templates.rs"));
|
|||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
struct GeneratorForm<'a> {
|
struct GeneratorForm<'a> {
|
||||||
service: FormService,
|
service: FormValue,
|
||||||
user: Cow<'a, str>,
|
user: Cow<'a, str>,
|
||||||
repo: Cow<'a, str>,
|
repo: Cow<'a, str>,
|
||||||
branch: Option<Cow<'a, str>>,
|
branch: Option<Cow<'a, str>>,
|
||||||
@ -309,7 +309,7 @@ pub(crate) async fn json_hoc<T: Service>(
|
|||||||
let branch = branch.branch.as_deref().unwrap_or("master");
|
let branch = branch.branch.as_deref().unwrap_or("master");
|
||||||
let rc_clone = repo_count.clone();
|
let rc_clone = repo_count.clone();
|
||||||
let mapper = move |r| match r {
|
let mapper = move |r| match r {
|
||||||
HocResult::NotFound => p404(rc_clone),
|
HocResult::NotFound => p404(&rc_clone),
|
||||||
HocResult::Hoc {
|
HocResult::Hoc {
|
||||||
hoc, head, commits, ..
|
hoc, head, commits, ..
|
||||||
} => Ok(HttpResponse::Ok().json(JsonResponse {
|
} => Ok(HttpResponse::Ok().json(JsonResponse {
|
||||||
@ -345,7 +345,7 @@ pub(crate) async fn calculate_hoc<T: Service>(
|
|||||||
let rc_clone = repo_count.clone();
|
let rc_clone = repo_count.clone();
|
||||||
let label = query.label.clone();
|
let label = query.label.clone();
|
||||||
let mapper = move |r| match r {
|
let mapper = move |r| match r {
|
||||||
HocResult::NotFound => p404(rc_clone),
|
HocResult::NotFound => p404(&rc_clone),
|
||||||
HocResult::Hoc { hoc_pretty, .. } => {
|
HocResult::Hoc { hoc_pretty, .. } => {
|
||||||
let badge_opt = BadgeOptions {
|
let badge_opt = BadgeOptions {
|
||||||
subject: label,
|
subject: label,
|
||||||
@ -386,7 +386,7 @@ async fn overview<T: Service>(
|
|||||||
let base_url = state.settings.base_url.clone();
|
let base_url = state.settings.base_url.clone();
|
||||||
let rc_clone = repo_count.clone();
|
let rc_clone = repo_count.clone();
|
||||||
let mapper = move |r| match r {
|
let mapper = move |r| match r {
|
||||||
HocResult::NotFound => p404(rc_clone),
|
HocResult::NotFound => p404(&rc_clone),
|
||||||
HocResult::Hoc {
|
HocResult::Hoc {
|
||||||
hoc,
|
hoc,
|
||||||
commits,
|
commits,
|
||||||
@ -413,7 +413,7 @@ async fn overview<T: Service>(
|
|||||||
VERSION_INFO,
|
VERSION_INFO,
|
||||||
rc_clone.load(Ordering::Relaxed),
|
rc_clone.load(Ordering::Relaxed),
|
||||||
repo_info,
|
repo_info,
|
||||||
label,
|
&label,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
||||||
@ -423,11 +423,13 @@ async fn overview<T: Service>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/health_check")]
|
#[get("/health_check")]
|
||||||
|
#[allow(clippy::unused_async)]
|
||||||
async fn health_check() -> HttpResponse {
|
async fn health_check() -> HttpResponse {
|
||||||
HttpResponse::Ok().finish()
|
HttpResponse::Ok().finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
|
#[allow(clippy::unused_async)]
|
||||||
async fn index(
|
async fn index(
|
||||||
state: web::Data<State>,
|
state: web::Data<State>,
|
||||||
repo_count: web::Data<AtomicUsize>,
|
repo_count: web::Data<AtomicUsize>,
|
||||||
@ -443,6 +445,7 @@ async fn index(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/generate")]
|
#[post("/generate")]
|
||||||
|
#[allow(clippy::unused_async)]
|
||||||
async fn generate(
|
async fn generate(
|
||||||
params: web::Form<GeneratorForm<'_>>,
|
params: web::Form<GeneratorForm<'_>>,
|
||||||
state: web::Data<State>,
|
state: web::Data<State>,
|
||||||
@ -470,20 +473,22 @@ async fn generate(
|
|||||||
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn p404(repo_count: web::Data<AtomicUsize>) -> Result<HttpResponse> {
|
fn p404(repo_count: &web::Data<AtomicUsize>) -> Result<HttpResponse> {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
templates::p404_html(&mut buf, VERSION_INFO, repo_count.load(Ordering::Relaxed))?;
|
templates::p404_html(&mut buf, VERSION_INFO, repo_count.load(Ordering::Relaxed))?;
|
||||||
Ok(HttpResponse::NotFound().content_type("text/html").body(buf))
|
Ok(HttpResponse::NotFound().content_type("text/html").body(buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::unused_async)]
|
||||||
async fn async_p404(repo_count: web::Data<AtomicUsize>) -> Result<HttpResponse> {
|
async fn async_p404(repo_count: web::Data<AtomicUsize>) -> Result<HttpResponse> {
|
||||||
p404(repo_count)
|
p404(&repo_count)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A duration to add to current time for a far expires header.
|
/// A duration to add to current time for a far expires header.
|
||||||
static FAR: Duration = Duration::from_secs(180 * 24 * 60 * 60);
|
static FAR: Duration = Duration::from_secs(180 * 24 * 60 * 60);
|
||||||
|
|
||||||
#[get("/static/{filename}")]
|
#[get("/static/{filename}")]
|
||||||
|
#[allow(clippy::unused_async)]
|
||||||
async fn static_file(
|
async fn static_file(
|
||||||
path: web::Path<String>,
|
path: web::Path<String>,
|
||||||
repo_count: web::Data<AtomicUsize>,
|
repo_count: web::Data<AtomicUsize>,
|
||||||
@ -496,11 +501,11 @@ async fn static_file(
|
|||||||
.content_type(data.mime.clone())
|
.content_type(data.mime.clone())
|
||||||
.body(data.content)
|
.body(data.content)
|
||||||
})
|
})
|
||||||
.map(Result::Ok)
|
.map_or_else(|| p404(&repo_count), Result::Ok)
|
||||||
.unwrap_or_else(|| p404(repo_count))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/favicon.ico")]
|
#[get("/favicon.ico")]
|
||||||
|
#[allow(clippy::unused_async)]
|
||||||
async fn favicon32() -> HttpResponse {
|
async fn favicon32() -> HttpResponse {
|
||||||
let data = &template_statics::favicon32_png;
|
let data = &template_statics::favicon32_png;
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
@ -508,6 +513,7 @@ async fn favicon32() -> HttpResponse {
|
|||||||
.body(data.content)
|
.body(data.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::unused_async)]
|
||||||
async fn start_server(listener: TcpListener, settings: Settings) -> std::io::Result<Server> {
|
async fn start_server(listener: TcpListener, settings: Settings) -> std::io::Result<Server> {
|
||||||
let workers = settings.workers;
|
let workers = settings.workers;
|
||||||
let repo_count =
|
let repo_count =
|
||||||
@ -536,6 +542,11 @@ async fn start_server(listener: TcpListener, settings: Settings) -> std::io::Res
|
|||||||
.run())
|
.run())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Start the server.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// * server cannot bind to `listener`
|
||||||
pub async fn run(listener: TcpListener, settings: Settings) -> std::io::Result<Server> {
|
pub async fn run(listener: TcpListener, settings: Settings) -> std::io::Result<Server> {
|
||||||
let span = info_span!("hoc", version = env!("CARGO_PKG_VERSION"));
|
let span = info_span!("hoc", version = env!("CARGO_PKG_VERSION"));
|
||||||
let _ = span.enter();
|
let _ = span.enter();
|
||||||
|
@ -29,7 +29,7 @@ pub(crate) trait Service: Sized + 'static {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Clone, Copy)]
|
#[derive(Deserialize, Serialize, Clone, Copy)]
|
||||||
pub enum FormService {
|
pub enum FormValue {
|
||||||
#[serde(rename = "github")]
|
#[serde(rename = "github")]
|
||||||
GitHub,
|
GitHub,
|
||||||
#[serde(rename = "gitlab")]
|
#[serde(rename = "gitlab")]
|
||||||
@ -40,22 +40,22 @@ pub enum FormService {
|
|||||||
Sourcehut,
|
Sourcehut,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FormService {
|
impl FormValue {
|
||||||
pub(crate) fn url(&self) -> &str {
|
pub(crate) fn url(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
FormService::GitHub => "github.com",
|
FormValue::GitHub => "github.com",
|
||||||
FormService::Gitlab => "gitlab.com",
|
FormValue::Gitlab => "gitlab.com",
|
||||||
FormService::Bitbucket => "bitbucket.org",
|
FormValue::Bitbucket => "bitbucket.org",
|
||||||
FormService::Sourcehut => "git.sr.ht",
|
FormValue::Sourcehut => "git.sr.ht",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn service(&self) -> &str {
|
pub(crate) fn service(&self) -> &str {
|
||||||
match self {
|
match self {
|
||||||
FormService::GitHub => "github",
|
FormValue::GitHub => "github",
|
||||||
FormService::Gitlab => "gitlab",
|
FormValue::Gitlab => "gitlab",
|
||||||
FormService::Bitbucket => "bitbucket",
|
FormValue::Bitbucket => "bitbucket",
|
||||||
FormService::Sourcehut => "sourcehut",
|
FormValue::Sourcehut => "sourcehut",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#[derive(Clone, Copy)]
|
||||||
pub struct VersionInfo<'a> {
|
pub struct VersionInfo<'a> {
|
||||||
pub commit: &'a str,
|
pub commit: &'a str,
|
||||||
pub version: &'a str,
|
pub version: &'a str,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::service::FormService;
|
use crate::service::FormValue;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
pub struct RepoInfo<'a> {
|
pub struct RepoInfo<'a> {
|
||||||
pub commit_url: &'a str,
|
pub commit_url: &'a str,
|
||||||
pub commits: u64,
|
pub commits: u64,
|
||||||
@ -13,7 +14,7 @@ pub struct RepoInfo<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct RepoGeneratorInfo<'a> {
|
pub struct RepoGeneratorInfo<'a> {
|
||||||
pub service: FormService,
|
pub service: FormValue,
|
||||||
pub user: &'a str,
|
pub user: &'a str,
|
||||||
pub repo: &'a str,
|
pub repo: &'a str,
|
||||||
pub branch: &'a str,
|
pub branch: &'a str,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
@use super::statics::*;
|
@use super::statics::tacit_css_min_css;
|
||||||
@use crate::statics::VersionInfo;
|
@use crate::statics::VersionInfo;
|
||||||
|
|
||||||
@(title: &str, header: &str, content: Content, version_info: VersionInfo, repo_count: usize)
|
@(title: &str, header: &str, content: Content, version_info: VersionInfo, repo_count: usize)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
@use crate::statics::VersionInfo;
|
@use crate::statics::VersionInfo;
|
||||||
@use crate::template::RepoInfo;
|
@use crate::template::RepoInfo;
|
||||||
|
|
||||||
@(version_info: VersionInfo, repo_count: usize, repo_info: RepoInfo, label: String)
|
@(version_info: VersionInfo, repo_count: usize, repo_info: RepoInfo, label: &str)
|
||||||
|
|
||||||
@:base_html("Hits-of-Code Badges", "Overview", {
|
@:base_html("Hits-of-Code Badges", "Overview", {
|
||||||
|
|
||||||
|
@ -38,6 +38,8 @@ pub async fn spawn_app() -> TestApp {
|
|||||||
.await
|
.await
|
||||||
.expect("Failed to bind address");
|
.expect("Failed to bind address");
|
||||||
|
|
||||||
|
#[allow(clippy::let_underscore_future)]
|
||||||
|
// don't await so the test server runs in the background
|
||||||
let _ = tokio::spawn(server);
|
let _ = tokio::spawn(server);
|
||||||
|
|
||||||
TestApp {
|
TestApp {
|
||||||
|
Loading…
Reference in New Issue
Block a user