Skip to content

Commit

Permalink
Add GitHub CI
Browse files Browse the repository at this point in the history
  • Loading branch information
pohlm01 committed Oct 16, 2023
1 parent 3e49422 commit 7578bf1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Image Thumbs
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
CARGO_TERM_COLOR: always

jobs:
# no cache needed for rustfmt
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: cargo fmt --all -- --check

# no cache needed for cargo outdated
outdated:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: cargo outdated --exit-code 1

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
with:
prefix-key: cargo
shared-key: build
- run: cargo build --all-features --all-targets --release

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
with:
prefix-key: cargo
shared-key: check
- run: cargo clippy --all-features --all-targets -- --deny clippy::all

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
with:
prefix-key: cargo
shared-key: test
- run: cargo test --all-features --all-targets
2 changes: 1 addition & 1 deletion src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::model::{ImageDetails, Mode};
use crate::{Error, ImageThumbs, ThumbsResult};

impl<T: ObjectStore> ImageThumbs<T> {
pub(crate) async fn create_thumbs_from_bytes(
pub(crate) async fn create_thumb_images_from_bytes(
&self,
bytes: Vec<u8>,
dest_dir: Path,
Expand Down
20 changes: 15 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! Easy to use library to create image thumbnails from images existing on some (cloud) object
//! storage or from disk.
//!
//! Currently implemented is a connection to Google Cloud Storage, but it can be easily extended to
//! other providers.
use ::image::ImageFormat;
use config::Config;
use object_store::path::Path;
Expand Down Expand Up @@ -68,7 +74,7 @@ impl<T: ObjectStore> ImageThumbs<T> {
force_override: bool,
) -> ThumbsResult<()> {
let image = self.download_image(file).await?;
self.create_thumbs_dest_from_bytes(
self.create_thumbs_from_bytes(
image.bytes,
dest_dir,
&image.stem,
Expand All @@ -95,7 +101,7 @@ impl<T: ObjectStore> ImageThumbs<T> {
///
/// * `force_override` - if `true` it will override already existent files with the same name.
/// If false, it will preserve already existent files.
pub async fn create_thumbs_dest_from_bytes(
pub async fn create_thumbs_from_bytes(
&self,
bytes: Vec<u8>,
dest_dir: &str,
Expand All @@ -106,7 +112,7 @@ impl<T: ObjectStore> ImageThumbs<T> {
let dest_dir = Path::parse(dest_dir)?;

let thumbs = self
.create_thumbs_from_bytes(bytes, dest_dir, image_name, format, force_override)
.create_thumb_images_from_bytes(bytes, dest_dir, image_name, format, force_override)
.await?;
self.upload_thumbs(thumbs).await
}
Expand Down Expand Up @@ -140,6 +146,7 @@ mod tests {
use crate::ImageThumbs;

#[tokio::test]
#[ignore]
#[sequential]
async fn create_thumbs() {
let client = ImageThumbs::new("src/test/image_thumbs").await.unwrap();
Expand Down Expand Up @@ -184,6 +191,7 @@ mod tests {
}

#[tokio::test]
#[ignore]
#[sequential]
async fn create_thumbs_dir() {
let client = ImageThumbs::new("src/test/image_thumbs").await.unwrap();
Expand Down Expand Up @@ -247,6 +255,7 @@ mod tests {
}

#[tokio::test]
#[ignore]
#[sequential]
async fn create_thumbs_from_bytes() {
let client = ImageThumbs::new("src/test/image_thumbs").await.unwrap();
Expand All @@ -261,7 +270,7 @@ mod tests {
reader.read_to_end(&mut buffer).await.unwrap();

client
.create_thumbs_dest_from_bytes(
.create_thumbs_from_bytes(
buffer,
"/from_bytes_test",
"penguin",
Expand All @@ -283,7 +292,7 @@ mod tests {
reader.read_to_end(&mut buffer).await.unwrap();

client
.create_thumbs_dest_from_bytes(
.create_thumbs_from_bytes(
buffer,
"/from_bytes_test",
"penguin",
Expand Down Expand Up @@ -332,6 +341,7 @@ mod tests {
}

#[tokio::test]
#[ignore]
#[sequential]
async fn override_behaviour() {
let client = ImageThumbs::new("src/test/image_thumbs").await.unwrap();
Expand Down

0 comments on commit 7578bf1

Please sign in to comment.