From b1eb2a4050bc245e6321afcfaf0e36fc13ba8e4e Mon Sep 17 00:00:00 2001 From: Marcel Hoppe Date: Tue, 4 Feb 2025 13:03:05 +0100 Subject: [PATCH 1/6] Add support for mise.toml --- index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.js b/index.js index eb71b4ed2..8b08d33d7 100644 --- a/index.js +++ b/index.js @@ -117,6 +117,8 @@ function parseRubyEngineAndVersion(rubyVersion) { rubyVersion = '.ruby-version' } else if (fs.existsSync('.tool-versions')) { rubyVersion = '.tool-versions' + } else if (fs.existsSync('mise.toml')) { + rubyVersion = 'mise.toml' } else { throw new Error('input ruby-version needs to be specified if no .ruby-version or .tool-versions file exists') } @@ -130,6 +132,11 @@ function parseRubyEngineAndVersion(rubyVersion) { const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s/.test(e))[0] rubyVersion = rubyLine.match(/^ruby\s+(.+)$/)[1] console.log(`Using ${rubyVersion} as input from file .tool-versions`) + } else if (rubyVersion === 'mise.toml') { // Read from mise.toml + const toolVersions = fs.readFileSync('mise.toml', 'utf8').trim() + const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s=\s/.test(e))[0] + rubyVersion = rubyLine.match(/^ruby\s=\s"(.+)"$/)[1] + console.log(`Using ${rubyVersion} as input from file mise.toml`) } let engine, version From db5b91146feda2afe72b78c014ccb0b521ba99eb Mon Sep 17 00:00:00 2001 From: Marcel Hoppe Date: Tue, 4 Feb 2025 13:06:20 +0100 Subject: [PATCH 2/6] Add mise.toml to action.yml --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 302149251..3e052125e 100644 --- a/action.yml +++ b/action.yml @@ -6,7 +6,7 @@ branding: icon: download inputs: ruby-version: - description: 'Engine and version to use, see the syntax in the README. Reads from .ruby-version or .tool-versions if unset.' + description: 'Engine and version to use, see the syntax in the README. Reads from .ruby-version, .tool-versions or mise.toml if unset.' default: 'default' rubygems: description: | @@ -26,7 +26,7 @@ inputs: description: 'Run "bundle install", and cache the result automatically. Either true or false.' default: 'false' working-directory: - description: 'The working directory to use for resolving paths for .ruby-version, .tool-versions and Gemfile.lock.' + description: 'The working directory to use for resolving paths for .ruby-version, .tool-versions, mise.toml and Gemfile.lock.' cache-version: description: | Arbitrary string that will be added to the cache key of the bundler cache. Set or change it if you need From fe28e301d2cd4961fc8149b89561829dc7448198 Mon Sep 17 00:00:00 2001 From: Marcel Hoppe Date: Tue, 4 Feb 2025 13:08:06 +0100 Subject: [PATCH 3/6] Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 150f04273..5bc0f1ecc 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ jobs: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: - ruby-version: '3.3' # Not needed with a `.ruby-version` or `.tool-versions` + ruby-version: '3.3' # Not needed with a `.ruby-version`, `.tool-versions` or `mise.toml` bundler-cache: true # runs 'bundle install' and caches installed gems automatically - run: bundle exec rake ``` @@ -139,11 +139,12 @@ and the [condition and expression syntax](https://help.github.com/en/actions/ref * engine only like `ruby` and `truffleruby`, uses the latest stable release of that implementation * `.ruby-version` reads from the project's `.ruby-version` file * `.tool-versions` reads from the project's `.tool-versions` file -* If the `ruby-version` input is not specified, `.ruby-version` is tried first, followed by `.tool-versions` +* `mise.toml` reads from the project's `mise.toml` file +* If the `ruby-version` input is not specified, `.ruby-version` is tried first, followed by `.tool-versions`, followed by `mise.toml` ### Working Directory -The `working-directory` input can be set to resolve `.ruby-version`, `.tool-versions` and `Gemfile.lock` +The `working-directory` input can be set to resolve `.ruby-version`, `.tool-versions`, `mise.toml` and `Gemfile.lock` if they are not at the root of the repository, see [action.yml](action.yml) for details. ### RubyGems From 8d6502bf66fc33df1782bab1c2cc3a9c46a9679e Mon Sep 17 00:00:00 2001 From: Marcel Hoppe Date: Tue, 4 Feb 2025 13:11:25 +0100 Subject: [PATCH 4/6] Add dist --- dist/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dist/index.js b/dist/index.js index 955621289..fe99bc1ec 100644 --- a/dist/index.js +++ b/dist/index.js @@ -74913,6 +74913,8 @@ function parseRubyEngineAndVersion(rubyVersion) { rubyVersion = '.ruby-version' } else if (fs.existsSync('.tool-versions')) { rubyVersion = '.tool-versions' + } else if (fs.existsSync('mise.toml')) { + rubyVersion = 'mise.toml' } else { throw new Error('input ruby-version needs to be specified if no .ruby-version or .tool-versions file exists') } @@ -74926,6 +74928,11 @@ function parseRubyEngineAndVersion(rubyVersion) { const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s/.test(e))[0] rubyVersion = rubyLine.match(/^ruby\s+(.+)$/)[1] console.log(`Using ${rubyVersion} as input from file .tool-versions`) + } else if (rubyVersion === 'mise.toml') { // Read from mise.toml + const toolVersions = fs.readFileSync('mise.toml', 'utf8').trim() + const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s=\s/.test(e))[0] + rubyVersion = rubyLine.match(/^ruby\s=\s"(.+)"$/)[1] + console.log(`Using ${rubyVersion} as input from file mise.toml`) } let engine, version From 674a514dc5f6fe422cc493db2b25b333cdfcfa85 Mon Sep 17 00:00:00 2001 From: Marcel Hoppe Date: Wed, 5 Feb 2025 07:18:58 +0100 Subject: [PATCH 5/6] Match " and ' --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 8b08d33d7..ee6443e71 100644 --- a/index.js +++ b/index.js @@ -135,7 +135,7 @@ function parseRubyEngineAndVersion(rubyVersion) { } else if (rubyVersion === 'mise.toml') { // Read from mise.toml const toolVersions = fs.readFileSync('mise.toml', 'utf8').trim() const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s=\s/.test(e))[0] - rubyVersion = rubyLine.match(/^ruby\s=\s"(.+)"$/)[1] + rubyVersion = rubyLine.match(/^ruby\s=\s['"](.+)['"]$/)[1] console.log(`Using ${rubyVersion} as input from file mise.toml`) } From fe5fa58f3377fa3c3d0f3bde23dd1f87d36eddf2 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Wed, 5 Feb 2025 10:28:41 +0100 Subject: [PATCH 6/6] Apply suggestions from code review --- dist/index.js | 4 ++-- index.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index fe99bc1ec..7d6c3821c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -74930,8 +74930,8 @@ function parseRubyEngineAndVersion(rubyVersion) { console.log(`Using ${rubyVersion} as input from file .tool-versions`) } else if (rubyVersion === 'mise.toml') { // Read from mise.toml const toolVersions = fs.readFileSync('mise.toml', 'utf8').trim() - const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s=\s/.test(e))[0] - rubyVersion = rubyLine.match(/^ruby\s=\s"(.+)"$/)[1] + const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s*=\s*/.test(e))[0] + rubyVersion = rubyLine.match(/^ruby\s*=\s*['"](.+)['"]$/)[1] console.log(`Using ${rubyVersion} as input from file mise.toml`) } diff --git a/index.js b/index.js index ee6443e71..e50f92dd9 100644 --- a/index.js +++ b/index.js @@ -134,8 +134,8 @@ function parseRubyEngineAndVersion(rubyVersion) { console.log(`Using ${rubyVersion} as input from file .tool-versions`) } else if (rubyVersion === 'mise.toml') { // Read from mise.toml const toolVersions = fs.readFileSync('mise.toml', 'utf8').trim() - const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s=\s/.test(e))[0] - rubyVersion = rubyLine.match(/^ruby\s=\s['"](.+)['"]$/)[1] + const rubyLine = toolVersions.split(/\r?\n/).filter(e => /^ruby\s*=\s*/.test(e))[0] + rubyVersion = rubyLine.match(/^ruby\s*=\s*['"](.+)['"]$/)[1] console.log(`Using ${rubyVersion} as input from file mise.toml`) }