Skip to content

Instantly share code, notes, and snippets.

@AliSoftware
Last active February 14, 2019 14:27
Show Gist options
  • Save AliSoftware/33d17631c8bc6a0d24d9811811eb33fb to your computer and use it in GitHub Desktop.
Save AliSoftware/33d17631c8bc6a0d24d9811811eb33fb to your computer and use it in GitHub Desktop.
Dangerfile Rules
#######################################
# Check that some Build Settings (those defined by VERSION_SETTINGS below) are set on the right level (target/project)
#######################################
VERSION_SETTINGS = %w(GLOBAL_APP_VERSION GLOBAL_APP_BUILD_VERSION)
require 'xcodeproj'
project = Xcodeproj::Project.open('YOUR_PROJECT_NAME.xcodeproj')
target = project.targets.find("YOUR_TARGET_NAME").first
target.build_configurations.each do |bc|
## Don't allow some build settings at target level (but only at project level)
not_allowed_at_target_level = bc.build_settings.keys & VERSION_SETTINGS
not_allowed_at_target_level.each do |bs|
fail("The Build Setting \`#{bs}\` have been set on the **target**. It should only have a value set at the **project** level.")
end
end
#######################################
# Check that no Build Settings are set at all (neither at targets nor project level)
# Aimed to be used if all settings were set using xcconfig files and none in the pbxproj…
#
# !! NOT TESTED IN PRACTICE !! (only written live in GitHub to give more ideas, might contain typos)
#######################################
require 'xcodeproj'
project = Xcodeproj::Project.open('YOUR_PROJECT_NAME.xcodeproj')
# Check that no build settings is set (at all) at the project level
project.build_configurations.each do |config|
keys = config.build_settings.keys
warn("Those build settings are set at the progject level: #{keys}") unless keys.empty?
end
# Check that no build settings is set (at all) on each target
project.target.each do |target|
target.build_configurations.each do |config|
keys = config.build_settings.keys
warn("This build settings are set on target '#{target.name}': #{keys}") unless keys.empty?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment