Skip to content

Commit

Permalink
fix: Add additional debug info (#19)
Browse files Browse the repository at this point in the history
Adds additional debug information.
  • Loading branch information
MAHDTech authored May 22, 2023
1 parent a28a2d6 commit 71c73c7
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jobs:

- id: setup_buildx
name: Setup BuildX
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

- id: login
name: Login to Container registry
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ jobs:

- id: setup_buildx
name: Setup BuildX
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

- id: login
name: Login to Container registry
Expand Down
12 changes: 12 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ inputs:
required: false
default: "UTC-0"

# INPUT_CALVER_PREFIX
calver_prefix:
description: "A manual prefix to apply to the calendar version number. For example; 'v'"
required: false
default: ""

# INPUT_CALVER_SUFFIX
calver_suffix:
description: "A manual suffix to apply to the calendar version number. For example; '-dev'"
required: false
default: ""

### SemVer ###

# INPUT_SEMVER_ENABLE
Expand Down
4 changes: 2 additions & 2 deletions examples/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:

- id: prep_release
name: Prepare for Release
uses: salt-labs/action-its-shipping-time@master
uses: salt-labs/action-its-shipping-time@trunk
with:
loglevel: "INFO"
tag_enable: "TRUE"
Expand All @@ -59,7 +59,7 @@ jobs:
calver_suffix: ""
calver_split: "."
calver_split_mod: "."
timezone: "Australia/Sydney"
calver_timezone: "Australia/Sydney"

- id: create_release
name: Create Release
Expand Down
42 changes: 24 additions & 18 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export CALVER_SCHEME="${INPUT_CALVER_SCHEME:=YYYY.0M.0D.GEN}"
export CALVER_SPLIT="${INPUT_CALVER_SPLIT:=.}"
export CALVER_SPLIT_MOD="${INPUT_CALVER_SPLIT_MOD:=$CALVER_SPLIT}"
export TZ="${INPUT_CALVER_TIMEZONE:=UTC-0}"
export CALVER_PREFIX="${INPUT_CALVER_PREFIX}"
export CALVER_SUFFIX="${INPUT_CALVER_SUFFIX}"

# Semantic Versioning
export SEMVER_ENABLE="${INPUT_SEMVER_ENABLE:=FALSE}"
Expand Down Expand Up @@ -65,13 +67,13 @@ declare -r REQ_BINS=(
source "$(dirname "${BASH_SOURCE[0]}")/functions.sh"

checkLogLevel "${LOGLEVEL}" || {
writeLog "ERROR" "Failed to check the log level"
exit 1
writeLog "ERROR" "Failed to check the log level"
exit 1
}

checkReqs || {
writeLog "ERROR" "Failed to check all requirements"
exit 1
writeLog "ERROR" "Failed to check all requirements"
exit 1
}

# Used if the CI is running a simple test
Expand All @@ -96,6 +98,8 @@ fi

if [ "${LOGLEVEL}" == "DEBUG" ]; then

writeLog "DEBUG" "########## Start Dump ##########"

writeLog "DEBUG" "Dumping diagnostic information for shell ${SHELL} ${BASH_VERSION}"

writeLog "DEBUG" "########## Environment ##########"
Expand All @@ -110,6 +114,8 @@ if [ "${LOGLEVEL}" == "DEBUG" ]; then
writeLog "DEBUG" "########## Exported Function Contents ##########"
export -f

writeLog "DEBUG" "########## End Dump ##########"

fi

#########################
Expand All @@ -118,14 +124,14 @@ fi

# Configure Git with a default user
gitConfig || {
writeLog "ERROR" "Failed to configure the git user"
exit 1
writeLog "ERROR" "Failed to configure the git user"
exit 1
}

# Fetch all the tags that are required for this Action to work
gitFetchAll || {
writeLog "ERROR" "Failed to fetch all the Git tags!"
exit 1
writeLog "ERROR" "Failed to fetch all the Git tags!"
exit 1
}

# Check the TimeZone is available if it was modified by an input
Expand All @@ -144,8 +150,8 @@ if [ "${CALVER_ENABLE^^}" == "TRUE" ]; then
writeLog "INFO" "Determining Calendar Version"

getCalVer "${CALVER_SCHEME}" "${CALVER_SPLIT}" "${CALVER_SPLIT_MOD}" || {
writeLog "ERROR" "Failed to get the current Calendar Version"
exit 1
writeLog "ERROR" "Failed to get the current Calendar Version"
exit 1
}

# Append any prefix and suffix if provided
Expand All @@ -161,8 +167,8 @@ fi
if [ "${SEMVER_ENABLE^^}" == "TRUE" ]; then

getSemVer "${SEMVER_TYPE}" "${SEMVER_PREFIX}" || {
writeLog "ERROR" "Failed to get the current Semantic Version"
exit 1
writeLog "ERROR" "Failed to get the current Semantic Version"
exit 1
}

writeLog "INFO" "Semantic Version: ${SEMVER}"
Expand All @@ -175,8 +181,8 @@ fi
if [ "${CHANGELOG_ENABLE^^}" == "TRUE" ]; then

gitChangelog || {
writeLog "ERROR" "Failed to generate change log"
exit 1
writeLog "ERROR" "Failed to generate change log"
exit 1
}

writeLog "INFO" "Branch changelog"
Expand Down Expand Up @@ -210,15 +216,15 @@ if [ "${TAG_ENABLE^^}" == "TRUE" ]; then

if [ "${CALVER_ENABLE^^}" == "TRUE" ]; then
gitTag "${CALVER}" "${TAG_FORCE^^}" || {
writeLog "ERROR" "Failed to apply the tag ${CALVER}"
exit 1
writeLog "ERROR" "Failed to apply the tag ${CALVER}"
exit 1
}
fi

if [ "${SEMVER_ENABLE^^}" == "TRUE" ]; then
gitTag "${SEMVER}" "${TAG_FORCE^^}" || {
writeLog "ERROR" "Failed to apply the tag ${SEMVER}"
exit 1
writeLog "ERROR" "Failed to apply the tag ${SEMVER}"
exit 1
}
fi

Expand Down
59 changes: 42 additions & 17 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function checkReqs() {
for BIN in "${REQ_BINS[@]}"; do
writeLog "DEBUG" "Checking for dependant binary ${BIN}"
checkBin "${BIN}" || {
writeLog "ERROR" "Please install the ${BIN} binary on this system in order to run ${SCRIPT}"
return 1
writeLog "ERROR" "Please install the ${BIN} binary on this system in order to run ${SCRIPT}"
return 1
}
done

Expand Down Expand Up @@ -235,13 +235,13 @@ function gitConfig() {
git config --global user.email "${GITHUB_ACTOR:-user}@users.noreply.github.com" ||
{
writeLog "ERROR" "Failed to configure the git user email"
return 1
return 1
}

git config --global user.name "GitHub Actions" ||
{
writeLog "ERROR" "Failed to configure the git user name"
return 1
return 1
}

return 0
Expand All @@ -257,7 +257,7 @@ function gitFetchAll() {
git fetch --prune --tags --prune-tags --all ||
{
writeLog "ERROR" "Failed to fetch git tags"
return 1
return 1
}

return 0
Expand All @@ -267,6 +267,7 @@ function gitFetchAll() {
function getCalVer() {

# Determines the current Calendar Version in the provided scheme.
writeLog "DEBUG" "Entered getCalVer"

# Parameters
local SCHEME="${1}"
Expand All @@ -279,6 +280,10 @@ function getCalVer() {
SPLIT="${SPLIT:=.}"
SPLIT_MOD="${SPLIT_MOD:=$SPLIT}"

writeLog "DEBUG" "Scheme: ${SCHEME}"
writeLog "DEBUG" "Split: ${SPLIT}"
writeLog "DEBUG" "Split Mod: ${SPLIT_MOD}"

# The user provided CalVer
local -a ARR_SCHEME_VER
local -a ARR_MOD_VER
Expand Down Expand Up @@ -323,12 +328,24 @@ function getCalVer() {
MICRO_VER="${ARR_SCHEME_VER[2]}"
MOD_VER="${ARR_SCHEME_VER[3]}"

writeLog "DEBUG" "## Split Ver ###"
writeLog "DEBUG" "Major: ${MAJOR_VER:-EMPTY}"
writeLog "DEBUG" "Minor: ${MINOR_VER:-EMPTY}"
writeLog "DEBUG" "Micro: ${MICRO_VER:-EMPTY}"
writeLog "DEBUG" "Mod: ${MOD_VER:-EMPTY}"

# Do the same for the Git Tag
MAJOR_TAG="${ARR_SCHEME_TAG[0]}"
MINOR_TAG="${ARR_SCHEME_TAG[1]}"
MICRO_TAG="${ARR_SCHEME_TAG[2]}"
MOD_TAG="${ARR_SCHEME_TAG[3]}"

writeLog "DEBUG" "## Split Tag ###"
writeLog "DEBUG" "Major: ${MAJOR_TAG:-EMPTY}"
writeLog "DEBUG" "Minor: ${MINOR_TAG:-EMPTY}"
writeLog "DEBUG" "Micro: ${MICRO_TAG:-EMPTY}"
writeLog "DEBUG" "Mod: ${MOD_TAG:-EMPTY}"

# If the MODIFIER is empty, split MICRO again by SPLIT_MOD
mapfile -t -d "${SPLIT_MOD}" ARR_MOD_VER <<< "${MICRO_VER}"
mapfile -t -d "${SPLIT_MOD}" ARR_MOD_TAG <<< "${MICRO_TAG}"
Expand All @@ -337,10 +354,18 @@ function getCalVer() {
MICRO_VER="${ARR_MOD_VER[0]}"
MOD_VER="${MOD_VER:=${ARR_MOD_VER[1]}}"

writeLog "DEBUG" "## Split Mod Ver ###"
writeLog "DEBUG" "Micro: ${MICRO_VER:-EMPTY}"
writeLog "DEBUG" "Mod: ${MOD_VER:-EMPTY}"

# Re-split the Tag into MICRO and MOD (only if MOD is empty)
MICRO_TAG="${ARR_MOD_TAG[0]}"
MOD_TAG="${MOD_TAG:=${ARR_MOD_TAG[1]}}"

writeLog "DEBUG" "## Split Mod Tag ###"
writeLog "DEBUG" "Micro: ${MICRO_TAG:-EMPTY}"
writeLog "DEBUG" "Mod: ${MOD_TAG:-EMPTY}"

# Strip all new lines
MAJOR_VER="${MAJOR_VER//$'\n'/}"
MINOR_VER="${MINOR_VER//$'\n'/}"
Expand Down Expand Up @@ -392,19 +417,19 @@ function getCalVer() {
# Determine if there is a potential tag clash
[ "${MAJOR_VER:-EMPTY}" = "${MAJOR_TAG}" ] && {
MAJOR_MATCH="TRUE"
writeLog "DEBUG" "MAJOR Matched existing tag!"
writeLog "DEBUG" "MAJOR Matched existing tag!"
}
[ "${MINOR_VER:-EMPTY}" = "${MINOR_TAG}" ] && {
MINOR_MATCH="TRUE"
writeLog "DEBUG" "MINOR Matched existing tag!"
writeLog "DEBUG" "MINOR Matched existing tag!"
}
[ "${MICRO_VER:-EMPTY}" = "${MICRO_TAG}" ] && {
MICRO_MATCH="TRUE"
writeLog "DEBUG" "MICRO Matched existing tag!"
writeLog "DEBUG" "MICRO Matched existing tag!"
}
[ "${MOD_VER:-EMPTY}" = "${MOD_TAG}" ] && {
MOD_MATCH="TRUE"
writeLog "DEBUG" "MODIFIER Matched existing tag!"
writeLog "DEBUG" "MODIFIER Matched existing tag!"
}

# The Calendar Versioning scheme stipulates that;
Expand Down Expand Up @@ -598,8 +623,8 @@ function gitChangelog() {
CHANGELOG=$(git --git-dir="${GIT_DIR}" log --pretty=format:"${GIT_PRETTY_FORMAT}")

checkResult $? || {
writeLog "ERROR" "Failed to obtain change log for full commit history"
return 1
writeLog "ERROR" "Failed to obtain change log for full commit history"
return 1
}

else
Expand All @@ -609,8 +634,8 @@ function gitChangelog() {
CHANGELOG=$(git --git-dir="${GIT_DIR}" log "${TAG}"..HEAD --pretty=format:"${GIT_PRETTY_FORMAT}")

checkResult $? || {
writeLog "ERROR" "Failed to obtain change log between HEAD and ${TAG}"
return 1
writeLog "ERROR" "Failed to obtain change log between HEAD and ${TAG}"
return 1
}

fi
Expand Down Expand Up @@ -665,7 +690,7 @@ function gitTag() {
tag --annotate --no-sign --force --message "Release ${TAG}" "${TAG}" ||
{
writeLog "ERROR" "Unable to apply tag ${TAG}"
return 1
return 1
}

else
Expand All @@ -674,7 +699,7 @@ function gitTag() {
tag --annotate --no-sign --message "Release ${TAG}" "${TAG}" ||
{
writeLog "ERROR" "Unable to apply tag ${TAG}. Force is not enabled"
return 0
return 0
}

fi
Expand All @@ -686,7 +711,7 @@ function gitTag() {
tag --list -n1 ||
{
writeLog "ERROR" "Failed to list tags"
return 1
return 1
}

writeLog "INFO" "Pushing new Git tag ${TAG} to origin"
Expand All @@ -696,7 +721,7 @@ function gitTag() {
push origin --force --tags ||
{
writeLog "ERROR" "Failed to push tag ${TAG} to origin"
return 1
return 1
}

return 0
Expand Down

0 comments on commit 71c73c7

Please sign in to comment.