Skip to content
Merged
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
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ name: Test site build
permissions:
contents: read

on: [push, pull_request]
on:
push:
branches: [gh-pages]
pull_request:

jobs:
build:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ensure-alphabetize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ permissions:

on:
push:
branches: [gh-pages]
paths:
- "Gemfile"
- "script/alphabetize"
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ensure-orgs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/**"

Expand All @@ -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
Comment thread
mlinksva marked this conversation as resolved.
Resolved
- name: Ensure data entries are GitHub Orgs
run: bundle exec script/ensure-orgs
1 change: 1 addition & 0 deletions .github/workflows/ensure-unique.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ permissions:

on:
push:
branches: [gh-pages]
paths:
- "Gemfile"
- "script/ensure-unique"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/rubucop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ permissions:

on:
push:
branches: [gh-pages]
paths:
- "Gemfile"
- ".rubocop.yml"
Expand Down
3 changes: 0 additions & 3 deletions _data/research.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ U.S. Research Labs:
- EMSL-MSC
- epicsdeb
- esgf
- EVS-ATMOS
- exmatex
- flux-framework
- gatech
Expand All @@ -322,7 +321,6 @@ U.S. Research Labs:
- LANL-Bioinformatics
- lbl-anp
- lbl-cal
- lblpbd
- libmesh
- llnl
- losalamos
Expand All @@ -336,7 +334,6 @@ U.S. Research Labs:
- mit-ll
- mitre
- NASA-Tensegrity-Robotics-Toolkit
- nasajpl
- ncats
- ncbi
- ncip
Expand Down
30 changes: 20 additions & 10 deletions script/ensure-orgs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
71 changes: 71 additions & 0 deletions test/ensure_orgs_test.rb
Original file line number Diff line number Diff line change
@@ -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
Loading