Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 33 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ jobs:
parallel: true
flag-name: ${{ matrix.os }}-unit

- uses: actions/upload-artifact@v4
with:
path: ./target/release/pkgx

coverage-integration:
needs: fmt
strategy:
Expand All @@ -95,6 +91,10 @@ jobs:

- uses: dtolnay/rust-toolchain@stable

- uses: taiki-e/install-action@v2
with:
tool: rustfilt

- name: build
run: |
RUSTFLAGS="-C instrument-coverage" cargo build
Expand All @@ -111,6 +111,7 @@ jobs:
- run: pkgx +git --json=v1
- run: pkgx +git --json=v2
- run: pkgx git --version
- run: pkgx git@latest --version
- run: pkgx --silent +git
- run: pkgx --quiet +git
- run: pkgx +git -- git --version # lib/utils.rs:find_program
Expand All @@ -129,6 +130,9 @@ jobs:
# testing we correctly handle +pkg syntax for pkgs with no env
- run: pkgx +curl.se/ca-certs

- run: '! pkgx flubber-flubbles' # cmd not found machinery
- run: '! pkgx --sync flubber-flubbles' # cmd not found machinery separate if branch

# create a fork bomb, but since it’s via pkgx we prevent it
- run: |
echo '#!/bin/sh' > foo
Expand Down Expand Up @@ -158,23 +162,13 @@ jobs:
pkgx -Q hyperfine
! test -d ~/.pkgx/crates.io/hyperfine
! pkgx -Q flubber-flubber
! pkgx -Qqq flubber-flubber
pkgx -Q

- run: if [ $(find ~/.pkgx -name .tmp\* -type d | wc -l) -gt 0 ]; then
exit 1;
fi

- name: generate coverage
run: |
cargo install rustfilt
pkgx +llvm.org -- llvm-profdata merge -sparse default_*.profraw -o default.profdata
pkgx +llvm.org -- llvm-cov export \
./target/debug/pkgx \
--format=lcov \
--ignore-filename-regex="$HOME/.cargo" \
--instr-profile=default.profdata \
-Xdemangler=rustfilt \
> lcov.info

- name: --shebang test 1
run: |
echo "#!/usr/bin/env -S pkgx --shebang echo" > ./stub.sh
Expand All @@ -188,6 +182,29 @@ jobs:
run: |
pkgx semverator eq $(pkgx krampus=0.2.0 --version) 0.2.0
pkgx semverator gt $(pkgx krampus@latest --version) 0.2.0
env:
XDG_DATA_HOME: ${{ github.workspace }}/.data

- name: PKGX_PANTRY_DIR
run: |
git clone https://github.com/pkgxdev/pantry
pkgx hyperfine --version
PKGX_PANTRY_DIR=pantry pkgx hyperfine --version
env:
PKGX_PANTRY_DIR: ${{ github.workspace }}/pantry
PKGX_DIR: ${{ github.workspace }}/pkgx
PKGX_DIST_URL: https://dist.pkgx.dev

- name: generate coverage
run: |
pkgx +llvm.org -- llvm-profdata merge -sparse $(find . -name default_\*.prof\*) -o default.profdata
pkgx +llvm.org -- llvm-cov export \
./target/debug/pkgx \
--format=lcov \
--ignore-filename-regex="$HOME/.cargo" \
--instr-profile=default.profdata \
-Xdemangler=rustfilt \
> lcov.info

- uses: coverallsapp/github-action@v2
with:
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn parse() -> Args {
"--json" => {
if !silent {
eprintln!(
"{} use --json={}",
"{} use --json=v{}",
style("warning: --json is not stable").yellow(),
json_latest_v
);
Expand All @@ -75,7 +75,7 @@ pub fn parse() -> Args {
style("│").red()
);
eprintln!(
"{} you need to migrate to the new, isolated `dev` command",
"{} you need to migrate to the new, independent `dev` command",
style("│").red()
);
eprintln!("{} run the following:", style("│").red());
Expand Down
15 changes: 9 additions & 6 deletions crates/cli/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use libpkgx::{
};
use rusqlite::Connection;

use crate::{spinner::Spinner, which};
use crate::{
spinner::Spinner,
which::{which, WhichError},
};

pub async fn resolve(
args: &mut [String],
Expand All @@ -32,7 +35,7 @@ pub async fn resolve(
.join(pkgspec.project())
.is_dir()
{
let project = which::which(&pkgspec.project(), conn, &pkgs).await?;
let project = which(&pkgspec.project(), conn, &pkgs).await?;
pkgspec.set_project(project);
}

Expand All @@ -45,15 +48,15 @@ pub async fn resolve(

args[0] = cmd.clone(); // invoke eg. `node` rather than eg. `node@20`

let project = match which::which(&cmd, conn, &pkgs).await {
Err(which::WhichError::CmdNotFound(cmd)) => {
let project = match which(&cmd, conn, &pkgs).await {
Err(WhichError::CmdNotFound(cmd)) => {
if !did_sync {
spinner.set_message(&format!("{} not found, syncing…", cmd));
sync::update(config, conn).await?; // cmd not found ∴ sync in case it is new
spinner.set_message("resolving pkg graph…");
which::which(&cmd, conn, &pkgs).await
which(&cmd, conn, &pkgs).await
} else {
Err(which::WhichError::CmdNotFound(cmd))
Err(WhichError::CmdNotFound(cmd))
}
}
Err(err) => Err(err),
Expand Down
36 changes: 7 additions & 29 deletions crates/lib/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,6 @@ use libsemverator::semver::Semver as Version;
use reqwest::Url;
use std::error::Error;

// Custom error for download issues
#[derive(Debug)]
pub struct DownloadError {
pub status: u16,
pub src: String,
}

impl std::fmt::Display for DownloadError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Download error: status code {} from {}",
self.status, self.src
)
}
}

impl Error for DownloadError {}

// Select function to pick a version
pub async fn select(rq: &PackageReq, config: &Config) -> Result<Option<Version>, Box<dyn Error>> {
let versions = ls(&rq.project, config).await?;
Expand All @@ -45,14 +26,11 @@ pub async fn ls(project: &String, config: &Config) -> Result<Vec<Version>, Box<d
base_url, project, platform, arch
))?;

let rsp = build_client()?.get(url.clone()).send().await?;

if !rsp.status().is_success() {
return Err(Box::new(DownloadError {
status: rsp.status().as_u16(),
src: url.to_string(),
}));
}
let rsp = build_client()?
.get(url.clone())
.send()
.await?
.error_for_status()?;

let releases = rsp.text().await?;
let mut versions: Vec<Version> = releases
Expand All @@ -63,8 +41,8 @@ pub async fn ls(project: &String, config: &Config) -> Result<Vec<Version>, Box<d

if versions.is_empty() {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
format!("No versions for {}", project),
std::io::ErrorKind::NotFound,
format!("No inventory for {}", project),
)));
}

Expand Down