From 4c71dccc2b248ec8a66d454b3774f65353922f67 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 21 Jun 2026 22:36:46 +0900 Subject: [PATCH 1/4] Added the `.check.rb --gitrepo` switch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The purpose is to enable verification of the validity of Git repositories and branches. It actually accesses the URL specified by the "repository" in the ".gem" file and retrieves the branch and tag names. If the "branch" in the ".gem" file is not included in the retrieved reference name, it reports an error. Additionally, if the "branch" in the ".gem" file is actually a tag name, it also reports an error. Furthermore, the `.check.rb --interval` switch has been added. The `--gitrepo` switch is equivalent to web scraping from the perspective of the target server. Therefore, unlimited consecutive access may be restricted by the target server’s rate limits. This switch allows specifying the interval between consecutive accesses as a real number in seconds. The default value is 1.2 seconds. --- .check.rb | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/.check.rb b/.check.rb index 3c6ba05..4e24fbb 100755 --- a/.check.rb +++ b/.check.rb @@ -1,5 +1,6 @@ #!/usr/bin/env ruby +require "optparse" require "yaml" # please add or remove files on the top dir for management if necessary. @@ -25,6 +26,12 @@ def run_and_split_nul(cmd) IO.popen(cmd, "rb") { |pipe| pipe.read.split("\0") } end +class Array # rubocop:disable Style/Documentation + def extract_git_branches + grep(%r{^refs/heads/}).map { |e| e.delete_prefix("refs/heads/") } + end +end + errinfo = Object.new class << errinfo def push(mesg) @@ -49,8 +56,63 @@ def output end end +def git_get_remote_refs(repository) + env = { "GIT_TERMINAL_PROMPT" => "0" } + cmd = %W[git ls-remote -btq --refs #{repository}] + + IO.popen(env, cmd, "r", err: File::NULL) do |r| + refs = r.read.split(/[\n\t]/).select.with_index { |_, i| i.odd? } + return refs unless refs.empty? + end + + nil +end + +def check_git_repository(gemname, tree, errinfo) # rubocop:disable Metrics/MethodLength + repo = tree["repository"].to_s + branch = tree["branch"] || "master" + refs = git_get_remote_refs(repo) unless repo.empty? + + if refs.nil? + errinfo.push <<~INFO + #{gemname}: unable to access the repository or locate a valid branch name. + INFO + elsif refs.include?("refs/heads/#{branch}") + # OK + elsif refs.include?("refs/tags/#{branch}") + errinfo.push <<~INFO + #{gemname}: instead of branches, the tag "#{branch}" is used. + INFO + else + errinfo.push <<~INFO + #{gemname}: branch "#{branch}" is missing. + > candidates: #{refs.extract_git_branches.join(" ")} + INFO + end +end + Dir.chdir(__dir__) +banner = <<~BANNER + Usage: #{$PROGRAM_NAME} [options] +BANNER + +gitrepo = false +interval = 1.2 +OptionParser.new(banner, 24, "") do |o| + o.separator "" + + o.on "--gitrepo", "Verify a Git repository and a specified branch" do + gitrepo = true + end + + o.on "--interval seconds", "Specify the access interval with `--gitrepo` (default: #{interval})", Float do |n| + interval = n + end + + o.order! +end + entries = run_and_split_nul(%w[git ls-files -z :^*/*]) puts "checking project management files" @@ -61,7 +123,7 @@ def output MESG end -(entries - PROJECT_FILES).each do |f| +(entries - PROJECT_FILES).each_with_index do |f, i| puts "checking #{f}" unless f.match?(/\.gem$/) @@ -82,6 +144,11 @@ def output tree["dependencies"].to_a.each do |x| errinfo.push "#{f}: invalid dependencies" unless x.is_a?(String) end + + if gitrepo + sleep interval if i.positive? + check_git_repository(f, tree, errinfo) + end rescue StandardError => e errinfo.push e end From 02e40f45c9a847b9b674f9b069fe6c939c8a00f0 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 21 Jun 2026 22:36:46 +0900 Subject: [PATCH 2/4] Added the `.check.rb --gitdiff` switch The goal is to enable efficient verification of specific changes rather than verifying all files. Using `.check.rb --gitdiff base-ref head-ref` allows verifying only the files that have changed between Git commits. --- .check.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/.check.rb b/.check.rb index 4e24fbb..a6b7e85 100755 --- a/.check.rb +++ b/.check.rb @@ -95,13 +95,19 @@ def check_git_repository(gemname, tree, errinfo) # rubocop:disable Metrics/Metho banner = <<~BANNER Usage: #{$PROGRAM_NAME} [options] + #{$PROGRAM_NAME} [options] --gitdiff base-ref [head-ref] BANNER +gitdiff = false gitrepo = false interval = 1.2 OptionParser.new(banner, 24, "") do |o| o.separator "" + o.on "--gitdiff", "Verify only the files with changes between two Git refs" do + gitdiff = true + end + o.on "--gitrepo", "Verify a Git repository and a specified branch" do gitrepo = true end @@ -115,6 +121,22 @@ def check_git_repository(gemname, tree, errinfo) # rubocop:disable Metrics/Metho entries = run_and_split_nul(%w[git ls-files -z :^*/*]) +if gitdiff + case ARGV.size + when 1, 2 + # do nothing + else + warn banner + exit 1 + end + cmd = %w[git diff -z --name-only --diff-filter=ACMR] + cmd.concat ARGV + cmd.concat %w[-- :^*/*] + gemfiles = run_and_split_nul(cmd) +else + gemfiles = entries +end + puts "checking project management files" unless (PROJECT_FILES - entries).empty? errinfo.push <<~MESG @@ -123,7 +145,7 @@ def check_git_repository(gemname, tree, errinfo) # rubocop:disable Metrics/Metho MESG end -(entries - PROJECT_FILES).each_with_index do |f, i| +(gemfiles - PROJECT_FILES).each_with_index do |f, i| puts "checking #{f}" unless f.match?(/\.gem$/) From 5ffeb59c345d8aa091f13a0c806f8d965ab10786 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 21 Jun 2026 22:36:46 +0900 Subject: [PATCH 3/4] Updated the GitHub Actions verification flow The `.check.rb --gitrepo` switch now verifies the validity of the Git repository and branch specified by the ".gem" file. The actual targets for verification are the ".gem" files detected by the `.check.rb --gitdiff` switch. Although the logic is triggered by "push" events as well, the current workflow configuration is limited to pull requests only. --- .github/workflows/check-gems.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-gems.yml b/.github/workflows/check-gems.yml index 29d6019..690efed 100644 --- a/.github/workflows/check-gems.yml +++ b/.github/workflows/check-gems.yml @@ -9,6 +9,10 @@ jobs: check-gems: name: Check gem files runs-on: ubuntu-latest + env: + BASE_REF: ${{ case(github.event_name == 'pull_request', github.event.pull_request.base.sha, + github.event.before == '0000000000000000000000000000000000000000', 'master', + github.event.before) }} steps: - name: Checkout Code uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 @@ -19,4 +23,12 @@ jobs: ruby-version: '3.4' # Not needed with a .ruby-version file bundler: 'default' bundler-cache: true # runs 'bundle install' and caches installed gems automatically - - run: bundle exec .check.rb + - name: Fetch base revision + run: | + git fetch --depth 1 origin "${BASE_REF}" + if [ "${BASE_REF}" = "master" ] + then + git branch master origin/master + fi + - name: Validation + run: bundle exec .check.rb --gitrepo --gitdiff "${BASE_REF}" From 8b367836b4e6583cfc9fee31649135c3aaf566ef Mon Sep 17 00:00:00 2001 From: dearblue Date: Sat, 27 Jun 2026 16:21:02 +0900 Subject: [PATCH 4/4] =?UTF-8?q?editorconfig-check=20=E3=81=AE=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=83=87=E3=83=B3=E3=83=88=E3=82=B5=E3=82=A4=E3=82=BA?= =?UTF-8?q?=E3=82=92=E7=84=A1=E5=8A=B9=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit editorconfig-check は構文を理解せず、単純なインデントサイズしか確認しないためです。 ref. https://github.com/super-linter/super-linter/blob/c358755/README.md#configure-super-linter ref. https://github.com/editorconfig-checker/editorconfig-checker/blob/dbb0dbb/README.md#configuration --- .github/linters/editorconfig-checker.json | 5 +++++ .github/workflows/super-linter.yml | 1 + 2 files changed, 6 insertions(+) create mode 100644 .github/linters/editorconfig-checker.json diff --git a/.github/linters/editorconfig-checker.json b/.github/linters/editorconfig-checker.json new file mode 100644 index 0000000..1adc63b --- /dev/null +++ b/.github/linters/editorconfig-checker.json @@ -0,0 +1,5 @@ +{ + "Disable": { + "IndentSize": false + } +} diff --git a/.github/workflows/super-linter.yml b/.github/workflows/super-linter.yml index 293579a..28537ff 100644 --- a/.github/workflows/super-linter.yml +++ b/.github/workflows/super-linter.yml @@ -21,6 +21,7 @@ jobs: uses: super-linter/super-linter/slim@9e863354e3ff62e0727d37183162c4a88873df41 # v8.6.0 env: VALIDATE_EDITORCONFIG: true + EDITORCONFIG_FILE_NAME: ${{ github.workspace }}/.github/linters/editorconfig-checker.json VALIDATE_GITHUB_ACTIONS: true VALIDATE_GITLEAKS: true DEFAULT_BRANCH: master