diff --git a/.github/workflows/release.yaml b/.github/workflows/release-linter.yaml similarity index 94% rename from .github/workflows/release.yaml rename to .github/workflows/release-linter.yaml index e39ad57..ea78dda 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release-linter.yaml @@ -1,10 +1,10 @@ -name: sbuilder release +name: sbuild-linter release on: workflow_dispatch: push: tags: - - "v*.*.*" + - "v*.*.*-linter" permissions: contents: write @@ -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: | diff --git a/.github/workflows/release-sbuild.yaml b/.github/workflows/release-sbuild.yaml new file mode 100644 index 0000000..5601290 --- /dev/null +++ b/.github/workflows/release-sbuild.yaml @@ -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 }}" diff --git a/Cargo.lock b/Cargo.lock index 3ac778b..6c8cbb4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1236,7 +1236,7 @@ dependencies = [ [[package]] name = "sbuild-linter" -version = "0.3.2" +version = "0.3.3" dependencies = [ "colored", "indexmap", diff --git a/sbuild-linter/Cargo.toml b/sbuild-linter/Cargo.toml index 53b7f66..bfbb152 100644 --- a/sbuild-linter/Cargo.toml +++ b/sbuild-linter/Cargo.toml @@ -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 diff --git a/sbuild/src/builder.rs b/sbuild/src/builder.rs index 93ca608..75f86e3 100644 --- a/sbuild/src/builder.rs +++ b/sbuild/src/builder.rs @@ -6,6 +6,7 @@ use std::{ process::{Child, Command, Stdio}, sync::{self, Arc}, thread, + time::Duration, }; use goblin::elf::Elf; @@ -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 + )); } } @@ -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) @@ -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(); @@ -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; @@ -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();