Skip to content

Commit

Permalink
👷 Auto-set Loop's version based on Git tags
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Sep 3, 2023
1 parent 0ac1e2e commit ac43e09
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 25 deletions.
40 changes: 40 additions & 0 deletions Loop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,11 @@
buildConfigurationList = A8E59C44297F5E9B0064D4BA /* Build configuration list for PBXNativeTarget "Loop" */;
buildPhases = (
A8291D6C2A450C2700C5CB69 /* Run SwiftLint */,
A8388B932AA5483600975152 /* Set Build Number */,
A8E59C31297F5E9A0064D4BA /* Sources */,
A8E59C32297F5E9A0064D4BA /* Frameworks */,
A8E59C33297F5E9A0064D4BA /* Resources */,
A8388B942AA548BD00975152 /* Reset Build Number */,
);
buildRules = (
);
Expand Down Expand Up @@ -371,6 +373,44 @@
shellPath = /bin/sh;
shellScript = "if [[ \"$(uname -m)\" == arm64 ]]; then\n export PATH=\"/opt/homebrew/bin:$PATH\"\nfi\n\nif which swiftlint > /dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
A8388B932AA5483600975152 /* Set Build Number */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Set Build Number";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/bash;
shellScript = "$SRCROOT/assets/set_build_number.sh\n";
};
A8388B942AA548BD00975152 /* Reset Build Number */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Reset Build Number";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "$SRCROOT/assets/reset_build_number.sh\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down
21 changes: 1 addition & 20 deletions Loop.xcodeproj/xcshareddata/xcschemes/Loop.xcscheme
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "1.7">
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<PreActions>
<ExecutionAction
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Run Script"
scriptText = "$SRCROOT/assets/set_build_number.sh&#10;"
shellToInvoke = "/bin/bash">
<EnvironmentBuildable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "A8E59C34297F5E9A0064D4BA"
BuildableName = "Loop.app"
BlueprintName = "Loop"
ReferencedContainer = "container:Loop.xcodeproj">
</BuildableReference>
</EnvironmentBuildable>
</ActionContent>
</ExecutionAction>
</PreActions>
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
Expand Down
5 changes: 1 addition & 4 deletions Loop/Config.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@
// Created by Kai Azim on 2023-08-09.
//

// Using other tools to set Loop's build number and marketing version didn't work well, so I
// resorted to using this config file to edit their values. There is a script in the resources
// folder that will auto-update the build number based on the number of commits.
VERSION = 1.0.0
VERSION = 0.0.0
BUILD_NUMBER = 0
15 changes: 15 additions & 0 deletions assets/reset_build_number.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

echo "--- Resetting build number! ---"

cd "$SRCROOT"

# Set VERSION
sed -i -e "/VERSION =/ s/= .*/= 0.0.0/" Loop/Config.xcconfig

# Set BUILD_NUMBER
sed -i -e "/BUILD_NUMBER =/ s/= .*/= 0/" Loop/Config.xcconfig

rm Loop/Config.xcconfig-e

echo "--- Done! ---"
8 changes: 7 additions & 1 deletion assets/set_build_number.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ echo "--- Setting build number! ---"

cd "$SRCROOT"

sed -i -e "/BUILD_NUMBER =/ s/= .*/= $(git rev-list --count HEAD)/" Loop/Config.xcconfig
# Set VERSION
latest_tag=$(git describe --tags --abbrev=0)
sed -i -e "/VERSION =/ s/= .*/= $latest_tag/" Loop/Config.xcconfig

# Set BUILD_NUMBER
latest_commit_number=$(git rev-list --count HEAD)
sed -i -e "/BUILD_NUMBER =/ s/= .*/= $latest_commit_number/" Loop/Config.xcconfig

rm Loop/Config.xcconfig-e

Expand Down

0 comments on commit ac43e09

Please sign in to comment.