Skip to content

Commit

Permalink
fix sbuild and update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
QaidVoid committed Jan 6, 2025
1 parent ec65fb1 commit 6456561
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: sbuilder release
name: sbuild-linter release

on:
workflow_dispatch:
push:
tags:
- "v*.*.*"
- "v*.*.*-linter"
permissions:
contents: write

Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
with:
use-cross: true
command: build
args: --release --locked --target ${{ matrix.build.TARGET }}
args: --bin sbuild-linter --release --locked --target ${{ matrix.build.TARGET }}
- name: Prepare release assets
shell: bash
run: |
Expand Down
76 changes: 76 additions & 0 deletions .github/workflows/release-sbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: sbuild release

on:
push:
tags:
- "v*.*.*-sbuild"
permissions:
contents: write

jobs:
publish-binaries:
name: Publish binaries
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
build:
- {
NAME: x86_64-linux,
TOOLCHAIN: stable,
TARGET: x86_64-unknown-linux-musl,
}
- {
NAME: aarch64-linux,
TOOLCHAIN: stable,
TARGET: aarch64-unknown-linux-musl,
}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set the release version
shell: bash
run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV
- name: Install dependencies
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
--allow-unauthenticated musl-tools b3sum
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.build.TOOLCHAIN }}
target: ${{ matrix.build.TARGET }}
override: true
- name: Build
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --bin sbuild --release --locked --target ${{ matrix.build.TARGET }}
- name: Prepare release assets
shell: bash
run: |
mkdir -p release
cp {LICENSE,README.md} release/
cp "target/${{ matrix.build.TARGET }}/release/sbuild-linter" release/
- name: Create release artifacts
shell: bash
run: |
cp release/sbuild sbuild-${{ matrix.build.NAME }}
b3sum sbuild-${{ matrix.build.NAME }} \
> sbuild-${{ matrix.build.NAME }}.b3sum
tar -czvf sbuild-${{ matrix.build.NAME }}.tar.gz \
release/
b3sum sbuild-${{ matrix.build.NAME }}.tar.gz \
> sbuild-${{ matrix.build.NAME }}.tar.gz.b3sum
- name: Publish to GitHub
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: sbuild-linter-${{ matrix.build.NAME }}*
file_glob: true
overwrite: true
tag: ${{ github.ref }}
release_name: "sbuild v${{ env.RELEASE_VERSION }}"
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sbuild-linter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "sbuild-linter"
description = "Linter for SBUILD package files"
version = "0.3.2"
version = "0.3.3"
authors.workspace = true
license.workspace = true
edition.workspace = true
Expand Down
113 changes: 81 additions & 32 deletions sbuild/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
process::{Child, Command, Stdio},
sync::{self, Arc},
thread,
time::Duration,
};

use goblin::elf::Elf;
Expand Down Expand Up @@ -133,44 +134,85 @@ impl Builder {
}
}

async fn prepare_assets(
async fn prepare_resources(
&mut self,
build_config: &BuildConfig,
context: &BuildContext,
) -> Result<(), String> {
if let Some(ref build_assets) = build_config.build_asset {
self.download_build_assets(build_assets).await;
}

if let Some(ref desktop) = build_config.desktop {
let out_path = extract_filename(desktop);
self.logger
.info(&format!("Downloading desktop file from {}", desktop));
download(desktop, &out_path).await?;
let final_path = format!("{}.desktop", context.sbuild_pkg);
fs::rename(out_path, final_path).unwrap();
let out_path = if let Some(ref file) = desktop.file {
self.logger.info(&format!("Using local file from {}", file));
extract_filename(file)
} else if let Some(ref dir) = desktop.dir {
let out_path = format!("{}/{}.desktop", dir, context.sbuild_pkg);
self.logger
.info(&format!("Using local file from {}", out_path));
out_path
} else {
let url = &desktop.url.clone().unwrap();
let out_path = extract_filename(url);
self.logger
.info(&format!("Downloading desktop file from {}", url));
download(url, &out_path).await?;
out_path
};

let out_path = Path::new(&out_path);
if out_path.exists() {
let final_path = format!("{}.desktop", context.sbuild_pkg);
fs::rename(out_path, final_path).unwrap();
} else {
self.logger.error(&format!(
"Desktop file not found in {}. Skipping...",
self.desktop
));
}
}

if let Some(ref icon) = build_config.icon {
let out_path = extract_filename(icon);
self.logger.info(&format!("Downloading icon from {}", icon));
download(icon, &out_path).await?;
let magic_bytes = calc_magic_bytes(&out_path, 8);
if let Some(extension) = if magic_bytes == PNG_MAGIC_BYTES {
Some("png")
} else if magic_bytes[..4] == SVG_MAGIC_BYTES || magic_bytes[..5] == XML_MAGIC_BYTES {
Some("svg")
let out_path = if let Some(ref file) = icon.file {
self.logger.info(&format!("Using local file from {}", file));
extract_filename(file)
} else if let Some(ref dir) = icon.dir {
// TODO: add fallbacks
let out_path = format!("{}/.DirIcon", dir);
self.logger
.info(&format!("Using local file from {}", out_path));
out_path
} else {
None
} {
let final_path = format!("{}.{}", context.sbuild_pkg, extension);
self.logger.info(&format!("Renamed icon to {}", final_path));
fs::rename(out_path, final_path).unwrap();
let url = &icon.url.clone().unwrap();
let out_path = extract_filename(url);
self.logger.info(&format!("Downloading icon from {}", url));
download(url, &out_path).await?;
out_path
};

let out_path = Path::new(&out_path);
if out_path.exists() {
let magic_bytes = calc_magic_bytes(&out_path, 8);

if let Some(extension) = if magic_bytes == PNG_MAGIC_BYTES {
Some("png")
} else if magic_bytes[..4] == SVG_MAGIC_BYTES || magic_bytes[..5] == XML_MAGIC_BYTES
{
Some("svg")
} else {
None
} {
let final_path = format!("{}.{}", context.sbuild_pkg, extension);
self.logger.info(&format!("Renamed icon to {}", final_path));
fs::rename(out_path, final_path).unwrap();
} else {
let tmp_path = format!("{}/{}", context.tmpdir, out_path.display());
fs::rename(&out_path, &tmp_path).unwrap();
self.logger
.warn(&format!("Unsupported icon. Moved to {}", tmp_path));
}
} else {
let tmp_path = format!("{}/{}", context.tmpdir, out_path);
fs::rename(&out_path, &tmp_path).unwrap();
self.logger
.warn(&format!("Unsupported icon. Moved to {}", tmp_path));
self.logger.error(&format!(
"Desktop file not found in {}. Skipping...",
self.desktop
));
}
}

Expand Down Expand Up @@ -267,9 +309,8 @@ impl Builder {
}
}

if let Err(e) = self.prepare_assets(&build_config, context).await {
self.logger.error(&e);
return false;
if let Some(ref build_assets) = build_config.build_asset {
self.download_build_assets(build_assets).await;
}

let mut child = Command::new(exec_file)
Expand All @@ -281,6 +322,11 @@ impl Builder {
.spawn()
.unwrap();

if let Err(e) = self.prepare_resources(&build_config, context).await {
self.logger.error(&e);
return false;
}

self.setup_cmd_logging(&mut child);

let status = child.wait().unwrap();
Expand Down Expand Up @@ -340,7 +386,7 @@ impl Builder {

pub async fn build(&mut self, file_path: &str) -> bool {
let logger = self.logger.clone();
let linter = Linter::new(logger.clone());
let linter = Linter::new(logger.clone(), Duration::from_secs(120));

let pwd = env::current_dir().unwrap();
let mut success = false;
Expand All @@ -351,6 +397,9 @@ impl Builder {
if let Some(build_config) = linter.lint(file_path, false, false, true) {
if build_config._disabled {
logger.error(&format!("{} -> Disabled package. Skipping...", file_path));
if let Some(reason) = build_config._disabled_reason {
logger.error(&format!("{} -> {}", file_path, reason));
}
} else {
let version = fs::read_to_string(&version_file).ok();

Expand Down

0 comments on commit 6456561

Please sign in to comment.