diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0e78642ba..bfd9474a6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,10 @@ name: Test site build permissions: contents: read -on: [push, pull_request] +on: + push: + branches: [gh-pages] + pull_request: jobs: build: diff --git a/.github/workflows/ensure-alphabetize.yml b/.github/workflows/ensure-alphabetize.yml index 1dc0f6b1f..39fd29914 100644 --- a/.github/workflows/ensure-alphabetize.yml +++ b/.github/workflows/ensure-alphabetize.yml @@ -4,6 +4,7 @@ permissions: on: push: + branches: [gh-pages] paths: - "Gemfile" - "script/alphabetize" diff --git a/.github/workflows/ensure-orgs.yml b/.github/workflows/ensure-orgs.yml index 8b62cf03d..895506a0a 100644 --- a/.github/workflows/ensure-orgs.yml +++ b/.github/workflows/ensure-orgs.yml @@ -4,15 +4,18 @@ permissions: on: push: + branches: [gh-pages] paths: - "Gemfile" - "script/ensure-orgs" + - "test/ensure_orgs_test.rb" - ".github/workflows/ensure-orgs.yml" - "_data/**" pull_request: paths: - "Gemfile" - "script/ensure-orgs" + - "test/ensure_orgs_test.rb" - ".github/workflows/ensure-orgs.yml" - "_data/**" @@ -27,5 +30,7 @@ jobs: uses: ruby/setup-ruby@de492cf36cbab201753d720ce4f4e336cd688c94 # v1.336.0 with: bundler-cache: true + - name: Test organization checks + run: bundle exec ruby test/ensure_orgs_test.rb - name: Ensure data entries are GitHub Orgs run: bundle exec script/ensure-orgs diff --git a/.github/workflows/ensure-unique.yml b/.github/workflows/ensure-unique.yml index 2010e5506..4254106c0 100644 --- a/.github/workflows/ensure-unique.yml +++ b/.github/workflows/ensure-unique.yml @@ -4,6 +4,7 @@ permissions: on: push: + branches: [gh-pages] paths: - "Gemfile" - "script/ensure-unique" diff --git a/.github/workflows/rubucop.yml b/.github/workflows/rubucop.yml index ec02c21ad..bc59e3977 100644 --- a/.github/workflows/rubucop.yml +++ b/.github/workflows/rubucop.yml @@ -4,6 +4,7 @@ permissions: on: push: + branches: [gh-pages] paths: - "Gemfile" - ".rubocop.yml" diff --git a/_data/research.yml b/_data/research.yml index 24b71a9e1..da50b7a3c 100644 --- a/_data/research.yml +++ b/_data/research.yml @@ -299,7 +299,6 @@ U.S. Research Labs: - EMSL-MSC - epicsdeb - esgf - - EVS-ATMOS - exmatex - flux-framework - gatech @@ -322,7 +321,6 @@ U.S. Research Labs: - LANL-Bioinformatics - lbl-anp - lbl-cal - - lblpbd - libmesh - llnl - losalamos @@ -336,7 +334,6 @@ U.S. Research Labs: - mit-ll - mitre - NASA-Tensegrity-Robotics-Toolkit - - nasajpl - ncats - ncbi - ncip diff --git a/script/ensure-orgs b/script/ensure-orgs index 2e3b41eb8..ed1c5ba21 100755 --- a/script/ensure-orgs +++ b/script/ensure-orgs @@ -23,26 +23,29 @@ end Typhoeus::Config.cache = Cache.new -# Ideally this would be an API call, but given the volume of calls, -# We'd constantly hit any rate limit as each needs to be its own query -def org?(user) - response = Typhoeus.head "https://github.com/orgs/#{user}/people", accept_encoding: 'gzip' - response.success? || response.response_code == 429 -end - puts 'Checking that all orgs listed are in fact, an org...' data_folder_path = File.expand_path '../_data', File.dirname(__FILE__) files = Dir["#{data_folder_path}/*.yml"] valid = true +response_counts = Hash.new(0) files.each do |file| data = YAML.load_file file data.each do |group, orgs| - not_orgs = Parallel.map(orgs) { |org| org unless org?(org) }.compact + responses = Parallel.map(orgs) do |org| + [org, Typhoeus.head("https://github.com/orgs/#{org}/people", accept_encoding: 'gzip')] + end + not_orgs = [] + responses.each do |org, response| + response_counts[response.response_code] += 1 + next if response.success? + + not_orgs << org if response.response_code == 404 + end next if not_orgs.empty? - puts "\nIn #{File.basename(file)}, in the #{group} group, the following entries are users, not orgs:\n\n" + puts "\nIn #{File.basename(file)}, in the #{group} group, the following entries are not organizations or no longer exist (HTTP 404):\n\n" puts not_orgs valid = false data[group] = data[group] - not_orgs @@ -55,8 +58,15 @@ files.each do |file| File.write(file, output) end +puts "Responses (#{response_counts.values.sum} total):" +response_counts.sort.each do |code, count| + puts "#{code.zero? ? 'No HTTP response' : "HTTP #{code}"}: #{count}" +end +skipped = response_counts.sum { |code, count| code.between?(200, 299) || code == 404 ? 0 : count } +puts "Skipped #{skipped} organization checks due to unavailable responses; entries retained." if skipped.positive? + if valid - puts 'All orgs check out.' + puts(skipped.zero? ? 'All orgs check out.' : 'No non-organizations found among completed checks.') exit 0 else exit 1 diff --git a/test/ensure_orgs_test.rb b/test/ensure_orgs_test.rb new file mode 100644 index 000000000..32bbd8a87 --- /dev/null +++ b/test/ensure_orgs_test.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +require 'minitest/autorun' +require 'fileutils' +require 'json' +require 'open3' +require 'tmpdir' +require 'yaml' + +class EnsureOrgsTest < Minitest::Test + def run_check(codes) + Dir.mktmpdir do |dir| + FileUtils.mkdir_p("#{dir}/script") + FileUtils.mkdir_p("#{dir}/_data") + FileUtils.cp(File.expand_path('../script/ensure-orgs', __dir__), "#{dir}/script/ensure-orgs") + data_path = "#{dir}/_data/orgs.yml" + File.write(data_path, "# Organizations\n\nTest:\n#{codes.keys.map { |org| " - #{org}\n" }.join}") + File.write("#{dir}/responses.rb", <<~RUBY) + require 'typhoeus' + require 'json' + Typhoeus::Config.block_connection = true + JSON.parse(ENV.fetch('ORG_RESPONSES')).each do |org, code| + Typhoeus.stub("https://github.com/orgs/\#{org}/people").and_return( + Typhoeus::Response.new(code: code, return_code: code.zero? ? :operation_timedout : :ok) + ) + end + RUBY + output, status = Open3.capture2e( + { 'ORG_RESPONSES' => codes.to_json, 'GITHUB_ACTIONS' => 'true' }, + Gem.ruby, '-r', "#{dir}/responses.rb", "#{dir}/script/ensure-orgs" + ) + [output, status, YAML.safe_load_file(data_path).fetch('Test')] + end + end + + def test_unavailable_responses_are_inconclusive_and_retained + codes = { 'org' => 200, 'forbidden' => 403, 'limited' => 429, 'server-error' => 500, + 'unavailable' => 503, 'timeout' => 0, 'redirect' => 302 } + output, status, entries = run_check(codes) + + assert status.success?, output + assert_equal codes.keys, entries + assert_includes output, 'Skipped 6 organization checks' + assert_includes output, 'Responses (7 total):' + assert_includes output, 'HTTP 403: 1' + assert_includes output, 'HTTP 429: 1' + assert_includes output, 'No HTTP response: 1' + codes.keys.drop(1).each { |org| refute_includes output, "#{org}:" } + refute_includes output, 'All orgs check out.' + end + + def test_not_found_still_fails_without_removing_inconclusive_entries + output, status, entries = run_check('org' => 200, 'user' => 404, 'limited' => 429) + + assert_equal 1, status.exitstatus, output + assert_equal %w[org limited], entries + assert_includes output, 'not organizations or no longer exist' + assert_includes output, "(HTTP 404):\n\nuser\n" + assert_includes output, 'HTTP 404: 1' + assert_includes output, 'Skipped 1 organization checks' + end + + def test_successful_checks_report_success + output, status, entries = run_check('org' => 200) + + assert status.success?, output + assert_equal ['org'], entries + assert_includes output, 'All orgs check out.' + refute_includes output, 'Skipped' + end +end