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
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,17 @@ jobs:
- name: C:/msys64/mingw64/bin/gcc.exe not installed
run: ruby -e "abort if File.exist?('C:/msys64/mingw64/bin/gcc.exe')"

validate-windows-versions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: ./
with:
ruby-version: ruby
- run: ruby generate-windows-versions.rb
- name: Check generated files are up to date
run: git diff --exit-code

lint:
runs-on: ubuntu-22.04
steps:
Expand Down
27 changes: 27 additions & 0 deletions generate-windows-versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@
require 'yaml'
require 'json'

# General rules:
# - All the static parts of the expected URL are checked literally.
# - Don't forget to escape dot (`.`) and other special characters when used literally.
# - Each path component must begin with [\w], or a more restrictive character set.
# - Percent (`%`) shall not be allowed to avoid any percent encoding.
WINDOWS_VERSIONS_URLS_REGEXPS = [
%r{^https://github\.com/oneclick/rubyinstaller2?/releases/download/\w[\w.-]*/\w[\w.-]*$},
%r{^https://github\.com/MSP-Greg/ruby-loco/releases/download/\w[\w.-]*/\w[\w.-]*$}
].freeze

WINDOWS_TOOLCHAIN_VERSIONS_URLS_REGEXPS = [
%r{^https://github\.com/oneclick/rubyinstaller/releases/download/devkit-4\.7\.2/DevKit-mingw64-64-4\.7\.2-20130224-1432-sfx\.exe$},
%r{^https://github\.com/ruby/setup-msys2-gcc/releases/download/\w[\w.-]*/\w[\w@.-]*$},
%r{^https://github\.com/ruby/setup-msys2-gcc/releases/latest/download/\w[\w@.-]*$}
].freeze

# Validate all the URLs in the versions json
def validate(versions, allowed_urls_regexps)
versions.values.flat_map(&:values).each do |url|
if allowed_urls_regexps.none? { |regexp| regexp =~ url }
raise SecurityError, "Unexpected URL: #{url}"
end
end
end

min_requirements = ['~> 2.0.0', '~> 2.1.9', '>= 2.2.6'].map { |req| Gem::Requirement.new(req) }

url = 'https://raw.githubusercontent.com/oneclick/rubyinstaller.org-website/master/_data/downloads.yaml'
Expand Down Expand Up @@ -48,6 +73,7 @@
'x64' => 'https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-ucrt.7z'
}

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

base_url = 'https://github.com/ruby/setup-msys2-gcc/releases/latest/download/windows-toolchain.json'
Expand Down Expand Up @@ -90,4 +116,5 @@
end
end

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