Skip to content

Commit

Permalink
refactor: rework info generation
Browse files Browse the repository at this point in the history
  • Loading branch information
mishamyrt committed Jul 12, 2024
1 parent 9e8e66c commit e4655d6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 24 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
VERSION := 1.0.0
BUILD_INFO_FILE := Sources/BuildInfo.swift
BUILD_INFO_TEMPLATE := Sources/BuildInfo.template.swift

.PHONY: help
help: ## print this message
Expand All @@ -11,7 +12,8 @@ help: ## print this message

.PHONY: generate
generate: ## generate build info
@bash scripts/generate.bash $(VERSION)
@bash build/generate-info.sh \
"${BUILD_INFO_TEMPLATE}" "${VERSION}" > "${BUILD_INFO_FILE}"

.PHONY: build
build: generate ## build runon
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let package = Package(
.product(name: "Rainbow", package: "Rainbow"),
.product(name: "Shellac", package: "swift-shellac"),
],
exclude: ["BuildInfo.swift.dist"]
exclude: ["BuildInfo.template.swift"]
),
.testTarget(
name: "runonTests",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is autogenerated. Do not edit it by hand.
let kAppVersion = "$APP_VERSION"
let kBuildCommit = "$BUILD_COMMIT"
let kBuildDate = "$BUILD_DATE"
let kBuildCommit = "$APP_BUILD_COMMIT"
let kBuildDate = "$APP_BUILD_DATE"
26 changes: 26 additions & 0 deletions build/generate-info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
# Generate info file from template
# Usage: ./generate-info.sh <build-info-template> <version>
# Supported template variables:
# - $APP_VERSION - app version
# - $APP_BUILD_COMMIT - current commit hash
# - $APP_BUILD_DATE - current build date

set -e

if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 <build-info-template> <version>"
exit 1
fi

TEMPLATE_PATH="$1"
VERSION="$2"

APP_VERSION="$VERSION" \
APP_BUILD_COMMIT="$(git rev-parse --short HEAD)" \
APP_BUILD_DATE="$(date -u +"%Y-%m-%d")" \
envsubst "\
\$APP_VERSION \
\$APP_BUILD_COMMIT \
\$APP_BUILD_DATE" \
< "$TEMPLATE_PATH"
20 changes: 0 additions & 20 deletions scripts/generate.bash

This file was deleted.

0 comments on commit e4655d6

Please sign in to comment.