forked from NOAA-OWP/ngencerf-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_git_info.sh
More file actions
executable file
·35 lines (32 loc) · 1.48 KB
/
generate_git_info.sh
File metadata and controls
executable file
·35 lines (32 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#! /bin/bash
ngencerf_ui="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
# Function to generate git_info.properties
# Should parallel similar functionality in the Dockerfile
generate_git_info() {
repo_url=$(git config --get remote.origin.url)
# Extract the repo name (everything after the last slash) and remove any trailing .git
key=${repo_url##*/}
key=${key%.git}
GIT_INFO_PATH=$ngencerf_ui/${key}_git_info.json
echo "Generating ${GIT_INFO_PATH}..."
jq -n \
--arg commit_hash "$(git rev-parse HEAD)" \
--arg branch "$(git rev-parse --abbrev-ref HEAD)" \
--arg tags "$(git tag --points-at HEAD | tr '\n' ' ')" \
--arg author "$(git log -1 --pretty=format:'%an')" \
--arg commit_date "$(date -u -d @"$(git log -1 --pretty=format:'%ct')" +'%Y-%m-%d %H:%M:%S UTC')" \
--arg message "$(git log -1 --pretty=format:'%s' | tr '\n' ';')" \
--arg build_date "$(date -u +'%Y-%m-%d %H:%M:%S UTC')" \
"{\"${key}\": {commit_hash: \$commit_hash, branch: \$branch, tags: \$tags, author: \$author, commit_date: \$commit_date, message: \$message, build_date: \$build_date}}" \
> "$GIT_INFO_PATH"
echo "Generated $GIT_INFO_PATH"
}
# Check if the script is being sourced or run directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
# Script is being run directly, call the function
generate_git_info
echo
else
# Script is being sourced, print message
echo "generate_git_info function sourced successfully!"
fi