build(mac): calculate CFBundleVersion from commit date and time

This commit is contained in:
Christopher Willis-Ford 2023-05-25 13:44:58 -07:00
parent 6a0a019656
commit 61d3e2914d
4 changed files with 26 additions and 25 deletions
README.md
Scratch Link Safari Helper/Configuration Files
SharedProps
scratch-link-mac

View file

@ -49,8 +49,8 @@ a change is merged to either of those branches, `semantic-release` will calculat
Apple requires that `CFBundleShortVersionString` is unique for published releases. The App Store will also reject an
upload unless the `CFBundleVersion` tuple is greater than that of previously uploaded builds. To make this easy, we
set both to the version calculated by `semantic-release`. The uniqueness requirement means we can't "try again" on
the same version number, but that just enforces the semantic versioning so it's arguably a good thing.
set `CFBundleShortVersionString` to the version calculated by `semantic-release`, and `CFBundleVersion` is calculated
from the date and time of the build commit.
Extended version information is available within the application. This extended information is similar to `git
describe`.

View file

@ -9,7 +9,7 @@
// https://help.apple.com/xcode/#/dev745c5c974
// MARKETING_VERSION becomes CFBundleShortVersionString
MARKETING_VERSION = 2.0;
MARKETING_VERSION = 2.0.0;
// CURRENT_PROJECT_VERSION becomes CFBundleVersion
CURRENT_PROJECT_VERSION = 2.0;
CURRENT_PROJECT_VERSION = 1.0.0;

View file

@ -5,24 +5,24 @@ This file sets up version properties in our own Scratch way.
<Project>
<Target Name="ScratchVersion" DependsOnTargets="GitVersion">
<!--
<Message Text="GitInfo: GitRepositoryUrl = $(GitRepositoryUrl)" />
<Message Text="GitInfo: GitBranch = $(GitBranch)" />
<Message Text="GitInfo: GitCommit = $(GitCommit)" />
<Message Text="GitInfo: GitCommitDate = $(GitCommitDate)" />
<Message Text="GitInfo: GitCommits = $(GitCommits)" />
<Message Text="GitInfo: GitTag = $(GitTag)" />
<Message Text="GitInfo: GitBaseTag = $(GitBaseTag)" />
<Message Text="GitInfo: GitBaseVersionMajor = $(GitBaseVersionMajor)" />
<Message Text="GitInfo: GitBaseVersionMinor = $(GitBaseVersionMinor)" />
<Message Text="GitInfo: GitBaseVersionPatch = $(GitBaseVersionPatch)" />
<Message Text="GitInfo: GitSemVerMajor = $(GitSemVerMajor)" />
<Message Text="GitInfo: GitSemVerMinor = $(GitSemVerMinor)" />
<Message Text="GitInfo: GitSemVerPatch = $(GitSemVerPatch)" />
<Message Text="GitInfo: GitSemVerLabel = $(GitSemVerLabel)" />
<Message Text="GitInfo: GitSemVerDashLabel = $(GitSemVerDashLabel)" />
<Message Text="GitInfo: GitSemVerSource = $(GitSemVerSource)" />
<Message Text="GitInfo: GitIsDirty = $(GitIsDirty)" />
-->
<Message Text="GitInfo: GitRepositoryUrl = $(GitRepositoryUrl)" />
<Message Text="GitInfo: GitBranch = $(GitBranch)" />
<Message Text="GitInfo: GitCommit = $(GitCommit)" />
<Message Text="GitInfo: GitCommitDate = $(GitCommitDate)" />
<Message Text="GitInfo: GitCommits = $(GitCommits)" />
<Message Text="GitInfo: GitTag = $(GitTag)" />
<Message Text="GitInfo: GitBaseTag = $(GitBaseTag)" />
<Message Text="GitInfo: GitBaseVersionMajor = $(GitBaseVersionMajor)" />
<Message Text="GitInfo: GitBaseVersionMinor = $(GitBaseVersionMinor)" />
<Message Text="GitInfo: GitBaseVersionPatch = $(GitBaseVersionPatch)" />
<Message Text="GitInfo: GitSemVerMajor = $(GitSemVerMajor)" />
<Message Text="GitInfo: GitSemVerMinor = $(GitSemVerMinor)" />
<Message Text="GitInfo: GitSemVerPatch = $(GitSemVerPatch)" />
<Message Text="GitInfo: GitSemVerLabel = $(GitSemVerLabel)" />
<Message Text="GitInfo: GitSemVerDashLabel = $(GitSemVerDashLabel)" />
<Message Text="GitInfo: GitSemVerSource = $(GitSemVerSource)" />
<Message Text="GitInfo: GitIsDirty = $(GitIsDirty)" />
-->
<PropertyGroup>
<ScratchVersionTriplet>$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)</ScratchVersionTriplet>
<ScratchVersionFull>$(ScratchVersionTriplet)$(GitSemVerDashLabel)</ScratchVersionFull>
@ -31,11 +31,12 @@ This file sets up version properties in our own Scratch way.
<ScratchVersionBuildNumber>$([System.Text.RegularExpressions.Regex]::Match($(GitSemVerLabel), '\d+$'))</ScratchVersionBuildNumber>
<ScratchVersionBuildNumber Condition=" '$(ScratchVersionBuildNumber)' == '' ">$(GitCommits)</ScratchVersionBuildNumber>
<ScratchVersionQuad>$(ScratchVersionTriplet).$(ScratchVersionBuildNumber)</ScratchVersionQuad>
<ScratchVersionBuildTime>$([System.DateTime]::Parse($(GitCommitDate)).ToUniversalTime().ToString(y.Mdd.Hmm))</ScratchVersionBuildTime>
</PropertyGroup>
<Message Text="ScratchVersionTriplet = $(ScratchVersionTriplet)" />
<Message Text="ScratchVersionFull = $(ScratchVersionFull)" />
<Message Text="ScratchVersionHash = $(ScratchVersionHash)" />
<Message Text="ScratchVersionDetail = $(ScratchVersionDetail)" />
<Message Text="ScratchVersionBuildNumber = $(ScratchVersionBuildNumber)" />
<Message Text="ScratchVersionBuildTime = $(ScratchVersionBuildTime)" />
</Target>
</Project>

View file

@ -122,7 +122,7 @@
</PropertyGroup>
<!-- See README.md for details on these version identifiers -->
<Exec Command="plutil -replace 'CFBundleShortVersionString' -string '$(ScratchVersionTriplet)' '$(IntermediateOutputPath)AppManifest.plist'" />
<Exec Command="plutil -replace 'CFBundleVersion' -string '$(ScratchVersionTriplet)' '$(IntermediateOutputPath)AppManifest.plist'" />
<Exec Command="plutil -replace 'CFBundleVersion' -string '$(ScratchVersionBuildTime)' '$(IntermediateOutputPath)AppManifest.plist'" />
<Exec Command="plutil -replace 'ScratchVersionDetail' -string '$(ScratchVersionDetail)' '$(IntermediateOutputPath)AppManifest.plist'" />
</Target>
<Target Name="EmbedSafariHelper" BeforeTargets="_CopyAppExtensionsToBundle" DependsOnTargets="ScratchVersion">
@ -131,7 +131,7 @@
<SafariHelperBundleName>Scratch Link Safari Extension.appex</SafariHelperBundleName>
<SafariHelperSrcPath>$(SafariHelperSrcDir)$(SafariHelperBundleName)/</SafariHelperSrcPath>
</PropertyGroup>
<Exec Condition="!Exists('$(SafariHelperSrcPath)Contents/Info.plist')" Outputs="$(SafariHelperSrcPath)" WorkingDirectory="$(SolutionDir)" Command="xcodebuild -configuration $(Configuration) -project 'Scratch Link Safari Helper/Scratch Link Safari Helper.xcodeproj' -target 'Scratch Link Safari Extension' -destination 'name=Any Mac' 'MARKETING_VERSION=$(ScratchVersionTriplet)' 'CURRENT_PROJECT_VERSION=$(ScratchVersionTriplet)' build" />
<Exec Condition="!Exists('$(SafariHelperSrcPath)Contents/Info.plist')" Outputs="$(SafariHelperSrcPath)" WorkingDirectory="$(SolutionDir)" Command="xcodebuild -configuration $(Configuration) -project 'Scratch Link Safari Helper/Scratch Link Safari Helper.xcodeproj' -target 'Scratch Link Safari Extension' -destination 'name=Any Mac' 'MARKETING_VERSION=$(ScratchVersionTriplet)' 'CURRENT_PROJECT_VERSION=$(ScratchVersionBuildTime)' build" />
<Error Condition="!Exists('$(SafariHelperSrcPath)Contents/Info.plist')" Text="Failed to build the $(Configuration) configuration of Scratch Link Safari Helper. Expected output bundle at:%0a$(SafariHelperSrcPath)" />
<ItemGroup>
<SafariHelperFiles Include="$(SafariHelperSrcPath)\**" />