fix(deps): update rust crate serde to v1.0.209 - abandoned #41
11 changed files with 514 additions and 23 deletions
118
images/gitea/Cargo.lock
generated
118
images/gitea/Cargo.lock
generated
|
@ -17,6 +17,15 @@ version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstream"
|
name = "anstream"
|
||||||
version = "0.2.6"
|
version = "0.2.6"
|
||||||
|
@ -90,6 +99,16 @@ version = "1.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bstr"
|
||||||
|
version = "1.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "542f33a8835a0884b006a0c3df3dadd99c0c3f296ed26c2fdc8028e01ad6230c"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bumpalo"
|
name = "bumpalo"
|
||||||
version = "3.12.0"
|
version = "3.12.0"
|
||||||
|
@ -185,8 +204,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "color-eyre"
|
name = "color-eyre"
|
||||||
version = "0.6.2"
|
version = "0.6.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/sclu1034/color-eyre.git?branch=fork#0fa05eba9954be223b06468c8760b97e660f9941"
|
||||||
checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"color-spantrace",
|
"color-spantrace",
|
||||||
|
@ -372,11 +390,12 @@ checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gitea"
|
name = "gitea"
|
||||||
version = "0.1.0"
|
version = "0.1.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"cli-table",
|
"cli-table",
|
||||||
"color-eyre",
|
"color-eyre",
|
||||||
|
"globwalk",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -384,6 +403,30 @@ dependencies = [
|
||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "globset"
|
||||||
|
version = "0.4.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "759c97c1e17c55525b57192c06a267cda0ac5210b222d6b82189a2338fa1c13d"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"bstr",
|
||||||
|
"fnv",
|
||||||
|
"log",
|
||||||
|
"regex",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "globwalk"
|
||||||
|
version = "0.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"ignore",
|
||||||
|
"walkdir",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
version = "0.3.16"
|
version = "0.3.16"
|
||||||
|
@ -511,6 +554,23 @@ dependencies = [
|
||||||
"unicode-normalization",
|
"unicode-normalization",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ignore"
|
||||||
|
version = "0.4.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492"
|
||||||
|
dependencies = [
|
||||||
|
"globset",
|
||||||
|
"lazy_static",
|
||||||
|
"log",
|
||||||
|
"memchr",
|
||||||
|
"regex",
|
||||||
|
"same-file",
|
||||||
|
"thread_local",
|
||||||
|
"walkdir",
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indenter"
|
name = "indenter"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
|
@ -600,9 +660,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.5.0"
|
version = "2.6.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mime"
|
name = "mime"
|
||||||
|
@ -704,6 +764,35 @@ dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.10.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reqwest"
|
name = "reqwest"
|
||||||
version = "0.11.16"
|
version = "0.11.16"
|
||||||
|
@ -817,6 +906,15 @@ version = "1.0.13"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
|
checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "same-file"
|
||||||
|
version = "1.0.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "schannel"
|
name = "schannel"
|
||||||
version = "0.1.21"
|
version = "0.1.21"
|
||||||
|
@ -1192,6 +1290,16 @@ version = "0.9.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "walkdir"
|
||||||
|
version = "2.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee"
|
||||||
|
dependencies = [
|
||||||
|
"same-file",
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "want"
|
name = "want"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "gitea"
|
name = "gitea"
|
||||||
version = "0.1.0"
|
version = "0.1.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
@ -14,7 +14,14 @@ serde = { version = "1.0.159", features = ["derive"] }
|
||||||
time = { version = "0.3.20", features = ["formatting", "parsing", "serde"] }
|
time = { version = "0.3.20", features = ["formatting", "parsing", "serde"] }
|
||||||
url = { version = "2.3.1", features = ["serde"] }
|
url = { version = "2.3.1", features = ["serde"] }
|
||||||
cli-table = "0.4.7"
|
cli-table = "0.4.7"
|
||||||
|
globwalk = "0.8.1"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
strip = "debuginfo"
|
strip = "debuginfo"
|
||||||
lto = true
|
lto = true
|
||||||
|
|
||||||
|
[profile.dev.package.backtrace]
|
||||||
|
opt-level = 3
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
color-eyre = { git = "https://github.com/sclu1034/color-eyre.git", branch = "fork" }
|
||||||
|
|
|
@ -22,20 +22,19 @@ RUN cargo build --color always --release --locked
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN touch -a -m ./src/main.rs && cargo build --color always --release --locked
|
RUN touch -a -m ./src/main.rs && cargo build --color always --release --locked
|
||||||
|
|
||||||
FROM alpine AS pr
|
FROM alpine AS final
|
||||||
# FROM debian:bullseye-slim AS pr
|
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates
|
RUN apk add --no-cache ca-certificates
|
||||||
# RUN set -e; \
|
|
||||||
# apt-get update; \
|
|
||||||
# apt-get install -y --no-install-recommends \
|
|
||||||
# ca-certificates; \
|
|
||||||
# rm -fr /var/apt/lists/*;
|
|
||||||
|
|
||||||
LABEL version="0.1.0"
|
|
||||||
|
|
||||||
ENV RUST_BACKTRACE=1
|
ENV RUST_BACKTRACE=1
|
||||||
ENV RUST_LOG=info
|
ENV RUST_LOG=info
|
||||||
|
|
||||||
COPY ./shims/pr/* /opt/resource/
|
|
||||||
COPY --from=builder /app/target/release/gitea /bin/
|
COPY --from=builder /app/target/release/gitea /bin/
|
||||||
|
|
||||||
|
# Put this last, as it's the only thing that's different between variants.
|
||||||
|
# This way, the previous layers can all be shared.
|
||||||
|
|
||||||
|
ARG VARIANT="missing build arg 'VARIANT'"
|
||||||
|
ARG VERSION="0.1.0"
|
||||||
|
LABEL version="$VERSION"
|
||||||
|
COPY ./shims/${VARIANT}/* /opt/resource/
|
||||||
|
|
2
images/gitea/shims/package/check
Executable file
2
images/gitea/shims/package/check
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
/bin/gitea package check "$@"
|
2
images/gitea/shims/package/in
Executable file
2
images/gitea/shims/package/in
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
/bin/gitea package in "$@"
|
2
images/gitea/shims/package/out
Executable file
2
images/gitea/shims/package/out
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
/bin/gitea package out "$@"
|
301
images/gitea/src/cmd/package.rs
Normal file
301
images/gitea/src/cmd/package.rs
Normal file
|
@ -0,0 +1,301 @@
|
||||||
|
use std::fs;
|
||||||
|
use std::io::{self, Read, Write};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use cli_table::format::Justify;
|
||||||
|
use cli_table::{Cell, Style, Table};
|
||||||
|
use color_eyre::eyre::{self, Context};
|
||||||
|
use color_eyre::{Help, Report, Result};
|
||||||
|
use globwalk::{DirEntry, GlobWalkerBuilder};
|
||||||
|
use reqwest::blocking::Client;
|
||||||
|
use reqwest::header::HeaderMap;
|
||||||
|
use reqwest::StatusCode;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_json::json;
|
||||||
|
use time::format_description::well_known::Iso8601;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
|
use crate::types::{Package, PackageType};
|
||||||
|
use crate::{Action, USER_AGENT};
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
|
struct Source {
|
||||||
|
access_token: String,
|
||||||
|
owner: String,
|
||||||
|
url: Url,
|
||||||
|
r#type: PackageType,
|
||||||
|
name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
|
struct Version {
|
||||||
|
version: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
|
struct Params {
|
||||||
|
version: String,
|
||||||
|
globs: Vec<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
fail_fast: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
r#override: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
|
struct Config {
|
||||||
|
/// Resource configuration.
|
||||||
|
/// Passed verbatim from the definition in the pipeline.
|
||||||
|
source: Source,
|
||||||
|
/// For 'check':
|
||||||
|
/// Previous version of this resource.
|
||||||
|
/// Will be empty for the very first request.
|
||||||
|
/// For 'in':
|
||||||
|
/// The version metadata to create this as.
|
||||||
|
version: Option<Version>,
|
||||||
|
params: Option<Params>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_client(src: &Source) -> Result<Client> {
|
||||||
|
let mut headers = HeaderMap::new();
|
||||||
|
headers.insert(
|
||||||
|
"Authorization",
|
||||||
|
format!("token {}", src.access_token).try_into()?,
|
||||||
|
);
|
||||||
|
|
||||||
|
Client::builder()
|
||||||
|
.default_headers(headers)
|
||||||
|
.user_agent(USER_AGENT)
|
||||||
|
.build()
|
||||||
|
.map_err(From::from)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn action_check(conf: Config) -> Result<()> {
|
||||||
|
let client = make_client(&conf.source)?;
|
||||||
|
let url = conf
|
||||||
|
.source
|
||||||
|
.url
|
||||||
|
.join(&format!("api/v1/packages/{}", conf.source.owner))
|
||||||
|
.wrap_err("Invalid URL")?;
|
||||||
|
|
||||||
|
let mut pkgs: Vec<Package> = client
|
||||||
|
.get(url)
|
||||||
|
.query(&[
|
||||||
|
("type", conf.source.r#type.to_string()),
|
||||||
|
("q", conf.source.name),
|
||||||
|
])
|
||||||
|
.send()?
|
||||||
|
.json()?;
|
||||||
|
|
||||||
|
if pkgs.is_empty() {
|
||||||
|
return io::stdout().write_all(b"[]").map_err(From::from);
|
||||||
|
}
|
||||||
|
|
||||||
|
pkgs.sort_unstable_by_key(|pkg| pkg.created_at);
|
||||||
|
|
||||||
|
let table: Vec<_> = pkgs
|
||||||
|
.iter()
|
||||||
|
.map(|pkg| {
|
||||||
|
vec![
|
||||||
|
pkg.id.cell().justify(Justify::Center),
|
||||||
|
pkg.name.clone().cell(),
|
||||||
|
pkg.owner.login.clone().cell(),
|
||||||
|
pkg.version.clone().cell(),
|
||||||
|
pkg.created_at
|
||||||
|
.format(&Iso8601::DEFAULT)
|
||||||
|
.unwrap_or_default()
|
||||||
|
.cell(),
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let table = table
|
||||||
|
.table()
|
||||||
|
.title(vec![
|
||||||
|
"#".cell().bold(true),
|
||||||
|
"Name".cell().bold(true),
|
||||||
|
"Owner".cell().bold(true),
|
||||||
|
"Version".cell().bold(true),
|
||||||
|
"Created At".cell().bold(true),
|
||||||
|
])
|
||||||
|
.bold(true);
|
||||||
|
|
||||||
|
let _ = cli_table::print_stderr(table);
|
||||||
|
|
||||||
|
let newest = pkgs
|
||||||
|
.last()
|
||||||
|
.expect("List of packages should not be empty.")
|
||||||
|
.version
|
||||||
|
.clone();
|
||||||
|
|
||||||
|
let out = if let Some(prev) = conf.version {
|
||||||
|
if prev.version == newest {
|
||||||
|
vec![prev]
|
||||||
|
} else {
|
||||||
|
vec![prev, Version { version: newest }]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
vec![Version { version: newest }]
|
||||||
|
};
|
||||||
|
|
||||||
|
serde_json::to_writer_pretty(io::stdout(), &out)
|
||||||
|
.wrap_err("Failed to write result to stdout")?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn action_out(conf: Config, dir: impl AsRef<Path>) -> Result<()> {
|
||||||
|
let dir = dir
|
||||||
|
.as_ref()
|
||||||
|
.canonicalize()
|
||||||
|
.wrap_err_with(|| format!("Invalid file path '{}'", dir.as_ref().display()))?;
|
||||||
|
|
||||||
|
let Some(params) = conf.params else {
|
||||||
|
eyre::bail!("Missing params");
|
||||||
|
};
|
||||||
|
|
||||||
|
if params.globs.is_empty() {
|
||||||
|
eyre::bail!("`params.globs` must not be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
let client = make_client(&conf.source)?;
|
||||||
|
let url = conf
|
||||||
|
.source
|
||||||
|
.url
|
||||||
|
.join(&format!(
|
||||||
|
// The trailing slash is required, to make sure this entire URL is used
|
||||||
|
// when `join`ing the file name later. Otherwise, the last component
|
||||||
|
// would be considered a "file" part itself, and replaced by a future `join`.
|
||||||
|
"api/packages/{}/{}/{}/{}/",
|
||||||
|
conf.source.owner, conf.source.r#type, conf.source.name, params.version
|
||||||
|
))
|
||||||
|
.wrap_err("Invalid URL")?;
|
||||||
|
|
||||||
|
let walker = GlobWalkerBuilder::from_patterns(dir, ¶ms.globs)
|
||||||
|
.max_depth(3)
|
||||||
|
.file_type(globwalk::FileType::FILE)
|
||||||
|
.build()
|
||||||
|
.wrap_err("Failed to create glob walker")?;
|
||||||
|
|
||||||
|
let handle_glob = |entry| {
|
||||||
|
let entry: DirEntry = entry?;
|
||||||
|
|
||||||
|
let name = entry.file_name();
|
||||||
|
let path = entry.path();
|
||||||
|
let url = url.join(&name.to_string_lossy()).wrap_err("Invalid url")?;
|
||||||
|
|
||||||
|
if params.r#override {
|
||||||
|
client
|
||||||
|
.delete(url.clone())
|
||||||
|
.send()
|
||||||
|
.wrap_err_with(|| format!("Failed request 'DELETE {}'", &url))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let data = fs::read(path)
|
||||||
|
.wrap_err_with(|| format!("Failed to read package file '{}'", path.display()))?;
|
||||||
|
|
||||||
|
let res = client
|
||||||
|
.put(url.clone())
|
||||||
|
.body(data)
|
||||||
|
.send()
|
||||||
|
.wrap_err_with(|| format!("Failed request 'PUT {}'", &url))?;
|
||||||
|
|
||||||
|
match res.status() {
|
||||||
|
StatusCode::CREATED => {
|
||||||
|
eprintln!(
|
||||||
|
"Uploaded file '{}', version={}, package={}",
|
||||||
|
name.to_string_lossy(),
|
||||||
|
params.version,
|
||||||
|
conf.source.name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
StatusCode::BAD_REQUEST => {
|
||||||
|
eyre::bail!(
|
||||||
|
"Package, version or file name are invalid. package={}, version={}, file={}",
|
||||||
|
conf.source.name,
|
||||||
|
params.version,
|
||||||
|
name.to_string_lossy(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
StatusCode::CONFLICT => {
|
||||||
|
eyre::bail!(
|
||||||
|
"File '{}' already exists. version={}, package={}",
|
||||||
|
name.to_string_lossy(),
|
||||||
|
params.version,
|
||||||
|
conf.source.name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
StatusCode::INTERNAL_SERVER_ERROR => {
|
||||||
|
eyre::bail!(
|
||||||
|
"Internal server error: {} {}",
|
||||||
|
res.status(),
|
||||||
|
res.text().unwrap_or_default()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
code => {
|
||||||
|
eyre::bail!("Unexpected status code {}\ntext = {:?}", code, res.text());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok::<_, Report>(())
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut has_entry = false;
|
||||||
|
|
||||||
|
let mut errors = Vec::new();
|
||||||
|
for entry in walker {
|
||||||
|
has_entry = true;
|
||||||
|
if let Err(err) = handle_glob(entry) {
|
||||||
|
errors.push(err);
|
||||||
|
if params.fail_fast {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !errors.is_empty() {
|
||||||
|
let mut err = eyre::eyre!("Failed to upload package with {} errors", errors.len());
|
||||||
|
|
||||||
|
for e in errors {
|
||||||
|
err = err.report(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Err(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if !has_entry {
|
||||||
|
eyre::bail!("Globs didn't produce any files");
|
||||||
|
}
|
||||||
|
|
||||||
|
let out = json!({
|
||||||
|
"version": {
|
||||||
|
"version": params.version
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
serde_json::to_writer_pretty(io::stdout(), &out)
|
||||||
|
.wrap_err("Failed to write result to stdout")?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn run(action: &Action) -> Result<()> {
|
||||||
|
let config: Config = {
|
||||||
|
let mut buf = String::new();
|
||||||
|
io::stdin()
|
||||||
|
.read_to_string(&mut buf)
|
||||||
|
.wrap_err("Failed to read from stdin")?;
|
||||||
|
|
||||||
|
if buf.is_empty() {
|
||||||
|
eyre::bail!("No data received on stdin");
|
||||||
|
}
|
||||||
|
|
||||||
|
serde_json::from_str(&buf).wrap_err("Failed to parse stdin")?
|
||||||
|
};
|
||||||
|
|
||||||
|
match action {
|
||||||
|
Action::Check => action_check(config),
|
||||||
|
Action::In { dest: _ } => Ok(()),
|
||||||
|
Action::Out { src } => action_out(config, src),
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,9 +14,7 @@ use time::OffsetDateTime;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::types::PullRequest;
|
use crate::types::PullRequest;
|
||||||
use crate::Action;
|
use crate::{Action, USER_AGENT};
|
||||||
|
|
||||||
static USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
struct Source {
|
struct Source {
|
||||||
|
@ -182,6 +180,6 @@ pub(crate) fn run(action: &Action) -> Result<()> {
|
||||||
match action {
|
match action {
|
||||||
Action::Check => action_check(config),
|
Action::Check => action_check(config),
|
||||||
Action::In { dest } => action_in(config, dest),
|
Action::In { dest } => action_in(config, dest),
|
||||||
Action::Out => Ok(()),
|
Action::Out { src: _ } => Ok(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ use std::path::PathBuf;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
|
|
||||||
|
static USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[command(author, version, about, long_about = None)]
|
#[command(author, version, about, long_about = None)]
|
||||||
#[command(propagate_version = true)]
|
#[command(propagate_version = true)]
|
||||||
|
@ -17,25 +19,31 @@ enum Commands {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
action: Action,
|
action: Action,
|
||||||
},
|
},
|
||||||
|
Package {
|
||||||
|
#[command(subcommand)]
|
||||||
|
action: Action,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Subcommand)]
|
#[derive(Clone, Debug, Subcommand)]
|
||||||
pub(crate) enum Action {
|
pub(crate) enum Action {
|
||||||
Check,
|
Check,
|
||||||
In { dest: PathBuf },
|
In { dest: PathBuf },
|
||||||
Out,
|
Out { src: PathBuf },
|
||||||
}
|
}
|
||||||
|
|
||||||
mod types;
|
mod types;
|
||||||
mod cmd {
|
mod cmd {
|
||||||
|
pub mod package;
|
||||||
pub mod pr;
|
pub mod pr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[tracing::instrument]
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
|
color_eyre::install()?;
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
match &cli.command {
|
match &cli.command {
|
||||||
Commands::Pr { action } => cmd::pr::run(action),
|
Commands::Pr { action } => cmd::pr::run(action),
|
||||||
|
Commands::Package { action } => cmd::package::run(action),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Serialize};
|
||||||
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
pub struct Ref {
|
pub struct Ref {
|
||||||
|
@ -18,3 +19,28 @@ pub struct PullRequest {
|
||||||
pub base: Ref,
|
pub base: Ref,
|
||||||
pub head: Ref,
|
pub head: Ref,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Deserialize, Serialize, Debug)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum PackageType {
|
||||||
|
Generic,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for PackageType {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
PackageType::Generic => write!(f, "generic"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
|
pub struct Package {
|
||||||
|
#[serde(with = "time::serde::iso8601")]
|
||||||
|
pub created_at: OffsetDateTime,
|
||||||
|
pub id: u64,
|
||||||
|
pub name: String,
|
||||||
|
pub owner: User,
|
||||||
|
pub r#type: PackageType,
|
||||||
|
pub version: String,
|
||||||
|
}
|
||||||
|
|
38
images/gitea/test.sh
Executable file
38
images/gitea/test.sh
Executable file
|
@ -0,0 +1,38 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cargo build
|
||||||
|
|
||||||
|
run() {
|
||||||
|
./target/debug/gitea package "$1" <<EOF
|
||||||
|
{
|
||||||
|
$2
|
||||||
|
"source": {
|
||||||
|
"access_token": "$GITEA_ACCESS_TOKEN",
|
||||||
|
"owner": "concourse",
|
||||||
|
"url": "https://git.sclu1034.dev",
|
||||||
|
"type": "generic",
|
||||||
|
"name": "test"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
run "$@"
|
||||||
|
echo ""
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$(tput bold)Test: Check existing versions$(tput sgr0)"
|
||||||
|
run check
|
||||||
|
printf "\n\n"
|
||||||
|
|
||||||
|
echo "$(tput bold)Test: Check 'v0.1.0'$(tput sgr0)"
|
||||||
|
run check '
|
||||||
|
"params": {
|
||||||
|
"version": "0.1.0"
|
||||||
|
},
|
||||||
|
'
|
||||||
|
printf "\n"
|
Loading…
Add table
Add a link
Reference in a new issue