Switched self-updater to packages, stop creating releases

This commit is contained in:
Mutzi 2023-01-25 16:33:34 +01:00
parent 78f4e0f681
commit 6953d6075c
2 changed files with 11 additions and 52 deletions

View File

@ -1,9 +1,8 @@
stages: stages:
- build - build
- release
variables: variables:
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/installer/" PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/installer"
build: build:
stage: build stage: build
@ -12,43 +11,13 @@ build:
- if: $CI_COMMIT_BRANCH == "installer" - if: $CI_COMMIT_BRANCH == "installer"
script: script:
- export CARGO_HOME="${PWD}/.cargo" - export CARGO_HOME="${PWD}/.cargo"
- apk add pkgconf musl-dev - 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 - 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 - 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_SHORT_SHA/installer-amd64"'
artifacts: artifacts:
paths: paths:
- installer-amd64 - installer-amd64
cache: cache:
paths: paths:
- .cargo/ - .cargo/
upload_assets:
stage: release
image: curlimages/curl:latest
rules:
- if: $CI_COMMIT_BRANCH == "installer"
needs:
- job: build
artifacts: true
script:
- 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file installer-amd64 "${PACKAGE_REGISTRY_URL}/dev-$CI_COMMIT_SHORT_SHA/installer-amd64"'
create_release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
rules:
- if: $CI_COMMIT_BRANCH == "installer"
needs:
- upload_assets
script:
- echo "running release_job"
release: # See https://docs.gitlab.com/ee/ci/yaml/#release for available properties
tag_name: 'dev-$CI_COMMIT_SHORT_SHA'
description: 'Release dev-$CI_COMMIT_SHORT_SHA'
assets:
links:
- name: 'installer-amd64'
url: '${PACKAGE_REGISTRY_URL}/dev-$CI_COMMIT_SHORT_SHA/installer-amd64'
link_type: package

View File

@ -6,37 +6,27 @@ use std::path::Path;
use serde::Deserialize; use serde::Deserialize;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
struct Commit { struct Pipeline {
id: String sha: String
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
struct Link { struct PackageEntry {
direct_asset_url: String version: String,
} pipeline: Pipeline
#[derive(Debug, Deserialize)]
struct Assets {
links: Vec<Link>
}
#[derive(Debug, Deserialize)]
struct ReleaseEntry {
commit: Commit,
assets: Assets
} }
pub fn check_for_updates(version: &str) { pub fn check_for_updates(version: &str) {
print!("Checking for updates... "); print!("Checking for updates... ");
let resp: Vec<ReleaseEntry> = attohttpc::get("https://gitlab.mattv.de/api/v4/projects/43/releases").send().unwrap().json().unwrap(); 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(); let newest = resp.first().unwrap();
if newest.commit.id != version { if newest.pipeline.sha != version {
println!("New version exists"); println!("New version exists");
let exe = current_exe().unwrap(); let exe = current_exe().unwrap();
let temp = Path::new("temp"); let temp = Path::new("temp");
print!("Downloading... "); print!("Downloading... ");
attohttpc::get(newest.assets.links.first().unwrap().direct_asset_url.clone()).send().unwrap().write_to(File::create(temp).unwrap()).unwrap(); 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();
println!("Done"); println!("Done");
fs::set_permissions(&temp, exe.metadata().unwrap().permissions()).unwrap(); fs::set_permissions(&temp, exe.metadata().unwrap().permissions()).unwrap();