diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2a68e57..60c1d9f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/README.md b/README.md index 371e1d3..3526922 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/lib/serverkit/mise.rb b/lib/serverkit/mise.rb index a78f63b..e1c8681 100644 --- a/lib/serverkit/mise.rb +++ b/lib/serverkit/mise.rb @@ -2,3 +2,4 @@ require_relative "mise/version" require_relative "resources/mise_install" +require_relative "resources/mise_use" diff --git a/lib/serverkit/resources/mise_install.rb b/lib/serverkit/resources/mise_install.rb index 2c90949..82e50e4 100644 --- a/lib/serverkit/resources/mise_install.rb +++ b/lib/serverkit/resources/mise_install.rb @@ -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}" @@ -35,6 +35,7 @@ def name_with_version end end + # @return [String] def version_or_latest version || "latest" end diff --git a/lib/serverkit/resources/mise_use.rb b/lib/serverkit/resources/mise_use.rb new file mode 100644 index 0000000..ff51cdd --- /dev/null +++ b/lib/serverkit/resources/mise_use.rb @@ -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}") + 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