Skip to content

Commit

Permalink
feat: add build-time variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mishamyrt committed Jul 11, 2024
1 parent 05e30f0 commit 615fb59
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ dist/
.swiftpm/
.netrc
.vscode

# Generated files
Sources/BuildInfo.swift
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
VERSION := 1.0.0
BUILD_INFO_FILE := Sources/BuildInfo.swift

.PHONY: help
help: ## print this message
@awk \
'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / \
{printf "\033[33m%-15s\033[0m %s\n", $$1, $$2}' \
$(MAKEFILE_LIST)


.PHONY: generate
generate: ## generate build info
@bash scripts/generate.bash $(VERSION)

.PHONY: build
build: ## build runon
build: generate ## build runon
swift build
rm -rf ./dist
mkdir ./dist
Expand All @@ -15,7 +23,7 @@ build: ## build runon
chmod +x ./dist/runon

.PHONY: lint
lint: ## check code style
lint: generate ## check code style
swiftlint lint --config .swiftlint.yaml .
shellcheck -a scripts/runon.bash

Expand All @@ -27,5 +35,5 @@ install: ## install runon to the system
cp dist/* /usr/local/bin/

.PHONY: test
test: ## run tests
test: generate ## run tests
swift test
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ let package = Package(
.product(name: "SimplyCoreAudio", package: "SimplyCoreAudio"),
.product(name: "Rainbow", package: "Rainbow"),
.product(name: "Shellac", package: "swift-shellac"),
]
],
exclude: ["BuildInfo.swift.dist"]
),
.testTarget(
name: "runonTests",
Expand Down
4 changes: 4 additions & 0 deletions Sources/BuildInfo.swift.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This file is autogenerated. Do not edit it by hand.
let kAppVersion = "$APP_VERSION"
let kBuildCommit = "$BUILD_COMMIT"
let kBuildDate: String = "$BUILD_DATE"
3 changes: 2 additions & 1 deletion Sources/RunOn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ struct RunOn: ParsableCommand {
static var configuration = CommandConfiguration(
commandName: "runon-daemon",
abstract: "A utility for automating actions on system events.",
version: "1.0.0",
discussion: "VERSION: \(kAppVersion) (\(kBuildCommit))",
version: kAppVersion,
subcommands: [Run.self, Autostart.self, Print.self],
defaultSubcommand: Run.self
)
Expand Down
20 changes: 20 additions & 0 deletions scripts/generate.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

TPL_FILE="Sources/BuildInfo.swift.dist"
OUT_FILE="Sources/BuildInfo.swift"

if [ ! -f "$TPL_FILE" ]; then
echo "File not found: $TPL_FILE"
exit 1
elif [ -z "$1" ]; then
echo "Version not specified"
exit 1
fi

set -e

APP_VERSION=${1} \
BUILD_COMMIT="$(git rev-parse --short HEAD)" \
BUILD_DATE="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
envsubst "\$APP_VERSION \$BUILD_COMMIT \$BUILD_DATE" < "$TPL_FILE" > "$OUT_FILE"

0 comments on commit 615fb59

Please sign in to comment.