Updated to jenkins and gitea (#4)
All checks were successful
Gitea Organization/dotfiles/pipeline/head This commit looks good
All checks were successful
Gitea Organization/dotfiles/pipeline/head This commit looks good
Co-authored-by: Mutzi <root@mattv.de> Reviewed-on: #4
This commit is contained in:
parent
39f08615d8
commit
00a38cbf03
@ -1,19 +0,0 @@
|
||||
stages:
|
||||
- build
|
||||
|
||||
variables:
|
||||
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/installer"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
image: rust:alpine
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == "installer"
|
||||
script:
|
||||
- apk add pkgconf musl-dev curl
|
||||
- RUSTFLAGS='-C target-feature=+crt-static -C link-self-contained=yes -C link-arg=-s' cargo build --release --target x86_64-unknown-linux-musl
|
||||
- cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64
|
||||
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file installer-amd64 "${PACKAGE_REGISTRY_URL}/dev-$CI_COMMIT_SHA/installer-amd64"'
|
||||
artifacts:
|
||||
paths:
|
||||
- installer-amd64
|
5
Cargo.lock
generated
5
Cargo.lock
generated
@ -87,6 +87,7 @@ dependencies = [
|
||||
"dialoguer",
|
||||
"indicatif",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"toml",
|
||||
]
|
||||
|
||||
@ -354,9 +355,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.91"
|
||||
version = "1.0.93"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
|
||||
checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
|
@ -9,6 +9,7 @@ edition = "2021"
|
||||
dialoguer = "0.10.3"
|
||||
indicatif = "0.17.3"
|
||||
toml = "0.6.0"
|
||||
serde_json = "1.0.93"
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0.152"
|
||||
|
20
Jenkinsfile
vendored
Normal file
20
Jenkinsfile
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
pipeline {
|
||||
agent none
|
||||
stages {
|
||||
stage('Build') {
|
||||
agent {
|
||||
docker { image 'rust:alpine' }
|
||||
}
|
||||
environment {
|
||||
RUSTFLAGS = '-C target-feature=+crt-static -C link-self-contained=yes -C link-arg=-s'
|
||||
TOKEN = credentials('abd7020c-43d6-485b-ae09-2f9b484d9c15')
|
||||
}
|
||||
steps {
|
||||
sh 'apk add pkgconf musl-dev curl'
|
||||
sh 'cargo build --release --target x86_64-unknown-linux-musl'
|
||||
sh 'cp target/x86_64-unknown-linux-musl/release/dotfiles_installer ./installer-amd64'
|
||||
sh 'curl -H "Authorization: token ${TOKEN_PSW}" --upload-file ./installer-amd64 https://gitea.mattv.de/api/packages/root/generic/installer/${GIT_COMMIT}/installer-amd64'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -29,7 +29,7 @@ impl ToString for MainMenu {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if let Some(version) = option_env!("CI_COMMIT_SHA") {
|
||||
if let Some(version) = option_env!("GIT_COMMIT") {
|
||||
println!("Starting installer version {}", version);
|
||||
update::check_for_updates(version);
|
||||
} else {
|
||||
|
@ -48,7 +48,7 @@ fn check_config() -> bool {
|
||||
fn clone_repo() -> bool {
|
||||
println!("Cloning repo...");
|
||||
if !Path::new("repo").exists() { std::fs::create_dir("repo").unwrap(); }
|
||||
git!("clone", "git@ssh.gitlab.mattv.de:root/dotfiles.git", ".").success()
|
||||
git!("clone", "gitea@gitea.mattv.de:root/dotfiles.git", ".").success()
|
||||
&& check_config()
|
||||
}
|
||||
|
||||
|
@ -3,30 +3,25 @@ use std::fs;
|
||||
use std::fs::File;
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::path::Path;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Pipeline {
|
||||
sha: String
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct PackageEntry {
|
||||
version: String,
|
||||
pipeline: Pipeline
|
||||
}
|
||||
const GITEA_KEY: &str = "786666bd8bce93c562c4fc4c83933faa6cbdc802";
|
||||
|
||||
pub fn check_for_updates(version: &str) {
|
||||
print!("Checking for updates... ");
|
||||
let resp: Vec<PackageEntry> = attohttpc::get("https://gitlab.mattv.de/api/v4/projects/43/packages?name=installer&sort=desc").send().unwrap().json().unwrap();
|
||||
let newest = resp.first().unwrap();
|
||||
if newest.pipeline.sha != version {
|
||||
println!("New version exists");
|
||||
let resp: serde_json::Value = attohttpc::get("https://gitea.mattv.de/api/v1/repos/root/dotfiles/branches/installer")
|
||||
.header("accept", "application/json")
|
||||
.header("Authorization", format!("token {GITEA_KEY}"))
|
||||
.send().unwrap().json().unwrap();
|
||||
let newest = resp["commit"]["id"].as_str().unwrap();
|
||||
if newest != version {
|
||||
println!("New version {newest}");
|
||||
let exe = current_exe().unwrap();
|
||||
let temp = Path::new("temp");
|
||||
|
||||
print!("Downloading... ");
|
||||
attohttpc::get(format!("https://gitlab.mattv.de/api/v4/projects/43/packages/generic/installer/{}/installer-amd64", newest.version)).send().unwrap().write_to(File::create(temp).unwrap()).unwrap();
|
||||
attohttpc::get(format!("https://gitea.mattv.de/api/packages/root/generic/installer/{newest}/installer-amd64"))
|
||||
.header("Authorization", format!("token {GITEA_KEY}"))
|
||||
.send().unwrap().write_to(File::create(temp).unwrap()).unwrap();
|
||||
println!("Done");
|
||||
|
||||
fs::set_permissions(&temp, exe.metadata().unwrap().permissions()).unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user