Skip to content

Install specific CLI versions - #2040

Merged
lionello merged 3 commits into
mainfrom
lio/install-version
Apr 10, 2026
Merged

Install specific CLI versions#2040
lionello merged 3 commits into
mainfrom
lio/install-version

Conversation

@lionello

@lionello lionello commented Apr 9, 2026

Copy link
Copy Markdown
Member

Description

  • allow passing version as arg
  • make script compatible with ash (alpine) and sh
  • wrap in top-level function to avoid pollution user env

Linked Issues

Checklist

  • I have performed a self-review of my code
  • I have added appropriate tests
  • I have updated the Defang CLI docs and/or README to reflect my changes, if necessary

Summary by CodeRabbit

  • New Features

    • Added support for installing nightly versions of the software.
  • Improvements

    • Broadened shell compatibility for wider system support.
    • Improved command-line argument parsing for explicit version selection and automatic confirmation.
    • More robust handling of shell profile and completion installation.
  • Chores

    • Added an automated nightly installation step to the CI workflow.

@coderabbitai

coderabbitai Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Updated the GitHub Actions workflow to add a new "Install with bash (nightly)" step and adjusted quoting in on.push.paths. Refactored the installer (src/bin/install) for POSIX sh: added a _defang_install() wrapper, converted Bash-only constructs to portable forms, and revised argument parsing and cleanup.

Changes

Cohort / File(s) Summary
Workflow Configuration
\.github/workflows/install.yml
Adjusted on.push.paths quoting; added an "Install with bash (nightly)" step that runs bash <(curl -fsSL s.defang.io/install) nightly with shell: bash and provides GITHUB_TOKEN from secrets.GITHUB_TOKEN.
Installer Script
src/bin/install
Added #!/bin/sh shebang and top-level _defang_install() function; moved execution into "$@" invocation and unsets helper functions after run. Rewrote argument parsing to a loop supporting -y and version positional; replaced Bash-specific syntax ([[, =~, case-only zsh checks) with POSIX [ ... ] and case patterns; converted conditional curl assignment to POSIX-form and adjusted completion/profile edit checks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I hopped to code and found a quirk,
Swapped Bash for POSIX — what a perk!
Wrapped my hops in _defang_install(), neat,
Now every shell can share my treat.
Curl, token, nightly — ready to greet. 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Install specific CLI versions' directly reflects the main objective of the PR, which is to add support for passing a version argument to the install script.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch lio/install-version

Comment @coderabbitai help to get the list of available commands and usage tips.

@lionello
lionello force-pushed the lio/install-version branch from bee5400 to f60f52e Compare April 9, 2026 22:20
@lionello
lionello marked this pull request as ready for review April 10, 2026 00:56

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
.github/workflows/install.yml (1)

34-39: Consider adding a sanity check for the nightly install.

The other install steps are followed by a defang --version sanity check. Adding one here would verify the nightly installation completed successfully.

Suggested addition
       - name: Install with bash (nightly)
         shell: bash
         run: bash <(curl -fsSL s.defang.io/install) nightly
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # alt name
+
+      - name: Sanity check
+        run: defang --version
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/install.yml around lines 34 - 39, In the "Install with
bash (nightly)" step where you run "bash <(curl -fsSL s.defang.io/install)
nightly", add a follow-up sanity check that runs "defang --version" (or
equivalent CLI health/version command) and fail the step if it does not return a
valid exit code/output; ensure the new command is executed in the same step or
as an immediately subsequent step so the workflow verifies the nightly
installation completed successfully.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/bin/install`:
- Around line 36-44: The loop uses the temporary variable _arg which can leak
into the caller's environment when the script is sourced/eval'd; after the for
loop that parses arguments (where _arg is assigned and
DEFANG_INSTALL_VERSION/REPLY/CI are set) add an unset _arg (or include _arg in
the existing unset list) so the temporary variable is removed from the
environment to avoid pollution when the script is sourced.
- Around line 279-282: The FPATH presence check is using the wrong string
("site_functions" with underscore) so it never matches the actual added path
("site-functions" with hyphen); update the case pattern that tests FPATH (the
"*":$HOME/.local/share/zsh/site_functions:"*) to use the correct hyphenated
directory name ("*":$HOME/.local/share/zsh/site-functions:"*) so the conditional
around _prompt_and_append_to_file and the profile_file update behaves correctly.

---

Nitpick comments:
In @.github/workflows/install.yml:
- Around line 34-39: In the "Install with bash (nightly)" step where you run
"bash <(curl -fsSL s.defang.io/install) nightly", add a follow-up sanity check
that runs "defang --version" (or equivalent CLI health/version command) and fail
the step if it does not return a valid exit code/output; ensure the new command
is executed in the same step or as an immediately subsequent step so the
workflow verifies the nightly installation completed successfully.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b0288c4f-9d25-43ac-95de-a2297e5966dd

📥 Commits

Reviewing files that changed from the base of the PR and between 2043c75 and f60f52e.

📒 Files selected for processing (2)
  • .github/workflows/install.yml
  • src/bin/install

Comment thread src/bin/install
Comment thread src/bin/install
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/bin/install (1)

262-262: Consider quoting shell variables for defensive scripting.

While shell names (bash, zsh) won't contain spaces, quoting variables is a POSIX best practice and prevents issues with unexpected values.

Suggested changes
     echo "Generating completion script at $target"
     mkdir -p "$(dirname "$target")"
-    defang completion $shell > "$target"
+    defang completion "$shell" > "$target"
 }
-_install_completion_script $SHELL || true
+_install_completion_script "$SHELL" || true
 CURRENT_SHELL=${0#-}
-[ "$CURRENT_SHELL" != "$SHELL" ] && _install_completion_script $CURRENT_SHELL || true
+[ "$CURRENT_SHELL" != "$SHELL" ] && _install_completion_script "$CURRENT_SHELL" || true

Similarly for the _generate_completion_script calls inside _install_completion_script.

Also applies to: 289-291

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/bin/install` at line 262, Quote shell variables in redirection and
command arguments to follow POSIX defensive scripting: update the defang
invocation so the $shell variable is quoted (e.g., use "$shell") and likewise
quote any uses of $shell in calls to _generate_completion_script inside the
_install_completion_script function; ensure all variable expansions used as
arguments or in redirections (including target and shell) are wrapped in double
quotes to avoid word-splitting or globbing issues.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/bin/install`:
- Around line 272-275: The check using BASH_COMPLETION_VERSINFO in the install
script is unreliable because that variable is only set in interactive shells;
replace it by testing for a bash-completion installation file instead (e.g.,
check existence/readability of /etc/bash_completion or
/usr/share/bash-completion/bash_completion) or remove the warning entirely to
avoid false positives; update the block that references BASH_COMPLETION_VERSINFO
to perform a filesystem check for bash-completion files (or skip the check) and
adjust the warning/return logic accordingly so the script only warns when those
files are absent.

---

Nitpick comments:
In `@src/bin/install`:
- Line 262: Quote shell variables in redirection and command arguments to follow
POSIX defensive scripting: update the defang invocation so the $shell variable
is quoted (e.g., use "$shell") and likewise quote any uses of $shell in calls to
_generate_completion_script inside the _install_completion_script function;
ensure all variable expansions used as arguments or in redirections (including
target and shell) are wrapped in double quotes to avoid word-splitting or
globbing issues.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ff5ab719-90ff-40d7-a025-cd433988f642

📥 Commits

Reviewing files that changed from the base of the PR and between f60f52e and 973fc4f.

📒 Files selected for processing (1)
  • src/bin/install

Comment thread src/bin/install
@lionello
lionello merged commit faf93d4 into main Apr 10, 2026
16 checks passed
@lionello
lionello deleted the lio/install-version branch April 10, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants