Skip to content

Commit

Permalink
Fix version sorting in git_changelog
Browse files Browse the repository at this point in the history
- Updated integration tests
- Added integration test with pre-release version tag
  • Loading branch information
JonatanAntoni authored Nov 21, 2022
1 parent 0e878e7 commit c8a5ef3
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 30 deletions.
2 changes: 1 addition & 1 deletion gen-pack
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

GEN_PACK_LIB_VERSION="0.6.1"
GEN_PACK_LIB_VERSION="0.6.2"
GEN_PACK_LIB_SOURCE="$(realpath $(dirname ${BASH_SOURCE}))"

shopt -s expand_aliases
Expand Down
7 changes: 6 additions & 1 deletion lib/gittools
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ function git_changelog {
shift # past argument
done

local TAGS=($("${UTILITY_GIT}" for-each-ref --format "%(refname)" --sort="-v:refname" "refs/tags/${PREFIX}*"))
local TAGS=($(\
GIT_CONFIG_COUNT=1\
GIT_CONFIG_KEY_0="versionsort.suffix"\
GIT_CONFIG_VALUE_0="-"\
"${UTILITY_GIT}" for-each-ref --format "%(refname)" --sort="-v:refname" "refs/tags/${PREFIX}*"\
))
local LATEST=$(git_describe "${PREFIX}")

git_changelog_${FORMAT}_head
Expand Down
6 changes: 4 additions & 2 deletions template/gen_pack.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# Version: 2.3
# Date: 2022-09-28
# Version: 2.4
# Date: 2022-11-21
# This bash script generates a CMSIS Software Pack:
#

Expand Down Expand Up @@ -59,13 +59,15 @@ PACK_CHANGELOG_MODE="<full|release|tag>"
function preprocess() {
# add custom steps here to be executed
# before populating the pack build folder
return 0
}

# custom post-processing steps
function postprocess() {
# add custom steps here to be executed
# after populating the pack build folder
# but before archiving the pack into output folder
return 0
}

############ DO NOT EDIT BELOW ###########
Expand Down
41 changes: 35 additions & 6 deletions test/test_integ_default/gen_pack.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash
# Version: 2.0
# Date: 2022-07-28
# Version: 2.4
# Date: 2022-11-21
# This bash script generates a CMSIS Software Pack:
#

set -o pipefail

# Set version of gen pack library
REQUIRED_GEN_PACK_LIB="0.1.0"
REQUIRED_GEN_PACK_LIB=""

# Set default command line arguments
DEFAULT_ARGS=()
Expand All @@ -28,17 +28,46 @@ PACK_BASE_FILES="

# Specify file names to be deleted from pack build directory
PACK_DELETE_FILES="
doc/test.dxy
doc/test.dxy
"

# Specify patches to be applied
PACK_PATCH_FILES="
test.patch
test.patch
"

# Specify addition argument to packchk
PACKCHK_ARGS=()

# Specify additional dependencies for packchk
PACKCHK_DEPS=""

# Optional: restrict fallback modes for changelog generation
# Default: full
# Values:
# - full Tag annotations, release descriptions, or commit messages (in order)
# - release Tag annotations, or release descriptions (in order)
# - tag Tag annotations only
PACK_CHANGELOG_MODE="full"

# custom pre-processing steps
function preprocess() {
# add custom steps here to be executed
# before populating the pack build folder
return 0
}

# custom post-processing steps
function postprocess() {
# add custom steps here to be executed
# after populating the pack build folder
# but before archiving the pack into output folder
return 0
}

############ DO NOT EDIT BELOW ###########

. "$(dirname "$0")/../../gen-pack"
. "${GEN_PACK_LIB}/gen-pack"
gen_pack "${DEFAULT_ARGS[@]}" "$@"

exit 0
Binary file modified test/test_integ_with_git.tbz2
Binary file not shown.
92 changes: 72 additions & 20 deletions test/tests_integ.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@

DIRNAME="$(realpath "$(dirname "$0")")"

setUp() {
export GEN_PACK_LIB="$(realpath "${DIRNAME}/../")"
TESTDIR="${SHUNIT_TMPDIR}/${_shunit_test_}"
mkdir -p "${TESTDIR}"
pushd "${TESTDIR}" >/dev/null
}

teardown() {
unset GEN_PACK_LIB
unset TESTDIR
popd >/dev/null
}

test_integ_default() {
cd "${DIRNAME}/test_integ_default"
cp -r "${DIRNAME}/test_integ_default" .
cd test_integ_default

rm -rf build output

./gen_pack.sh -k

assertTrue "Pack description file missing" "[ -f build/ARM.GenPack.pdsc ]"
Expand All @@ -18,9 +32,9 @@ test_integ_default() {
assertTrue "Header file missing" "[ -f build/inc/test.h ]"
assertTrue "Source file missing" "[ -f build/src/test.c ]"
assertTrue "Pack archive missing" "[ -f output/ARM.GenPack.1.0.1-dev1.pack ]"

assertTrue "Checksum file verification failed" "cd build; sha1sum ARM.GenPack.sha1"

pdsc=$(cat build/ARM.GenPack.pdsc)
assertContains "$pdsc" '<release version="1.0.1-dev1">'
assertContains "$pdsc" '<release version="1.0.0" date="2022-08-04" tag="v1.0.0">'
Expand All @@ -29,12 +43,13 @@ test_integ_default() {
}

test_integ_with_git_release() {
test -d "${DIRNAME}/test_integ_with_git" || tar -xjf "${DIRNAME}/test_integ_with_git.tbz2" -C "${DIRNAME}"
cd "${DIRNAME}/test_integ_with_git"

mkdir -p test_integ_with_git
tar -xjf "${DIRNAME}/test_integ_with_git.tbz2" -C test_integ_with_git
cd test_integ_with_git

git --git-dir=$(pwd)/.git clean -fdxq
git --git-dir=$(pwd)/.git checkout -fq v1.0.0

./gen_pack.sh -k

assertTrue "Pack description file missing" "[ -f build/ARM.GenPack.pdsc ]"
Expand All @@ -46,22 +61,59 @@ test_integ_with_git_release() {
assertTrue "Header file missing" "[ -f build/inc/test.h ]"
assertTrue "Source file missing" "[ -f build/src/test.c ]"
assertTrue "Pack archive missing" "[ -f output/ARM.GenPack.1.0.0.pack ]"

assertTrue "Checksum file verification failed" "cd build; sha1sum ARM.GenPack.sha1"

pdsc=$(cat build/ARM.GenPack.pdsc)
assertContains "$pdsc" '<release version="1.0.0" date="2022-08-04" tag="v1.0.0">'
assertContains "$pdsc" '<release version="1.0.0" date="2022-11-21" tag="v1.0.0">'
assertContains "$pdsc" "Initial release 1.0.0"
assertNotContains "$pdsc" "Active development ..."
}

test_integ_with_git_prerelease() {
mkdir -p test_integ_with_git
tar -xjf "${DIRNAME}/test_integ_with_git.tbz2" -C test_integ_with_git
cd test_integ_with_git

git --git-dir=$(pwd)/.git clean -fdxq
git --git-dir=$(pwd)/.git checkout -fq v1.0.0

$(\
GIT_COMMITTER_NAME="github-actions" \
GIT_COMMITTER_EMAIL="github-actions@github.com" \
GIT_COMMITTER_DATE="2022-08-04T16:00:00Z" \
git tag -m "Active development ..." v1.0.0-dev v1.0.0^ \
)

./gen_pack.sh -k

assertTrue "Pack description file missing" "[ -f build/ARM.GenPack.pdsc ]"
assertTrue "Pack checksum file missing" "[ -f build/ARM.GenPack.sha1 ]"
assertTrue "LICENSE file" "[ -f build/LICENSE ]"
assertTrue "Doc top level index missing" "[ -f build/doc/index.html ]"
assertFalse "Doxyfile found in build" "[ -f build/doc/test.dxy ]"
assertTrue "Doc index file missing" "[ -f build/doc/html/index.html ]"
assertTrue "Header file missing" "[ -f build/inc/test.h ]"
assertTrue "Source file missing" "[ -f build/src/test.c ]"
assertTrue "Pack archive missing" "[ -f output/ARM.GenPack.1.0.0.pack ]"

assertTrue "Checksum file verification failed" "cd build; sha1sum ARM.GenPack.sha1"

pdsc=$(cat build/ARM.GenPack.pdsc)
assertContains "$pdsc" '<release version="1.0.0" date="2022-11-21" tag="v1.0.0">'
assertContains "$pdsc" "Initial release 1.0.0"
assertContains "$pdsc" '<release version="1.0.0-dev" date="2022-08-04" tag="v1.0.0-dev">'
assertContains "$pdsc" "Active development ..."
}

test_integ_with_git_devdrop() {
test -d "${DIRNAME}/test_integ_with_git" || tar -xjf "${DIRNAME}/test_integ_with_git.tbz2" -C "${DIRNAME}"
cd "${DIRNAME}/test_integ_with_git"

mkdir -p test_integ_with_git
tar -xjf "${DIRNAME}/test_integ_with_git.tbz2" -C test_integ_with_git
cd test_integ_with_git

git --git-dir=$(pwd)/.git clean -fdxq
git --git-dir=$(pwd)/.git checkout -fq main

./gen_pack.sh -k

assertTrue "Pack description file missing" "[ -f build/ARM.GenPack.pdsc ]"
Expand All @@ -72,13 +124,13 @@ test_integ_with_git_devdrop() {
assertTrue "Doc index file missing" "[ -f build/doc/html/index.html ]"
assertTrue "Header file missing" "[ -f build/inc/test.h ]"
assertTrue "Source file missing" "[ -f build/src/test.c ]"
assertTrue "Pack archive missing" "[ -f output/ARM.GenPack.1.0.1-dev1+g932aa3d.pack ]"
assertTrue "Pack archive missing" "[ -f output/ARM.GenPack.1.0.1-dev1+g83ce9fd.pack ]"

assertTrue "Checksum file verification failed" "cd build; sha1sum ARM.GenPack.sha1"

pdsc=$(cat build/ARM.GenPack.pdsc)
assertContains "$pdsc" '<release version="1.0.1-dev1+g932aa3d">'
assertContains "$pdsc" '<release version="1.0.0" date="2022-08-04" tag="v1.0.0">'
assertContains "$pdsc" '<release version="1.0.1-dev1+g83ce9fd">'
assertContains "$pdsc" '<release version="1.0.0" date="2022-11-21" tag="v1.0.0">'
assertContains "$pdsc" "Initial release 1.0.0"
assertContains "$pdsc" "Active development ..."
}
Expand Down

0 comments on commit c8a5ef3

Please sign in to comment.