From 1691f7fe4e028df39a48a1d26cf9487d76547b19 Mon Sep 17 00:00:00 2001 From: Bilaal Rashid <42493384+bilaalrashid@users.noreply.github.com> Date: Sun, 10 Nov 2024 22:46:43 +0000 Subject: [PATCH 1/2] Display version in settings page --- ReadBeeb/Screens/SettingsScreen.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ReadBeeb/Screens/SettingsScreen.swift b/ReadBeeb/Screens/SettingsScreen.swift index 570f62d..68b1615 100644 --- a/ReadBeeb/Screens/SettingsScreen.swift +++ b/ReadBeeb/Screens/SettingsScreen.swift @@ -26,6 +26,21 @@ struct SettingsScreen: View { @AppStorage(Constants.UserDefaultIdentifiers.service) private var service = Service.english.rawValue + /// The text displayed as a footer + var footerText: String { + let credit = "A Bilaal Rashid project" + + guard let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String else { + return credit + } + + guard let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String else { + return credit + } + + return "Version \(version) (\(build))\n\(credit)" + } + var body: some View { List { Section { @@ -60,7 +75,7 @@ struct SettingsScreen: View { } Section( - footer: NavigationLink("A Bilaal Rashid project") { + footer: NavigationLink(self.footerText) { LogScreen() } .buttonStyle(.plain) From 4a309400db380844e5685aae29ac5b0f0e244742 Mon Sep 17 00:00:00 2001 From: Bilaal Rashid <42493384+bilaalrashid@users.noreply.github.com> Date: Tue, 12 Nov 2024 22:54:07 +0000 Subject: [PATCH 2/2] Add version bump script --- Makefile | 19 +++++++- README.md | 24 ++++++++-- bin/version-bump | 114 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+), 5 deletions(-) create mode 100755 bin/version-bump diff --git a/Makefile b/Makefile index 079b3b2..01cb80f 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,19 @@ +XCODE_PROJECT = ReadBeeb.xcodeproj/project.pbxproj +TOPICS_FILE = ReadBeeb/Files/Topics.json + +release-version: + bin/version-bump --xcode-project $(XCODE_PROJECT) --version $(VERSION) + +release-major: + bin/version-bump --xcode-project $(XCODE_PROJECT) --bump-type major + +release-minor: + bin/version-bump --xcode-project $(XCODE_PROJECT) --bump-type minor + +release-patch: + bin/version-bump --xcode-project $(XCODE_PROJECT) --bump-type patch + +release: release-patch + topics: - bin/fetch-topics $(API_KEY) > ReadBeeb/Files/Topics.json + bin/fetch-topics $(API_KEY) > $(TOPICS_FILE) diff --git a/README.md b/README.md index 7aba7b3..c790e4c 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,9 @@ This project is for educational and research purposes only. ## Development +This repository contains the ReadBeeb-specific logic and GUI code. +Logic related to the BBC News API should be contributed to [bbc-news-swift](https://github.com/bilaalrashid/bbc-news-swift). + Prerequisites: - [SwiftLint](https://github.com/realm/SwiftLint) - [Swift Package Manager](https://www.swift.org/documentation/package-manager/) @@ -49,11 +52,24 @@ open ReadBeeb/ReadBeeb.xcodeproj Full contributing guidelines can be found in [CONTRIBUTING.md](CONTRIBUTING.md). -## Release +## Tools -1. Update the list of installed topics: +To update the list of installed topics: ``` make topics API_KEY= ``` -2. Bump the version and build number in [project.pbxproj](ReadBeeb.xcodeproj/project.pbxproj/) -3. Creating a matching tag and release once merged into `main` + +## Release + +On the `main` branch: +1. Bump the version and build number, and tag the project +``` +make release # Defaults to patch +make release- +make release-version VERSION= +``` +2. Push to the remote +``` +git push --tags +``` +3. Create a corresponding [release](https://github.com/bilaalrashid/ReadBeeb/releases/new) on GitHub diff --git a/bin/version-bump b/bin/version-bump new file mode 100755 index 0000000..6ffb643 --- /dev/null +++ b/bin/version-bump @@ -0,0 +1,114 @@ +#!/usr/bin/env bash + +# version-bump +# Bumps the version number of an Xcode project and increments the build number. +# +# Usage: ./version-bump --xcode-project [--bump-type ] [--version ] + +### Functions + +function semver_major_bump { + local version="$1" + echo "$version"| awk -F. -v OFS=. '{$1++; $2=$3=0; print}' +} + +function semver_minor_bump { + local version="$1" + echo "$version"| awk -F. -v OFS=. '{$2++; $3=0; print}' +} + +function semver_patch_bump { + local version="$1" + echo "$version"| awk -F. -v OFS=. '{$3++; print}' +} + +function get_current_version { + grep -Po "MARKETING_VERSION = \K([0-9]+\.[0-9]+(?:\.[0-9]+)?)" "$xcode_project" | awk -F. '{printf "%d.%d.%d\n", $1, ($2?$2:0), ($3?$3:0)}' | head -n1 +} + +function bump_version { + local xcode_project="$1" + local version="$2" + perl -pi -e "s/\bMARKETING_VERSION = [0-9]+(\.[0-9])+;$/MARKETING_VERSION = $version;/g" "$xcode_project" +} + +### Main + +while [ $# -gt 0 ]; do + case "$1" in + --xcode-project) + xcode_project="$2" + shift 2 + ;; + --version) + version="$2" + shift 2 + ;; + --bump-type) + bump_type="$2" + shift 2 + ;; + *) + echo "Error: Invalid option" + exit 1 + ;; + esac +done + +if [ -z "$xcode_project" ]; then + echo "error: Please specify the path to the Xcode project file using --xcode-project." + exit 1 +fi + +if [ -z "$bump_type" ] && [ -z "$version" ]; then + echo "error: Please specify either a bump type or version string using --bump-type or --version." + exit 1 +fi + +if [ -z "$version" ]; then + case "$bump_type" in + major) + version=$(semver_major_bump "$(get_current_version)") + ;; + minor) + version=$(semver_minor_bump "$(get_current_version)") + ;; + patch) + version=$(semver_patch_bump "$(get_current_version)") + ;; + *) + echo "Error: Invalid option passed to --bump-type" + exit 1 + ;; + esac + + echo "No version specified, bumping to $version" +fi + +# Make sure working directory is clean. +if output=$(git status --porcelain) && [ -n "$output" ]; then + printf "error: Please commit any uncommitted files before proceeding:\n%s\n" "$output" + exit 1 +fi + +# Make sure we are on primary branch +branch=$(git rev-parse --abbrev-ref HEAD) +if [[ "$branch" != "master" && "$branch" != "main" ]]; then + echo "error: Please switch to the main or master branch before proceeding." + exit 1 +fi + +# Increment the build number +agvtool bump +new_build=$(agvtool vers -terse) + +# Update the version number +bump_version "$xcode_project" "$version" +new_version=$(get_current_version) + +# Commit +git add . +git commit -m "Bump to v$new_version($new_build)" + +# Tag +git tag -a "v$new_version" -m "Bump to v$new_version($new_build)"