Skip to content
Open
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
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ jobs:
run: gem install json -v 2.2.0
- name: C extension test with vcpkg libraries (mswin)
run: gem install fiddle:1.1.8 zlib:3.2.4
if: matrix.ruby == 'mswin'
if: startsWith(matrix.ruby, 'mswin')
- name: Load C extensions linked to vcpkg libraries (mswin)
run: ruby -rfiddle -e 'gem %q(zlib), %q(3.2.4); require %q(zlib); p Zlib.crc32(%q(a))'
if: matrix.ruby == 'mswin'
if: startsWith(matrix.ruby, 'mswin')
- run: bundle --version
# This step is redundant with `bundler-cache: true` but is there to check a redundant `bundle install` still works
- run: bundle install
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
shell: bash
run: which -a bundle
# https://github.com/ruby/setup-ruby/issues/658
if: "matrix.ruby != 'mingw' && matrix.ruby != 'mswin' && matrix.ruby != 'ucrt'"
if: "matrix.ruby != 'mingw' && matrix.ruby != 'ucrt'"
- name: which rake
run: which -a rake
if: runner.os != 'Windows'
Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This action currently supports these versions of MRI, JRuby and TruffleRuby:

| Interpreter | Versions |
| ----------- | -------- |
| `ruby` | 1.9.3, 2.0.0, 2.1.9, 2.2, all versions from 2.3.0 until 4.1.0-preview1, head, debug, mingw, mswin, ucrt |
| `ruby` | 1.9.3, 2.0.0, 2.1.9, 2.2, all versions from 2.3.0 until 4.1.0-preview1, head, debug, mingw, ucrt |
| `jruby` | 9.1.17.0 - 10.1.3.0, head |
| `truffleruby` | 19.3.0 - 40.0.0, head |
| `truffleruby+graalvm` | 21.2.0 - 40.0.0, head |
Expand All @@ -28,14 +28,19 @@ Native extensions are automatically compiled with AddressSanitizer when using `r

`ruby-asan` and `asan-release` are currently only available on `ubuntu-24.04` and `ubuntu-26.04`.

Regarding Windows ruby master builds, `mingw` is a MSYS2/MinGW build, `head` & `ucrt` are MSYS2/UCRT64
builds, and `mswin` is a MSVC build.
Regarding Windows ruby master builds, `mingw` is a MSYS2/MinGW build, and `head` & `ucrt` are MSYS2/UCRT64 builds.

`mswin` is CRuby built with MSVC, available on Windows only.
Use it to test that native extensions build and work with MSVC. The default Windows versions stay on RubyInstaller, which most precompiled gems target.
`mswin-4.0` installs the latest 4.0.x release and `mswin-head` the master build.
`mswin` alone also installs the master build for now but will install the latest release in the future, so use `mswin-head` to keep testing master.
The available versions are listed in [windows-mswin-versions.json](windows-mswin-versions.json).

Preview and RC versions of Ruby might be available too on Ubuntu and macOS (not on Windows).
However, it is recommended to test against `ruby-head` rather than previews,
as it provides more useful feedback for the Ruby core team and for upcoming changes.

Only release versions published by [RubyInstaller](https://rubyinstaller.org/downloads/archives/)
Apart from `mswin`, only release versions published by [RubyInstaller](https://rubyinstaller.org/downloads/archives/)
are available on Windows. Due to that, Ruby 2.2 resolves to 2.2.6 on Windows and 2.2.10
on other platforms. Ruby 2.3 on Windows only has builds for 2.3.0, 2.3.1 and 2.3.3.

Expand All @@ -54,7 +59,7 @@ The action works on these [GitHub-hosted runners](https://docs.github.com/en/act

Not all combinations of runner images and versions are supported.
The full list of available Ruby versions can be seen in [here for Ubuntu and macOS](https://github.com/ruby/ruby-builder/releases)
and in [windows-versions.json](windows-versions.json) for Windows.
and in [windows-versions.json](windows-versions.json) and [windows-mswin-versions.json](windows-mswin-versions.json) for Windows.
Newer runner images only have builds of the latest patch release of each series,
so prefer a short version like `'3.4'` over an exact one like `'3.4.2'`, or pin to a specific runner version (e.g. `ubuntu-24.04`).
For example, `ubuntu-26.04` (which `ubuntu-latest` now points to, see [this announcement](https://github.com/actions/runner-images/issues/14748))
Expand All @@ -63,7 +68,7 @@ only has builds of CRuby 2.3 and newer, as older CRuby versions do not compile o
The prebuilt releases are generated by [ruby-builder](https://github.com/ruby/ruby-builder)
and on Windows by [RubyInstaller2](https://github.com/oneclick/rubyinstaller2).
The `mingw` and `ucrt` builds are generated by [ruby-loco](https://github.com/MSP-Greg/ruby-loco).
The `mswin` build is the daily master build published at [cache.ruby-lang.org](https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/).
The `mswin` builds are generated by [ruby/actions](https://github.com/ruby/actions) and published at [cache.ruby-lang.org](https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/).
`ruby-head` is generated by [ruby-dev-builder](https://github.com/ruby/ruby-dev-builder),
`jruby-head` is generated by [jruby-dev-builder](https://github.com/ruby/jruby-dev-builder),
`truffleruby-head` and `truffleruby+graalvm-head` are generated by [truffleruby-dev-builder](https://github.com/ruby/truffleruby-dev-builder).
Expand Down
4 changes: 3 additions & 1 deletion bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ async function computeBaseKey(engine, version, lockFile, cacheVersion) {
const bundleWith = process.env['BUNDLE_WITH'] || ''
const bundleWithout = process.env['BUNDLE_WITHOUT'] || ''
const bundleOnly = process.env['BUNDLE_ONLY'] || ''
let key = `setup-ruby-bundler-cache-v6-${common.getOSNameVersionArch()}-${engine}-${version}-wd-${cwd}-with-${bundleWith}-without-${bundleWithout}-only-${bundleOnly}`
// Gems built for mswin cannot load in the RubyInstaller build of the same version
const ruby = common.inputs.mswin ? `${engine}-${version}-mswin` : `${engine}-${version}`
let key = `setup-ruby-bundler-cache-v6-${common.getOSNameVersionArch()}-${ruby}-wd-${cwd}-with-${bundleWith}-without-${bundleWithout}-only-${bundleOnly}`

if (cacheVersion !== DEFAULT_CACHE_VERSION) {
key += `-v-${cacheVersion}`
Expand Down
8 changes: 5 additions & 3 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const PATH_ENV_VAR = windows ? 'Path' : 'PATH'

export const inputs = {
selfHosted: undefined,
token: undefined
token: undefined,
mswin: undefined
}

export function partition(string, separator) {
Expand Down Expand Up @@ -70,7 +71,7 @@ export async function time(name, block) {

export function isHeadVersion(rubyVersion) {
// asan-release counts as "head" because the version cannot be selected -- you can only get whatever's latest
return ['head', 'debug', 'mingw', 'mswin', 'ucrt', 'asan', 'asan-release'].includes(rubyVersion)
return ['head', 'debug', 'mingw', 'ucrt', 'asan', 'asan-release'].includes(rubyVersion)
}

export function isStableVersion(engine, rubyVersion) {
Expand Down Expand Up @@ -292,7 +293,8 @@ function findWindowsVersion() {
}

export function shouldUseToolCache(engine, version) {
return (engine === 'ruby' && !isHeadVersion(version)) || isSelfHostedRunner()
// The tool cache of runners holds RubyInstaller builds under the same Ruby/<version> names as mswin
return (engine === 'ruby' && !isHeadVersion(version) && !inputs.mswin) || isSelfHostedRunner()
}

export function getToolCachePath() {
Expand Down
66 changes: 52 additions & 14 deletions dist/index.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions generate-test-matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def unique_versions(versions, segment_count, *symbolic)
# Versions
ruby_builder_versions = JSON.load(File.read('ruby-builder-versions.json'))
windows_versions = JSON.load(File.read('windows-versions.json'))
windows_mswin_versions = JSON.load(File.read('windows-mswin-versions.json'))

# ruby: each minor release + head
ruby_versions = unique_versions(ruby_builder_versions['ruby'], 2, 'head')
Expand All @@ -63,8 +64,11 @@ def unique_versions(versions, segment_count, *symbolic)
ruby_loco_versions = %w[mingw ucrt]
matrix += windows_x64_runners.product(ruby_loco_versions)

# mswin: head
matrix += windows_runners.product(%w[mswin])
# mswin: each minor release + head, on the runners of each arch that has a build of it
{ 'x64' => windows_x64_runners, 'arm64' => windows_arm64_runners }.each do |arch, arch_runners|
mswin_versions = windows_mswin_versions.select { |_, builds| builds.key?(arch) }.keys
matrix += arch_runners.product(unique_versions(mswin_versions, 2, 'head').map { |version| "mswin-#{version}" })
end

# asan: latest release + head
asan_versions = %w[asan-release asan]
Expand Down
78 changes: 60 additions & 18 deletions generate-windows-versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
WINDOWS_VERSIONS_URLS_REGEXPS = [
%r{\A#{Regexp.escape 'https://github.com/oneclick/rubyinstaller/releases/download'}/\w[\w.-]*/\w[\w.-]*\z},
%r{\A#{Regexp.escape 'https://github.com/oneclick/rubyinstaller2/releases/download'}/\w[\w.-]*/\w[\w.-]*\z},
%r{\A#{Regexp.escape 'https://github.com/MSP-Greg/ruby-loco/releases/download'}/\w[\w.-]*/\w[\w.-]*\z},
%r{\A#{Regexp.escape 'https://github.com/MSP-Greg/ruby-loco/releases/download'}/\w[\w.-]*/\w[\w.-]*\z}
].freeze

MSWIN_VERSIONS_URLS_REGEXPS = [
%r{\A#{Regexp.escape 'https://cache.ruby-lang.org/pub/ruby/binaries/mswin64'}/\w[\w.-]*\z},
%r{\A#{Regexp.escape 'https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/dev'}/\w[\w.-]*\z}
].freeze

Expand Down Expand Up @@ -67,10 +71,6 @@ def validate(versions, allowed_urls_regexps)
versions['mingw'] = {
'x64' => 'https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-mingw.7z'
}
versions['mswin'] = {
'arm64' => 'https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/dev/ruby-head-arm64-mswin64_140.zip',
'x64' => 'https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/dev/ruby-head-x64-mswin64_140.zip'
}
versions['ucrt'] = {
'x64' => 'https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-ucrt.7z'
}
Expand All @@ -81,6 +81,20 @@ def validate(versions, allowed_urls_regexps)
base_url = 'https://github.com/ruby/setup-msys2-gcc/releases/latest/download/windows-toolchain.json'
windows_toolchain = JSON.parse(URI.open(base_url, &:read), symbolize_names: true)

find_toolchain = -> platform, version {
toolchain = windows_toolchain.select do |pkg|
pkg[:platform] == platform && pkg[:required_ruby_version].any? do |requirement|
Gem::Requirement.new(requirement).satisfied_by?(version)
end
end

unless toolchain.one?
raise "#{toolchain.empty? ? 'no' : 'multiple'} toolchains found for #{platform} #{version}: #{toolchain}"
end

toolchain.first
}

versions.each do |raw_version, archs|
version = Gem::Version.correct?(raw_version) ? Gem::Version.new(raw_version) : head_version

Expand All @@ -93,8 +107,6 @@ def validate(versions, allowed_urls_regexps)
"#{arch}-mingw-ucrt"
when 'mingw'
"#{arch}-mingw32"
when 'mswin'
"#{raw_arch}-mswin64"
else
if version >= Gem::Version.new('3.1.0.dev')
"#{arch}-mingw-ucrt"
Expand All @@ -103,20 +115,50 @@ def validate(versions, allowed_urls_regexps)
end
end

toolchain =
windows_toolchain.select do |pkg|
pkg[:platform] == platform && pkg[:required_ruby_version].any? do |requirement|
Gem::Requirement.new(requirement).satisfied_by?(version)
end
end

unless toolchain.one?
raise "#{toolchain.empty? ? 'no' : 'multiple'} toolchains found for #{raw_version} #{raw_arch}: #{toolchain}"
end
toolchain = find_toolchain.(platform, version)

archs[raw_arch] = URI.join(base_url, toolchain.first[:href]).to_s
archs[raw_arch] = URI.join(base_url, toolchain[:href]).to_s
end
end

validate(versions, WINDOWS_TOOLCHAIN_VERSIONS_URLS_REGEXPS)
File.binwrite 'windows-toolchain-versions.json', "#{JSON.pretty_generate(versions)}\n"

mswin_index = JSON.parse(URI.open('https://cache.ruby-lang.org/pub/ruby/binaries/index.json', &:read), symbolize_names: true)

# mkmf of Ruby 3.3 and older ignores ENV['PKG_CONFIG'], so it would not use the vcpkg pkgconf that installVCPKG sets up
mswin_versions = mswin_index[:builds].select { |build|
build[:channel] == 'release' && build[:platform].end_with?('-mswin64_140') && Gem::Version.new(build[:version]) >= Gem::Version.new('3.4')
}.group_by { |build|
build[:version]
}.sort_by { |version, _|
Gem::Version.new(version)
}.to_h { |version, builds_by_version|
builds = builds_by_version.group_by { |build|
build[:platform].delete_suffix('-mswin64_140')
}.sort.to_h { |arch, builds_by_arch|
# A release is repackaged with a higher revision when a bundled library needs an update
[arch, builds_by_arch.max_by { |build| build[:revision] }[:url]]
}
[version, builds]
}

mswin_versions['head'] = {
'arm64' => 'https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/dev/ruby-head-arm64-mswin64_140.zip',
'x64' => 'https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/dev/ruby-head-x64-mswin64_140.zip'
}

validate(mswin_versions, MSWIN_VERSIONS_URLS_REGEXPS)
File.binwrite 'windows-mswin-versions.json', "#{JSON.pretty_generate(mswin_versions)}\n"

mswin_toolchain_versions = mswin_versions.to_h do |raw_version, archs|
version = raw_version == 'head' ? head_version : Gem::Version.new(raw_version)

toolchains = archs.to_h do |arch, _|
[arch, URI.join(base_url, find_toolchain.("#{arch}-mswin64", version)[:href]).to_s]
end
[raw_version, toolchains]
end

validate(mswin_toolchain_versions, WINDOWS_TOOLCHAIN_VERSIONS_URLS_REGEXPS)
File.binwrite 'windows-mswin-toolchain-versions.json', "#{JSON.pretty_generate(mswin_toolchain_versions)}\n"
22 changes: 18 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ export async function setupRuby(options = {}) {
process.chdir(inputs['working-directory'])

const platform = common.getOSNameVersion()
const [engine, parsedVersion] = parseRubyEngineAndVersion(inputs['ruby-version'])
const [engine, parsedVersion, mswin] = parseRubyEngineAndVersion(inputs['ruby-version'])
common.inputs.mswin = mswin

let installer
if (platform.startsWith('windows-') && engine === 'ruby' && !common.isSelfHostedRunner()) {
installer = require('./windows')
} else if (mswin) {
throw new Error('mswin is only available on GitHub-hosted Windows runners')
} else {
installer = require('./ruby-builder')
}
Expand Down Expand Up @@ -147,13 +150,24 @@ function parseRubyEngineAndVersion(rubyVersion) {
[engine, version] = common.partition(rubyVersion, '-')
}

return [engine, version]
// mswin is CRuby built with MSVC, so it stays the ruby engine and only selects other builds
const mswin = engine === 'mswin' || rubyVersion === 'ruby-mswin'
if (mswin) {
engine = 'ruby'
// mswin and ruby-mswin keep installing the master build until their known users move to mswin-head
if (version === '' || version === 'mswin') {
version = 'head'
}
}

return [engine, version, mswin]
}

function validateRubyEngineAndVersion(platform, engineVersions, engine, parsedVersion) {
if (!engineVersions) {
throw new Error(`Unknown engine ${engine} on ${platform}`)
}
const name = common.inputs.mswin ? 'mswin' : engine

let version = parsedVersion
if (!engineVersions.includes(parsedVersion)) {
Expand All @@ -168,8 +182,8 @@ function validateRubyEngineAndVersion(platform, engineVersions, engine, parsedVe
if (found) {
version = found
} else {
throw new Error(`Unknown version ${parsedVersion} for ${engine} on ${platform}
Available versions for ${engine} on ${platform}: ${engineVersions.join(', ')}
throw new Error(`Unknown version ${parsedVersion} for ${name} on ${platform}
Available versions for ${name} on ${platform}: ${engineVersions.join(', ')}
Make sure you use the latest version of the action with - uses: ruby/setup-ruby@v1`)
}
}
Expand Down
23 changes: 23 additions & 0 deletions windows-mswin-toolchain-versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"3.4.11": {
"x64": "https://github.com/ruby/setup-msys2-gcc/releases/latest/download/vcpkg-x64-windows.7z"
},
"3.4.12": {
"arm64": "https://github.com/ruby/setup-msys2-gcc/releases/latest/download/vcpkg-arm64-windows.7z",
"x64": "https://github.com/ruby/setup-msys2-gcc/releases/latest/download/vcpkg-x64-windows.7z"
},
"4.0.7": {
"x64": "https://github.com/ruby/setup-msys2-gcc/releases/latest/download/vcpkg-x64-windows.7z"
},
"4.0.8": {
"x64": "https://github.com/ruby/setup-msys2-gcc/releases/latest/download/vcpkg-x64-windows.7z"
},
"4.0.9": {
"arm64": "https://github.com/ruby/setup-msys2-gcc/releases/latest/download/vcpkg-arm64-windows.7z",
"x64": "https://github.com/ruby/setup-msys2-gcc/releases/latest/download/vcpkg-x64-windows.7z"
},
"head": {
"arm64": "https://github.com/ruby/setup-msys2-gcc/releases/latest/download/vcpkg-arm64-windows.7z",
"x64": "https://github.com/ruby/setup-msys2-gcc/releases/latest/download/vcpkg-x64-windows.7z"
}
}
23 changes: 23 additions & 0 deletions windows-mswin-versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"3.4.11": {
"x64": "https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/ruby-3.4.11-x64-mswin64_140.zip"
},
"3.4.12": {
"arm64": "https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/ruby-3.4.12-arm64-mswin64_140.zip",
"x64": "https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/ruby-3.4.12-x64-mswin64_140.zip"
},
"4.0.7": {
"x64": "https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/ruby-4.0.7-x64-mswin64_140.zip"
},
"4.0.8": {
"x64": "https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/ruby-4.0.8-x64-mswin64_140.zip"
},
"4.0.9": {
"arm64": "https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/ruby-4.0.9-arm64-mswin64_140.zip",
"x64": "https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/ruby-4.0.9-x64-mswin64_140.zip"
},
"head": {
"arm64": "https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/dev/ruby-head-arm64-mswin64_140.zip",
"x64": "https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/dev/ruby-head-x64-mswin64_140.zip"
}
}
4 changes: 0 additions & 4 deletions windows-toolchain-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,6 @@
"mingw": {
"x64": "https://github.com/ruby/setup-msys2-gcc/releases/download/v20261024.010459/msys2-mingw64.7z"
},
"mswin": {
"arm64": "https://github.com/ruby/setup-msys2-gcc/releases/latest/download/vcpkg-arm64-windows.7z",
"x64": "https://github.com/ruby/setup-msys2-gcc/releases/latest/download/vcpkg-x64-windows.7z"
},
"ucrt": {
"x64": "https://github.com/ruby/setup-msys2-gcc/releases/latest/download/msys2-ucrt64.7z"
}
Expand Down
4 changes: 0 additions & 4 deletions windows-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,6 @@
"mingw": {
"x64": "https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-mingw.7z"
},
"mswin": {
"arm64": "https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/dev/ruby-head-arm64-mswin64_140.zip",
"x64": "https://cache.ruby-lang.org/pub/ruby/binaries/mswin64/dev/ruby-head-x64-mswin64_140.zip"
},
"ucrt": {
"x64": "https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-ucrt.7z"
}
Expand Down
Loading
Loading