Skip to content

Commit a84b805

Browse files
committed
Use runRubyScript wrapper on Script Build Phase
To make sure rbenv / rvm are set up if used by the user, and that the script is run via `bundle exec ruby <path>` so that the ruby script would also be able to reference gems (like `xcodeproj`) from the local bundle.
1 parent 4d796df commit a84b805

2 files changed

Lines changed: 63 additions & 18 deletions

File tree

Scripts/BuildPhases/runRubyScript

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash -eu
2+
3+
# Use this to run a Ruby script from a "Script Build Phase" from Xcode.
4+
#
5+
# Since shell scripts ran by Xcode do not source the user shell profile, typical user setups like the configurations of `rbenv` or `rvm` would not be set up properly.
6+
# This script check if either rbenv or rvm is installed on the Mac and runs the setup steps as appririate, before running the ruby script via `bundle exec`
7+
#
8+
# Usage:
9+
# `runRubyScript <script_name.rb> <optional_args>`
10+
#
11+
# Where <script_name.rb` can be either an absolute path, or a path relative to this runRubyScript wrapper script.
12+
#
13+
# Inspiration: https://mgrebenets.github.io/xcode/2019/04/04/xcode-build-phases-and-environment
14+
#
15+
16+
if command -v rbenv; then
17+
echo "Configuring rbenv..."
18+
# Add `rbenv` ships to PATH
19+
export PATH="$HOME/.rbenv/shims:$PATH"
20+
# Check expected ruby version
21+
echo "Checking version..."
22+
rbenv version
23+
elif [[ -f "$HOME/.rvm/bin" ]]; then
24+
echo "Configuring rvm..."
25+
# Add `rvm` to PATH
26+
export PATH="$HOME/.rvm/bin:$PATH"
27+
# Load the expected Ruby version from `.ruby-version` — See https://rvm.io/rvm/basics#post-install-configuration
28+
RUBY_VERSION="$(cat .ruby-version)"
29+
source "$(rvm "${RUBY_VERSION}" do rvm env --path | tail -n1)"
30+
fi
31+
32+
# Run the script with bundle exec
33+
echo "Running the script using 'bundle exec' ..."
34+
cd "$(dirname "${BASH_SOURCE[0]}")"
35+
bundle exec ruby "$@"
36+
cd -

WordPress/WordPress.xcodeproj/project.pbxproj

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16597,6 +16597,7 @@
1659716597
};
1659816598
09DBEA4C281329ED0019724E /* [Lint] Check AppLocalizedString usage */ = {
1659916599
isa = PBXShellScriptBuildPhase;
16600+
alwaysOutOfDate = 1;
1660016601
buildActionMask = 2147483647;
1660116602
files = (
1660216603
);
@@ -16610,12 +16611,13 @@
1661016611
outputPaths = (
1661116612
);
1661216613
runOnlyForDeploymentPostprocessing = 0;
16613-
shellPath = "/bin/zsh -euo pipefail";
16614-
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
16614+
shellPath = "/bin/bash -eu";
16615+
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/runRubyScript\" \"LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
1661516616
showEnvVarsInLog = 0;
1661616617
};
1661716618
09DBEA4D281333060019724E /* [Lint] Check AppLocalizedString usage */ = {
1661816619
isa = PBXShellScriptBuildPhase;
16620+
alwaysOutOfDate = 1;
1661916621
buildActionMask = 2147483647;
1662016622
files = (
1662116623
);
@@ -16629,12 +16631,13 @@
1662916631
outputPaths = (
1663016632
);
1663116633
runOnlyForDeploymentPostprocessing = 0;
16632-
shellPath = "/bin/zsh -euo pipefail";
16633-
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
16634+
shellPath = "/bin/bash -eu";
16635+
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/runRubyScript\" \"LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
1663416636
showEnvVarsInLog = 0;
1663516637
};
1663616638
09DBEA4E2813334B0019724E /* [Lint] Check AppLocalizedString usage */ = {
1663716639
isa = PBXShellScriptBuildPhase;
16640+
alwaysOutOfDate = 1;
1663816641
buildActionMask = 2147483647;
1663916642
files = (
1664016643
);
@@ -16648,12 +16651,13 @@
1664816651
outputPaths = (
1664916652
);
1665016653
runOnlyForDeploymentPostprocessing = 0;
16651-
shellPath = "/bin/zsh -euo pipefail";
16652-
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
16654+
shellPath = "/bin/bash -eu";
16655+
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/runRubyScript\" \"LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
1665316656
showEnvVarsInLog = 0;
1665416657
};
1665516658
09DBEA4F281333530019724E /* [Lint] Check AppLocalizedString usage */ = {
1665616659
isa = PBXShellScriptBuildPhase;
16660+
alwaysOutOfDate = 1;
1665716661
buildActionMask = 2147483647;
1665816662
files = (
1665916663
);
@@ -16667,12 +16671,13 @@
1666716671
outputPaths = (
1666816672
);
1666916673
runOnlyForDeploymentPostprocessing = 0;
16670-
shellPath = "/bin/zsh -euo pipefail";
16671-
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
16674+
shellPath = "/bin/bash -eu";
16675+
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/runRubyScript\" \"LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
1667216676
showEnvVarsInLog = 0;
1667316677
};
1667416678
09DBEA50281333590019724E /* [Lint] Check AppLocalizedString usage */ = {
1667516679
isa = PBXShellScriptBuildPhase;
16680+
alwaysOutOfDate = 1;
1667616681
buildActionMask = 2147483647;
1667716682
files = (
1667816683
);
@@ -16686,12 +16691,13 @@
1668616691
outputPaths = (
1668716692
);
1668816693
runOnlyForDeploymentPostprocessing = 0;
16689-
shellPath = "/bin/zsh -euo pipefail";
16690-
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
16694+
shellPath = "/bin/bash -eu";
16695+
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/runRubyScript\" \"LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
1669116696
showEnvVarsInLog = 0;
1669216697
};
1669316698
09DBEA51281333610019724E /* [Lint] Check AppLocalizedString usage */ = {
1669416699
isa = PBXShellScriptBuildPhase;
16700+
alwaysOutOfDate = 1;
1669516701
buildActionMask = 2147483647;
1669616702
files = (
1669716703
);
@@ -16705,12 +16711,13 @@
1670516711
outputPaths = (
1670616712
);
1670716713
runOnlyForDeploymentPostprocessing = 0;
16708-
shellPath = "/bin/zsh -euo pipefail";
16709-
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
16714+
shellPath = "/bin/bash -eu";
16715+
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/runRubyScript\" \"LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
1671016716
showEnvVarsInLog = 0;
1671116717
};
1671216718
09DBEA52281333700019724E /* [Lint] Check AppLocalizedString usage */ = {
1671316719
isa = PBXShellScriptBuildPhase;
16720+
alwaysOutOfDate = 1;
1671416721
buildActionMask = 2147483647;
1671516722
files = (
1671616723
);
@@ -16724,12 +16731,13 @@
1672416731
outputPaths = (
1672516732
);
1672616733
runOnlyForDeploymentPostprocessing = 0;
16727-
shellPath = "/bin/zsh -euo pipefail";
16728-
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
16734+
shellPath = "/bin/bash -eu";
16735+
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/runRubyScript\" \"LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
1672916736
showEnvVarsInLog = 0;
1673016737
};
1673116738
09DBEA53281333770019724E /* [Lint] Check AppLocalizedString usage */ = {
1673216739
isa = PBXShellScriptBuildPhase;
16740+
alwaysOutOfDate = 1;
1673316741
buildActionMask = 2147483647;
1673416742
files = (
1673516743
);
@@ -16743,12 +16751,13 @@
1674316751
outputPaths = (
1674416752
);
1674516753
runOnlyForDeploymentPostprocessing = 0;
16746-
shellPath = "/bin/zsh -euo pipefail";
16747-
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
16754+
shellPath = "/bin/bash -eu";
16755+
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/runRubyScript\" \"LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
1674816756
showEnvVarsInLog = 0;
1674916757
};
1675016758
09DBEA542813337F0019724E /* [Lint] Check AppLocalizedString usage */ = {
1675116759
isa = PBXShellScriptBuildPhase;
16760+
alwaysOutOfDate = 1;
1675216761
buildActionMask = 2147483647;
1675316762
files = (
1675416763
);
@@ -16762,8 +16771,8 @@
1676216771
outputPaths = (
1676316772
);
1676416773
runOnlyForDeploymentPostprocessing = 0;
16765-
shellPath = "/bin/zsh -euo pipefail";
16766-
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
16774+
shellPath = "/bin/bash -eu";
16775+
shellScript = "\"$SRCROOT/../Scripts/BuildPhases/runRubyScript\" \"LintAppLocalizedStringsUsage.rb\" \"${TARGET_NAME}\"\n";
1676716776
showEnvVarsInLog = 0;
1676816777
};
1676916778
0AA1A8899C01FEF3599F6FCF /* [CP] Check Pods Manifest.lock */ = {

0 commit comments

Comments
 (0)