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
4 changes: 1 addition & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
.vscode

# Local build artifacts
target/
why
why.exe
tests/test_why_core
tests/test_why_core.exe
nimcache/

# Editor/OS noise
Thumbs.db
53 changes: 5 additions & 48 deletions .github/scripts/generate_formula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,13 @@ VERSION=$1
URL=$2
SHA256=$3

NIMBLE_FILE="why_cli.nimble"
readonly VERSION URL SHA256

if [ ! -f "$NIMBLE_FILE" ]; then
echo "Error: $NIMBLE_FILE not found." >&2
if [ ! -f "Cargo.toml" ]; then
echo "Error: Cargo.toml not found." >&2
exit 1
fi

get_nimble_version() {
local pkg_name=$1
# Extract version from lines like: requires "cligen >= 1.7.0"
grep "requires \"$pkg_name" "$NIMBLE_FILE" | sed -E 's/.*>= *([0-9.]+).*/\1/'
}

generate_resource() {
local name=$1
local repo_url_base=$2

local ver=$(get_nimble_version "$name")

if [ -z "$ver" ]; then
echo "Error: Could not find version for $name in $NIMBLE_FILE" >&2
exit 1
fi

local dl_url="${repo_url_base}/archive/refs/tags/${ver}.tar.gz"

local tmp_file="/tmp/${name}-${ver}.tar.gz"

curl -sL "$dl_url" -o "$tmp_file"
local sha=$(sha256sum "$tmp_file" | awk '{print $1}')
rm "$tmp_file"

echo " resource \"$name\" do"
echo " url \"$dl_url\""
echo " sha256 \"$sha\""
echo " end"
}

cat <<EOF
class Why < Formula
desc "Show where a command on your system really comes from"
Expand All @@ -52,22 +21,10 @@ class Why < Formula
sha256 "${SHA256}"
license "MIT"

depends_on "nim" => :build

EOF

# Define dependencies here. The version is auto-detected from .nimble.
generate_resource "cligen" "https://github.com/c-blake/cligen"

cat <<EOF
depends_on "rust" => :build

def install
resource("cligen").stage do
(buildpath/"vendor/cligen").install Dir["*"]
end

system "nim", "c", "-d:release", "--path:#{buildpath}/vendor/cligen", "-o:why", "src/why.nim"
bin.install "why"
system "cargo", "install", "--locked", *std_cargo_args
end

test do
Expand Down
47 changes: 30 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,49 @@ jobs:
- ubuntu-latest
- macos-latest
steps:
- uses: actions/checkout@v4

- name: Install Nim
uses: jiro4989/setup-nim-action@v2
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
nim-version: '2.2.6'
persist-credentials: false

- name: Cache Nimble and Nim
uses: actions/cache@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
with:
path: |
~/.nimble
~/.cache/nim
key: ${{ runner.os }}-nim-2.2.6-nimble-${{ hashFiles('nimble.lock') }}
restore-keys: |
${{ runner.os }}-nim-2.2.6-nimble-
components: clippy, rustfmt

- name: Cache Cargo
uses: Swatinem/rust-cache@42dc69e1aa15d09112580998cf2ef0119e2e91ae # v2

- name: Check Formatting
run: cargo fmt --check

- name: Install Dependencies
run: nimble install -y --depsOnly
- name: Run Clippy
run: cargo clippy --all-targets -- -D warnings

- name: Run Tests
run: nimble test
run: cargo test --locked

e2e:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false

- name: Run E2E Tests
run: ./tests/e2e/run.sh
env:
E2E_JOBS: 2

nix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false

- name: Install Nix
uses: cachix/install-nix-action@b97f05dcb019ddea06450a50ef6203d2fdc19fee # v31

- name: Build Nix Package
run: nix build
57 changes: 33 additions & 24 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,48 @@ jobs:
matrix:
include:
- os: ubuntu-24.04
target: x86_64-unknown-linux-gnu
target_os: linux
cpu: amd64
archive_name: why-linux-amd64
- os: ubuntu-24.04
install_cross: ''
linker_env: ''
- os: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
target_os: linux
cpu: arm64
archive_name: why-linux-arm64
install_cross: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu
nim_flags: --cpu:arm64 --os:linux --gcc.exe:aarch64-linux-gnu-gcc --gcc.linkerexe:aarch64-linux-gnu-gcc
install_cross: ''
linker_env: ''
- os: macos-15-intel
target: x86_64-apple-darwin
target_os: darwin
cpu: amd64
archive_name: why-darwin-amd64
install_cross: ''
linker_env: ''
- os: macos-15
target: aarch64-apple-darwin
target_os: darwin
cpu: arm64
archive_name: why-darwin-arm64
install_cross: ''
linker_env: ''

steps:
- uses: actions/checkout@v6

- name: Cache Nimble dependencies
uses: actions/cache@v4
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
path: ~/.nimble
key: ${{ runner.os }}-nimble-${{ hashFiles('nimble.lock') }}
restore-keys: |
${{ runner.os }}-nimble-
persist-credentials: false

- name: Install Nim
uses: jiro4989/setup-nim-action@v2
- name: Install Rust
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
with:
nim-version: '2.2.6'
targets: ${{ matrix.target }}

- name: Install Dependencies
run: nimble install -y --depsOnly
- name: Cache Cargo
uses: Swatinem/rust-cache@42dc69e1aa15d09112580998cf2ef0119e2e91ae # v2
with:
save-if: "false"

- name: Install Cross-compiler (Linux ARM64 only)
if: matrix.install_cross != ''
Expand All @@ -60,14 +66,14 @@ jobs:
- name: Build
shell: bash
run: |
nimble build -d:release ${{ matrix.nim_flags }}
mv why ${{ matrix.archive_name }}
${{ matrix.linker_env }} cargo build --release --locked --target ${{ matrix.target }}
cp target/${{ matrix.target }}/release/why ${{ matrix.archive_name }}

- name: Create Archive
run: tar czf ${{ matrix.archive_name }}.tar.gz ${{ matrix.archive_name }}

- name: Release to GitHub
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: ${{ matrix.archive_name }}.tar.gz
Expand All @@ -80,13 +86,16 @@ jobs:
if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '-')
steps:
- name: Checkout why-cli repository (for scripts)
uses: actions/checkout@v4
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false

- name: Checkout tap repository
uses: actions/checkout@v4
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
repository: akriaueno/homebrew-tap
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
persist-credentials: false
path: homebrew-tap

- name: Ensure Formula directory exists
Expand All @@ -105,8 +114,8 @@ jobs:
# Calculate SHA256 hash
SHA256=$(sha256sum source.tar.gz | awk '{print $1}')

echo "sha=$SHA256" >> $GITHUB_OUTPUT
echo "url=$SOURCE_URL" >> $GITHUB_OUTPUT
echo "sha=$SHA256" >> "$GITHUB_OUTPUT"
echo "url=$SOURCE_URL" >> "$GITHUB_OUTPUT"

- name: Generate Formula
run: |
Expand All @@ -123,7 +132,7 @@ jobs:
echo "========================="

- name: Create PR on tap repository
uses: peter-evans/create-pull-request@v8
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8
with:
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} # fine-grained PAT (homebrew-tap, contents:write & pull-requests:write)
path: homebrew-tap
Expand Down
10 changes: 2 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
# Output binaries
/target/
result
why
why.exe
tests/test_why_core
tests/test_why_core.exe
tests/e2e/why-linux-amd64

# Nimble files
nimble.develop
config.nims
nimble.paths
nimbledeps

# LLM utilities
repomix-output.xml

Expand Down
Loading