From 9b38cc043747c5578aad970566069fc365b020ad Mon Sep 17 00:00:00 2001 From: Danny Moesch Date: Fri, 28 Aug 2020 18:29:15 +0200 Subject: [PATCH] Skip SwiftLint and SwiftFormat runs on CI build Unfortunately, there seems to be no simpler way to tell a script in Xcode that it runs on CI. --- .gitignore | 5 +++++ .travis.yml | 3 +-- pass.xcodeproj/project.pbxproj | 14 ++++++++------ scripts/swiftformat.sh | 24 ++++++++++++++++++++++++ scripts/swiftlint.sh | 24 ++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 8 deletions(-) create mode 100755 scripts/swiftformat.sh create mode 100755 scripts/swiftlint.sh diff --git a/.gitignore b/.gitignore index 601351b..ce34db5 100644 --- a/.gitignore +++ b/.gitignore @@ -69,3 +69,8 @@ fastlane/Preview.html fastlane/screenshots fastlane/test_output .DS_Store + +# Environment +# +# The Continuous Integration environment will create this file. It avoids specific "Run Script" phases while building. +.ci-env diff --git a/.travis.yml b/.travis.yml index 694e750..8141e56 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,11 +6,10 @@ addons: - go - gnupg2 - pass - - swiftformat - - swiftlint update: true before_install: - echo -e "machine github.com\n login $GITHUB_ACCESS_TOKEN" >> ~/.netrc + - touch .ci-env install: - gem install bundler - bundle install diff --git a/pass.xcodeproj/project.pbxproj b/pass.xcodeproj/project.pbxproj index a00f334..d1e79d3 100644 --- a/pass.xcodeproj/project.pbxproj +++ b/pass.xcodeproj/project.pbxproj @@ -1051,8 +1051,8 @@ A26700191EEC450100176B8A /* Embed App Extensions */, A26075921EEC6F34005DB03E /* Embed Frameworks */, 9AF6A4F532EB900EE22C80EA /* [CP] Embed Pods Frameworks */, - 3005F34F24A9143C000519B5 /* ShellScript */, - 308800C124EB0D3600E87ED3 /* ShellScript */, + 3005F34F24A9143C000519B5 /* SwiftFormat */, + 308800C124EB0D3600E87ED3 /* SwiftLint */, ); buildRules = ( ); @@ -1279,7 +1279,7 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - 3005F34F24A9143C000519B5 /* ShellScript */ = { + 3005F34F24A9143C000519B5 /* SwiftFormat */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -1288,15 +1288,16 @@ ); inputPaths = ( ); + name = SwiftFormat; outputFileListPaths = ( ); outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "SWIFTFORMAT_VERSION=\"0.45.*\"\n\nif which swiftformat > /dev/null; then\n if [[ \"$(swiftformat --version)\" == $SWIFTFORMAT_VERSION ]]; then\n swiftformat .\n else\n echo \"Failure: SwiftFormat $SWIFTFORMAT_VERSION is required. Install it or update the build script to use a newer version.\"\n exit 1\n fi\nelse\n echo \"Failure: SwiftFormat not installed. Get it via 'brew install swiftformat'.\"\n exit 2\nfi\n"; + shellScript = ". \"${SRCROOT}/scripts/swiftformat.sh\"\n"; }; - 308800C124EB0D3600E87ED3 /* ShellScript */ = { + 308800C124EB0D3600E87ED3 /* SwiftLint */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -1305,13 +1306,14 @@ ); inputPaths = ( ); + name = SwiftLint; outputFileListPaths = ( ); outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "SWIFTLINT_VERSION=\"0.40.*\"\n\nif which swiftlint > /dev/null; then\n if [[ \"$(swiftlint version)\" == $SWIFTLINT_VERSION ]]; then\n swiftlint\n else\n echo \"Failure: SwiftLint $SWIFTLINT_VERSION is required. Install it or update the build script to use a newer version.\"\n exit 1\n fi\nelse\n echo \"Failure: SwiftLint not installed. Get it via 'brew install swiftlint'.\"\n exit 2\nfi\n"; + shellScript = ". \"${SRCROOT}/scripts/swiftlint.sh\"\n"; }; 3EFC287772C1D2B2762FAC45 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; diff --git a/scripts/swiftformat.sh b/scripts/swiftformat.sh new file mode 100755 index 0000000..2703ee4 --- /dev/null +++ b/scripts/swiftformat.sh @@ -0,0 +1,24 @@ +SWIFTFORMAT_VERSION="0.45.*" + +if [[ -f "${SRCROOT}/.ci-env" ]]; then + echo "Running in a Continuous Integration environment. Formatting is skipped." + return +fi + +if [[ "${CONFIGURATION}" != "Debug" ]]; then + echo "Running during a release build. Formatting is skipped." + return +fi + +if which swiftformat > /dev/null; then + if [[ "$(swiftformat --version)" == $SWIFTFORMAT_VERSION ]]; then + swiftformat . + else + echo "Failure: SwiftFormat $SWIFTFORMAT_VERSION is required. Install it or update the build script to use a newer version." + exit 1 + fi +else + echo "Failure: SwiftFormat not installed. Get it via 'brew install swiftformat'." + exit 2 +fi + diff --git a/scripts/swiftlint.sh b/scripts/swiftlint.sh new file mode 100755 index 0000000..fc0c82d --- /dev/null +++ b/scripts/swiftlint.sh @@ -0,0 +1,24 @@ +SWIFTLINT_VERSION="0.40.*" + +if [[ -f "${SRCROOT}/.ci-env" ]]; then + echo "Running in a Continuous Integration environment. Linting is skipped." + return +fi + +if [[ "${CONFIGURATION}" != "Debug" ]]; then + echo "Running during a release build. Linting is skipped." + return +fi + +if which swiftlint > /dev/null; then + if [[ "$(swiftlint version)" == $SWIFTLINT_VERSION ]]; then + swiftlint --strict + else + echo "Failure: SwiftLint $SWIFTLINT_VERSION is required. Install it or update the build script to use a newer version." + exit 1 + fi +else + echo "Failure: SwiftLint not installed. Get it via 'brew install swiftlint'." + exit 2 +fi +