Created
April 8, 2024 22:40
-
-
Save eliperkins/d84ddaf84858e4f9acea0fa1721c32af to your computer and use it in GitHub Desktop.
Find outdated dependencies in an XcodeGen-based project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
require 'colored2' | |
require 'octokit' | |
require 'yaml' | |
if ENV['GITHUB_TOKEN'].nil? | |
puts '❗️ GITHUB_TOKEN environment variable is not set!'.red | |
puts 'Supply a token from gh CLI by running `GITHUB_TOKEN=$(gh auth token) script/check-outdated-deps.rb`' | |
exit 1 | |
end | |
client = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN']) | |
def puts_replace_line(text) | |
print "\e[1A\e[K" # Move up and clear line | |
puts text | |
end | |
def puts_bordered(text) | |
puts '│'.dark + text | |
end | |
# Fetches the latest version of a given repository from either releases or tags | |
def fetch_latest_version(client, repo_name) | |
release = client.latest_release(repo_name) | |
release[:tag_name].gsub(/^v/, '') | |
rescue Octokit::NotFound | |
tags = client.tags(repo_name) | |
tags.first[:name].gsub(/^v/, '') | |
end | |
project = YAML.safe_load_file('project.yml') | |
has_outdated_package = false | |
project['packages'].each do |name, package| | |
puts "♺ Checking #{name} for latest version...".dark | |
if package['url'].nil? | |
puts_replace_line "↬ #{name} has no URL, skipping...".dark | |
next | |
end | |
if package['exactVersion'].nil? | |
puts_replace_line "↬ #{name} has no exactVersion, skipping...".dark | |
next | |
end | |
repo_name = package['url'].gsub(%r{^https://github.com/}, '').gsub(/\.git$/, '') | |
begin | |
latest_version_string = fetch_latest_version(client, repo_name) | |
rescue StandardError | |
puts "⚠ API error occurred while checking #{name} for outdated packages!".red | |
puts e | |
exit 1 | |
end | |
current_version_string = package['exactVersion'] | |
latest_version = Gem::Version.new(latest_version_string) | |
current_version = Gem::Version.new(current_version_string) | |
if latest_version > current_version | |
has_outdated_package = true | |
compare_link = "https://github.com/#{repo_name}/compare/#{current_version_string}...#{latest_version_string}".blue.underlined | |
puts_replace_line "⚠ #{name} is outdated!".red | |
puts_bordered " Current: #{current_version.to_s.bold.red}" | |
puts_bordered " Latest: #{latest_version.to_s.bold.green}" | |
puts_bordered " Compare: #{compare_link}" | |
else | |
puts_replace_line '✓'.dark.green + " #{name} is up to date!".dark | |
end | |
end | |
exit 1 if has_outdated_package |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment