Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08e50b132f
|
||
|
|
944b6f9c75
|
||
|
|
0f5730f242
|
||
|
|
dd5ec8a5be
|
||
|
|
a29a9fa9f7
|
||
|
|
ceeec1d2cb
|
@@ -0,0 +1,58 @@
|
||||
name: labyrinth release Tagging
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0 # Important for git describe --tags
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: 1.97
|
||||
components: cargo
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
|
||||
- name: Extract Version from Cargo.toml
|
||||
id: version
|
||||
run: |
|
||||
VERSION=$(grep '^version = "' Cargo.toml | sed -E 's/version = "([^"]+)"/\1/')
|
||||
PROJECT_COMMIT_HASH=$(git rev-parse HEAD | cut -c 1-10)
|
||||
BRANCH_REF="${{ gitea.ref }}"
|
||||
BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3)
|
||||
PROJECT_TAG_RELEASE="v$VERSION-$BRANCH_NAME-$PROJECT_COMMIT_HASH-928"
|
||||
|
||||
echo "::set-output name=project_tag_release::$PROJECT_TAG_RELEASE"
|
||||
|
||||
echo "Version: $VERSION"
|
||||
echo "Hash: $PROJECT_COMMIT_HASH"
|
||||
echo "Branh ref: $BRANCH_REF"
|
||||
echo "Branch: $BRANCH_NAME"
|
||||
echo "Tag Release: $PROJECT_TAG_RELEASE"
|
||||
|
||||
- name: Print version
|
||||
id: Version
|
||||
run: |
|
||||
echo "Printing version"
|
||||
echo "Version: ${{ steps.version.outputs.project_tag_release }}"
|
||||
|
||||
- name: Create GitHub Release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ steps.version.outputs.project_tag_release }}
|
||||
release_name: Release ${{ steps.version.outputs.project_tag_release }}
|
||||
body: |
|
||||
Release of version ${{ steps.version.outputs.project_tag_release }}
|
||||
+1
-1
@@ -6,7 +6,7 @@ license = "MIT"
|
||||
description = "Library for managing soaricarus storage"
|
||||
|
||||
[dependencies]
|
||||
aws-config = { version = "1.9.0" }
|
||||
aws-config = { version = "1.9.0", features = ["behavior-version-latest"] }
|
||||
aws-sdk-s3 = { version = "1.138.1" }
|
||||
time = "0.3.53"
|
||||
tokio = { version = "1.53.0", features = ["full"] }
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
#[derive(Default)]
|
||||
pub struct Config {
|
||||
pub url: String,
|
||||
pub bucket: String,
|
||||
pub region: String,
|
||||
pub access_key_id: String,
|
||||
pub secret_key: String,
|
||||
}
|
||||
+69
-9
@@ -1,14 +1,74 @@
|
||||
pub fn add(left: u64, right: u64) -> u64 {
|
||||
left + right
|
||||
pub mod config;
|
||||
|
||||
use aws_sdk_s3::config::{Credentials, Region};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Data {
|
||||
pub filepath: String,
|
||||
pub raw_data: Vec<u8>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
pub struct Labyrinth {
|
||||
pub config: config::Config,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
pub async fn load_data(filepath: &str) -> Result<Vec<u8>, std::io::Error> {
|
||||
tokio::fs::read(filepath).await
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Info(String),
|
||||
SError(aws_sdk_s3::operation::put_object::PutObjectError),
|
||||
}
|
||||
|
||||
impl Labyrinth {
|
||||
pub async fn upload(
|
||||
&self,
|
||||
file_key: &str,
|
||||
data: &Data,
|
||||
) -> Result<aws_sdk_s3::operation::put_object::PutObjectOutput, Error> {
|
||||
// 1. Create credentials
|
||||
let credentials = Credentials::new(
|
||||
self.config.access_key_id.clone(),
|
||||
self.config.secret_key.clone(),
|
||||
None, // session_token - None for long-term credentials
|
||||
None, // expires_after - None for long-term credentials
|
||||
"maze", // provider_name - just a label
|
||||
);
|
||||
|
||||
// 2. Create region
|
||||
let region = Region::new(self.config.region.to_string());
|
||||
let config = aws_config::from_env()
|
||||
.region(region)
|
||||
.credentials_provider(credentials)
|
||||
.load()
|
||||
.await;
|
||||
|
||||
// let config = aws_config::load_from_env().await;
|
||||
let client = aws_sdk_s3::Client::new(&config);
|
||||
|
||||
let data_content = if data.raw_data.is_empty() {
|
||||
match load_data(&data.filepath).await {
|
||||
Ok(content) => content,
|
||||
Err(err) => return Err(Error::Info(err.to_string())),
|
||||
}
|
||||
} else {
|
||||
data.raw_data.to_owned()
|
||||
};
|
||||
|
||||
let body = aws_sdk_s3::primitives::SdkBody::from(data_content);
|
||||
let b_stream = aws_sdk_s3::primitives::ByteStream::from(body);
|
||||
match client
|
||||
.put_object()
|
||||
.bucket(self.config.bucket.clone())
|
||||
.key(file_key)
|
||||
.body(b_stream)
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(response) => Ok(response),
|
||||
Err(err) => Err(Error::Info(err.to_string())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user