-
-
Save WEBOWNIA/4c1a52363b797cd2ba29c334ace712d0 to your computer and use it in GitHub Desktop.
Including github Commit in Spring Boot App
This file contains hidden or 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
- name: set env variables | |
run: | | |
echo "git_branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV | |
echo "git_hash=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_ENV | |
- name: Run Update Version file | |
run: | | |
echo "Branch: ${{ env.git_branch }}" | |
echo "Sha: ${{ env.git_hash }}" | |
. scripts/version.sh ${{ env.git_branch }} ${{ env.git_hash }} | |
- name: Build with Maven | |
run: mvn -B package --file pom.xml |
This file contains hidden or 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
@Component | |
@PropertySource("classpath:version.properties") | |
public class VersionConfig { | |
@Getter | |
@Value("${tiger.hash:unknown}") | |
private String hash; | |
@Value("${tiger.time:unknownTime}") | |
private String buildTime; | |
@Value("${tiger.name:unknownCommitName}") | |
private String commitName; | |
private String version = VersionConfig.class.getPackage().getImplementationVersion(); | |
} |
This file contains hidden or 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
# Check if two arguments are provided | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 <hash_value> <name_value>" | |
exit 1 | |
fi | |
# Assign arguments to variables | |
HASH_VALUE=$1 | |
NAME_VALUE=$2 | |
# Get current date and time | |
CURRENT_DATETIME=$(date '+%Y-%m-%d %H:%M:%S') | |
# Define the output file | |
OUTPUT_FILE="src/main/resources/version.properties" | |
# Write content to the file | |
echo "tiger.hash=$HASH_VALUE" > "$OUTPUT_FILE" | |
echo "tiger.time=$CURRENT_DATETIME" >> "$OUTPUT_FILE" | |
echo "tiger.name=$NAME_VALUE" >> "$OUTPUT_FILE" | |
# Print success message | |
echo "File '$OUTPUT_FILE' has been created/updated successfully." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment