Skip to content

Commit 6617195

Browse files
committed
ci/package_core: generate SemVer-compatible core version
Add the get_core_version.sh script to generate a SemVer-compatible version number for the core, based on Git tags. Update package_core.sh and gen_package_index_json.sh to use it. Signed-off-by: Luca Burelli <[email protected]>
1 parent 90751a1 commit 6617195

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

.github/workflows/package_core.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
yes | ./extra/bootstrap.sh -o=--filter=tree:0
3636
echo "CORE_HASH=$(git describe --always)" >> "$GITHUB_ENV"
3737
echo "ALL_BOARD_DATA=$(extra/get_board_details.sh | jq -c 'sort_by(.variant)')" >> "$GITHUB_ENV"
38+
echo "## Building \`$(extra/get_core_version.sh)\`" >> "$GITHUB_STEP_SUMMARY"
3839
3940
- name: Map output packages
4041
# needs the above env vars to be usable

extra/gen_package_index_json.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fi
1616

1717
JSON_TEMPLATE="extra/zephyr-core-template.json"
1818
cat $JSON_TEMPLATE | sed \
19-
-e "s/__CORE_TAG__/$CORE_TAG/" \
19+
-e "s/__CORE_TAG__/$(extra/get_core_version.sh)/" \
2020
-e "s/__ARTIFACT_FILE__/$(basename $ARTIFACT_FILE)/" \
2121
-e "s/__ARTIFACT_HASH__/$(sha256sum $ARTIFACT_FILE | awk '{print $1}')/" \
2222
-e "s/__ARTIFACT_SIZE__/$(stat -c %s $ARTIFACT_FILE)/" | jq .

extra/get_core_version.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# This script generates a SemVer-compatible version number based on Git tags.
4+
#
5+
# If the current commit is tagged, it returns that version. If not, it
6+
# generates a version string based on the next patch number and the current
7+
# commit hash.
8+
#
9+
# If the tag is a simple "<maj>.<min>.<patch>", git describe will output:
10+
#
11+
# <maj>.<min>.<patch>-<number-of-commits-since-tag>-g<commit-hash-dirty>
12+
#
13+
# The regexp splits the patch number, awk converts the tokens to:
14+
#
15+
# <maj>.<min>.<next-patch>-0.dev+<commit-hash-dirty>
16+
#
17+
# If the tag refers to a pre-release, like "<maj>.<min>.<patch>-<extra-stuff>",
18+
# sed will output a total of 4 arguments and the format of the final awk output
19+
# will be:
20+
#
21+
# <maj>.<min>.<patch>-<extra-stuff>-0.dev+<commit-hash-dirty>
22+
#
23+
# These are among the lowest possible SemVer versions greater than the last
24+
# tagged version.
25+
#
26+
# If there are no tags at all (for example when run in a fork etc), it defaults
27+
# to "9.9.9-<date>+<commit-hash-dirty>".
28+
29+
VERSION=$(git describe --tags --exact-match 2>/dev/null)
30+
if [ -z "$VERSION" ]; then
31+
VERSION=$(git describe --tags --dirty 2>/dev/null |
32+
sed 's/\.\([[:digit:]]\+\)\(-.*\)*-[[:digit:]]\+-g/ \1 \2 /' |
33+
awk '{ if (NF==3) { print $1 "." ($2+1) "-0.dev+" $3 } else { print $1 "." $2 $3 "-0.dev+" $4 }}')
34+
if [ -z "$VERSION" ]; then
35+
VERSION="9.9.9-$(date '+%Y%m%d-%H%M%S')+$(git describe --always --dirty)"
36+
fi
37+
fi
38+
echo $VERSION

extra/package_core.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ OUTPUT_FILE=${2:-distrib/${PACKAGE}-${VERSION}.tar.bz2}
1818

1919
# create a temporary platform.txt file with the correct version
2020
TEMP_PLATFORM=$(mktemp -p . | sed 's/\.\///')
21-
sed -e "s/^version=.*/version=${VERSION}/" platform.txt > ${TEMP_PLATFORM}
21+
cat platform.txt > ${TEMP_PLATFORM}
22+
sed -ie "s/^version=.*/version=$(extra/get_core_version.sh)/" ${TEMP_PLATFORM}
2223

2324
declutter_file() {
2425
[ -f "$1" ] || return 0

0 commit comments

Comments
 (0)