From 6b073bef6a8a1c2476971907120094014313ad0a Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Tue, 27 May 2025 19:40:59 +1000 Subject: [PATCH 1/3] fix: conform CFBundleVersion to documentation --- Coder-Desktop/Coder-Desktop/About.swift | 7 +++ Coder-Desktop/Coder-Desktop/Info.plist | 2 + Coder-Desktop/project.yml | 1 + Makefile | 15 ++++++- scripts/version.sh | 60 +++++++++++++++++++++++++ 5 files changed, 83 insertions(+), 2 deletions(-) create mode 100755 scripts/version.sh diff --git a/Coder-Desktop/Coder-Desktop/About.swift b/Coder-Desktop/Coder-Desktop/About.swift index 8849c9bd..902ef409 100644 --- a/Coder-Desktop/Coder-Desktop/About.swift +++ b/Coder-Desktop/Coder-Desktop/About.swift @@ -31,11 +31,18 @@ enum About { return coder } + private static var version: NSString { + let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown" + let commitHash = Bundle.main.infoDictionary?["CommitHash"] as? String ?? "Unknown" + return "Version \(version) - \(commitHash)" as NSString + } + @MainActor static func open() { appActivate() NSApp.orderFrontStandardAboutPanel(options: [ .credits: credits, + .applicationVersion: version, ]) } } diff --git a/Coder-Desktop/Coder-Desktop/Info.plist b/Coder-Desktop/Coder-Desktop/Info.plist index c1bf929a..4bfd96ff 100644 --- a/Coder-Desktop/Coder-Desktop/Info.plist +++ b/Coder-Desktop/Coder-Desktop/Info.plist @@ -33,5 +33,7 @@ SUPublicEDKey Ae2oQLTcx89/a73XrpOt+IVvqdo+fMTjo3UKEm77VdA= + CommitHash + $(GIT_COMMIT_HASH) diff --git a/Coder-Desktop/project.yml b/Coder-Desktop/project.yml index 224add81..679afad0 100644 --- a/Coder-Desktop/project.yml +++ b/Coder-Desktop/project.yml @@ -13,6 +13,7 @@ settings: base: MARKETING_VERSION: ${MARKETING_VERSION} # Sets the version number. CURRENT_PROJECT_VERSION: ${CURRENT_PROJECT_VERSION} # Sets the build number. + GIT_COMMIT_HASH: ${GIT_COMMIT_HASH} ALWAYS_SEARCH_USER_PATHS: NO ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS: YES diff --git a/Makefile b/Makefile index e50b060c..4172f04d 100644 --- a/Makefile +++ b/Makefile @@ -32,19 +32,29 @@ $(error MUTAGEN_VERSION must be a valid version) endif ifndef CURRENT_PROJECT_VERSION -CURRENT_PROJECT_VERSION:=$(shell git describe --match 'v[0-9]*' --dirty='.devel' --always --tags) +# Must be X.Y.Z[.N] +CURRENT_PROJECT_VERSION:=$(shell ./scripts/version.sh) endif ifeq ($(strip $(CURRENT_PROJECT_VERSION)),) $(error CURRENT_PROJECT_VERSION cannot be empty) endif ifndef MARKETING_VERSION -MARKETING_VERSION:=$(shell git describe --match 'v[0-9]*' --tags --abbrev=0 | sed 's/^v//' | sed 's/-.*$$//') +# Must be X.Y.Z +MARKETING_VERSION:=$(shell ./scripts/version.sh --short) endif ifeq ($(strip $(MARKETING_VERSION)),) $(error MARKETING_VERSION cannot be empty) endif +ifndef GIT_COMMIT_HASH +# Must be a valid git commit hash +GIT_COMMIT_HASH := $(shell ./scripts/version.sh --hash) +endif +ifeq ($(strip $(GIT_COMMIT_HASH)),) +$(error GIT_COMMIT_HASH cannot be empty) +endif + # Define the keychain file name first KEYCHAIN_FILE := app-signing.keychain-db # Use shell to get the absolute path only if the file exists @@ -70,6 +80,7 @@ $(XCPROJECT): $(PROJECT)/project.yml EXT_PROVISIONING_PROFILE_ID=${EXT_PROVISIONING_PROFILE_ID} \ CURRENT_PROJECT_VERSION=$(CURRENT_PROJECT_VERSION) \ MARKETING_VERSION=$(MARKETING_VERSION) \ + GIT_COMMIT_HASH=$(GIT_COMMIT_HASH) \ xcodegen $(PROJECT)/VPNLib/vpn.pb.swift: $(PROJECT)/VPNLib/vpn.proto diff --git a/scripts/version.sh b/scripts/version.sh new file mode 100755 index 00000000..22a1dff4 --- /dev/null +++ b/scripts/version.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +set -euo pipefail + +usage() { + echo "Usage: $0 [--short] [--hash]" + echo " --short Output only the version (X.Y.Z or X.Y.Z.N)" + echo " --hash Output only the commit hash" + echo " -h, --help Display this help message" + echo "" + echo "With no flags, outputs: X.Y.Z[.N]" +} + +SHORT=false +HASH_ONLY=false + +while [[ "$#" -gt 0 ]]; do + case $1 in + --short) + SHORT=true + shift + ;; + --hash) + HASH_ONLY=true + shift + ;; + -h | --help) + usage + exit 0 + ;; + *) + echo "Unknown parameter passed: $1" + usage + exit 1 + ;; + esac +done + +if [[ "$HASH_ONLY" == true ]]; then + current_hash=$(git rev-parse --short=7 HEAD) + echo "$current_hash" + exit 0 +fi + +describe_output=$(git describe --tags) + +# Of the form `vX.Y.Z-N-gHASH` +if [[ $describe_output =~ ^v([0-9]+\.[0-9]+\.[0-9]+)(-([0-9]+)-g[a-f0-9]+)?$ ]]; then + version=${BASH_REMATCH[1]} # X.Y.Z + commits=${BASH_REMATCH[3]} # number of commits since tag + + if [[ "$SHORT" == true ]]; then + echo "$version" + exit 0 + fi + + echo "${version}.${commits}" +else + echo "Error: Could not parse git describe output: $describe_output" >&2 + exit 1 +fi \ No newline at end of file From f179ea089989f2f4c645d7ab1cf5c0258508b493 Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Tue, 27 May 2025 20:11:31 +1000 Subject: [PATCH 2/3] help msg --- scripts/version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/version.sh b/scripts/version.sh index 22a1dff4..3ca8d03f 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -3,7 +3,7 @@ set -euo pipefail usage() { echo "Usage: $0 [--short] [--hash]" - echo " --short Output only the version (X.Y.Z or X.Y.Z.N)" + echo " --short Output a CFBundleShortVersionString compatible version (X.Y.Z)" echo " --hash Output only the commit hash" echo " -h, --help Display this help message" echo "" From 2c597758d0fa03c1b081e717f2b30b9e2b3f3c40 Mon Sep 17 00:00:00 2001 From: Ethan Dickson Date: Wed, 28 May 2025 13:36:10 +1000 Subject: [PATCH 3/3] fix indenting --- Coder-Desktop/Coder-Desktop/Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Coder-Desktop/Coder-Desktop/Info.plist b/Coder-Desktop/Coder-Desktop/Info.plist index 4bfd96ff..bb759f6b 100644 --- a/Coder-Desktop/Coder-Desktop/Info.plist +++ b/Coder-Desktop/Coder-Desktop/Info.plist @@ -32,7 +32,7 @@ $(TeamIdentifierPrefix)com.coder.Coder-Desktop.VPN SUPublicEDKey - Ae2oQLTcx89/a73XrpOt+IVvqdo+fMTjo3UKEm77VdA= + Ae2oQLTcx89/a73XrpOt+IVvqdo+fMTjo3UKEm77VdA= CommitHash $(GIT_COMMIT_HASH)