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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
ruby: ["3.1", "3.2", "3.3", "3.3"]
ruby: ["3.1", "3.2", "3.3", "3.4"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
36 changes: 27 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
[![Ruby](https://github.com/serverkit/serverkit-mise/actions/workflows/main.yml/badge.svg)](https://github.com/serverkit/serverkit-mise/actions/workflows/main.yml)
[![Test](https://github.com/serverkit/serverkit-mise/actions/workflows/test.yml/badge.svg)](https://github.com/serverkit/serverkit-mise/actions/workflows/test.yml)

# Serverkit::Mise
# serverkit-mise

TODO: Delete this and the text below, and describe your gem

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/serverkit/mise`. To experiment with that code, run `bin/console` for an interactive prompt.
[Serverkit](https://github.com/serverkit/serverkit) plug-in for [mise](https://github.com/jdx/mise).

## Installation

TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
TODO: Replace `serverkit-mise` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.

Install the gem and add to the application's Gemfile by executing:

```bash
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
bundle add serverkit-mise
```

If bundler is not being used to manage dependencies, install the gem by executing:

```bash
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
gem install serverkit-mise
```

## Usage
Expand Down Expand Up @@ -48,9 +46,29 @@ resources:
version: 3.4.3
```

### mise_use

Install specified tool and add the version to `mise.yml`.

#### Attributes

- `name` - tool name (required)
- `version` - tool version (optional)

#### Example

```yaml
resources:
- type: mise_use
name: go
version: '1.23'
- type: mise_use
name: ruby
```

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/serverkit-mise.
Bug reports and pull requests are welcome on GitHub at [serverkit/serverkit-mise](https://github.com/serverkit/serverkit-mise).

## License

Expand Down
1 change: 1 addition & 0 deletions lib/serverkit/mise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

require_relative "mise/version"
require_relative "resources/mise_install"
require_relative "resources/mise_use"
3 changes: 2 additions & 1 deletion lib/serverkit/resources/mise_install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def default_id
end

# @return [String]
# @example "git-plus@4.4.11"
# @example "ruby@3.4.3"
def name_with_version
if version
"#{name}@#{version}"
Expand All @@ -35,6 +35,7 @@ def name_with_version
end
end

# @return [String]
def version_or_latest
version || "latest"
end
Expand Down
54 changes: 54 additions & 0 deletions lib/serverkit/resources/mise_use.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

require "serverkit/resources/base"

module Serverkit
module Resources
class MiseUse < Base
attribute :name, required: true, type: String
attribute :version, type: String
# FIXME: add global option
attribute :global, type: [TrueClass, FalseClass] # , default: true

# @note Override
def apply
run_command("mise use --global #{name_with_version}")
Copy link

Copilot AI Apr 23, 2025

Choose a reason for hiding this comment

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

The apply method always appends the '--global' flag irrespective of the 'global' attribute. Consider modifying the command to conditionally include '--global' based on the 'global' attribute's value, to ensure consistent behavior with the check method.

Suggested change
run_command("mise use --global #{name_with_version}")
run_command("mise use #{global_option}#{name_with_version}")

Copilot uses AI. Check for mistakes.
end

# @note Override
def check
cmd = if global
"mise ls --global #{name} | grep '#{version_or_latest}'"
else
"mise ls --current #{name} | grep '#{version_or_latest}'"
end
check_command(cmd)
end

private

# @note Override
def default_id
name
end

# @return [String]
# @example "ruby@3.4.3"
def name_with_version
if version
"#{name}@#{version}"
else
name
end
end

def version_or_latest
version || "latest"
end

# def global_option
# "--global" if global
# end
end
end
end