-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"schemaVersion": "1.0", | ||
"artifacts": { | ||
"PackageBuildInfo": { | ||
"type": "executable", | ||
"version": "1.0.2", | ||
"variants": [ | ||
{ | ||
"path": "universal/packageBuildInfo.sh", | ||
"supportedTriples": [ | ||
"x86_64-unknown-linux-gnu", | ||
"arm64-unknown-linux-gnu", | ||
"x86_64-apple-macosx", | ||
"arm64-apple-macosx", | ||
"aarch64-unknown-linux-gnu" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
Binaries/PackageBuildInfo.artifactbundle/universal/packageBuildInfo.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#!/bin/bash | ||
# | ||
# packageBuildInfo.sh | ||
# Generate .swift file with info from git repo | ||
# Part of PackageBuildInfo plugin (https://github.com/DimaRU/PackageBuildInfo) | ||
# | ||
# Copyright © 2024 Dmitriy Borovikov. All rights reserved. | ||
# | ||
if [[ $# != 2 ]]; then | ||
echo "USAGE: packageBuildInfo <git directory> <output file>" | ||
exit 1 | ||
fi | ||
|
||
gitDirectory=$1 | ||
cd "$gitDirectory" || exit 2 | ||
|
||
function trim() { | ||
local var="$*" | ||
# remove leading whitespace characters | ||
var="${var#"${var%%[![:space:]]*}"}" | ||
|
||
# remove trailing whitespace characters | ||
var="${var%"${var##*[![:space:]]}"}" | ||
output=$var | ||
} | ||
|
||
function runGit() { | ||
out=$($1 2>&1) | ||
exitCode=$? | ||
trim "$out" | ||
} | ||
|
||
function getGitInfo() { | ||
runGit "git status --porcelain -uno" | ||
if [[ $exitCode != 0 ]]; then | ||
echo "$output" >&2 | ||
return | ||
fi | ||
if [[ ${#output} == 0 ]]; then | ||
isDirty="false" | ||
fi | ||
|
||
runGit "git describe --tags --abbrev=0" | ||
if [[ $exitCode == 0 && ${#output} != 0 ]]; then | ||
tag=\"$output\" | ||
runGit "git rev-list --count $output..HEAD" | ||
if [[ ${#output} != 0 ]]; then | ||
countSinceTag=$output | ||
fi | ||
fi | ||
|
||
runGit "git rev-parse --abbrev-ref HEAD" | ||
if [[ $exitCode == 0 && ${#output} != 0 ]]; then | ||
branch=\"$output\" | ||
fi | ||
|
||
runGit "git show -s --format=%H:%ct" | ||
if [[ $exitCode == 0 && ${#output} != 0 ]]; then | ||
digest=${output%:*} | ||
date=${output#*:} | ||
fi | ||
|
||
runGit "git rev-list --count HEAD" | ||
if [[ $exitCode == 0 && ${#output} != 0 ]]; then | ||
count=$output | ||
fi | ||
|
||
if [[ ${#digest} != 0 ]]; then | ||
digestS="[0x${digest:0:2}" | ||
for (( start=2; start < ${#digest}; start+=2 )) | ||
do | ||
digestS+=", 0x${digest:$start:2}" | ||
done | ||
digestS+="]" | ||
fi | ||
} | ||
|
||
isDirty="true" | ||
date=$(date +%s) | ||
count="0" | ||
branch="nil" | ||
countSinceTag="0" | ||
tag="nil" | ||
digest="" | ||
digestS="[]" | ||
|
||
TZO=$(date +%z) | ||
TZSIGN=${TZO:0:1}1 | ||
TZHOUR=10#${TZO:1:2} | ||
TZMIN=10#${TZO:3:2} | ||
timeZone=$((TZSIGN*((TZHOUR*60)+TZMIN)*60)) | ||
|
||
getGitInfo | ||
|
||
echo "///// | ||
//// Package Build info | ||
/// Code generated by PackageBuildInfo. DO NOT EDIT. | ||
// | ||
import Foundation | ||
public struct PackageBuild { | ||
let isDirty: Bool // Dirty build - git directory is't clean. | ||
let timeStamp: Date // Time of last commit | ||
let timeZone: TimeZone // Time Zone | ||
let count: Int // Total commit count | ||
let tag: String? // Tag, if exist | ||
let countSinceTag: Int // Commit count since tag | ||
let branch: String? // Git branch name | ||
let digest: [UInt8] // Latest commit sha1 digest (20 bytes) | ||
var commit: String { | ||
digest.reduce(\"\") { \$0 + String(format: \"%02x\", \$1) } | ||
} | ||
static let info = PackageBuild( | ||
isDirty: $isDirty, | ||
timeStamp: Date(timeIntervalSince1970: $date), | ||
timeZone: TimeZone(secondsFromGMT: $timeZone) ?? TimeZone.current, | ||
count: $count, | ||
tag: $tag, | ||
countSinceTag: $countSinceTag, | ||
branch: $branch, | ||
digest: $digestS) | ||
}" >"$2" |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters