Skip to content

Commit

Permalink
Bake in tagged version in src release tar.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzeller committed Jan 15, 2025
1 parent 05a8270 commit b318f56
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 20 deletions.
53 changes: 38 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,22 @@ jobs:
|| ( cat bant_clang-tidy.out ; exit 1)
# TODO: can this be done _after_ the tagging had taken place ?
BuildStaticBinary:
ReleasableArtifacts:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Extract Version
run: |
# Version number: current tag dot number of commits after tagging.
# If at exactly a tag, that will be left as-is
BANT_VERSION=$(git describe --match=v* 2>/dev/null \
| sed 's/v\([^-]*\)-\([0-9]*\)-.*/v\1-\2/')
echo BANT_VERSION=${BANT_VERSION} >> $GITHUB_ENV
- name: Create Cache Timestamp
id: cache_timestamp
uses: nanzm/[email protected]
Expand All @@ -171,33 +179,48 @@ jobs:
key: bazelcache_release_${{ steps.cache_timestamp.outputs.time }}
restore-keys: bazelcache_release_

- name: Build
- name: Build Source Tar
run: |
OUT_SRC=bant-${BANT_VERSION}-src
echo "OUT_SRC=${OUT_SRC}" >> $GITHUB_ENV
mkdir ../${OUT_SRC}
cp -r . ../${OUT_SRC}
# Bake in version number into source
sed -i 's/#undef BUILD_RELEASE_TAG/#define BUILD_RELEASE_TAG "${BANT_VERSION}"/' ../${OUT_SRC}/bant/bant.cc
tar --exclude=.git -cvzf ${OUT_SRC}.tar.gz ../${OUT_SRC}
- name: Build Static Binary
run: |
export CC=gcc-13
export CXX=g++-13
bazel build --noshow_progress -c opt --//bant:create_static_linked_executables bant:bant
bazel-bin/bant/bant -V # Print version
# Version number: current tag dot number of commits after tagging.
# If at exactly a tag, that will be left as-is
VERSION=$(git describe --match=v* 2>/dev/null \
| sed 's/v\([^-]*\)-\([0-9]*\)-.*/v\1-\2/')
OUT=bant-${VERSION}-linux-static-x86_64
echo "OUT=${OUT}" >> $GITHUB_ENV
OUT_BIN=bant-${BANT_VERSION}-linux-static-x86_64
echo "OUT_BIN=${OUT_BIN}" >> $GITHUB_ENV
mkdir -p "${OUT}/bin"
install bazel-bin/bant/bant "${OUT}/bin"
strip "${OUT}/bin/bant"
mkdir -p "${OUT_BIN}/bin"
install bazel-bin/bant/bant "${OUT_BIN}/bin"
strip "${OUT_BIN}/bin/bant"
# We need to pack it with with tar to retain proper unix permissions.
# Unfortunately, github then re-packs the result into a *.zip archive.
tar cvzf "${OUT}.tar.gz" ${OUT}
tar cvzf "${OUT_BIN}.tar.gz" ${OUT_BIN}
- name: Upload Source tar
uses: actions/upload-artifact@v4
with:
name: ${{ env.OUT_SRC }}
path: ${{ env.OUT_SRC }}.tar.gz

- name: Upload artifact
- name: Upload Binary tar
uses: actions/upload-artifact@v4
with:
name: ${{ env.OUT }}
path: ${{ env.OUT }}.tar.gz
name: ${{ env.OUT_BIN }}
path: ${{ env.OUT_BIN }}.tar.gz

release-tagging:
name: Version Tagging
Expand Down
18 changes: 14 additions & 4 deletions bant/bant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,22 @@ int getopt(int, char *const *, const char *); // NOLINT
#define RED "\033[1;31m"
#define RESET "\033[0m"

// If BUILD_VERSION could not be determined for whatever reason
// print version coming from BANT_BUILD_VERSION that is generated by
// by workspace status. If that didn't happen use secondary source or fallback
// to "unknown"
static int print_version() {
// If BBUILD_VERSION could not be determined for whatever reason
#ifndef BANT_BUILD_VERSION
#define BANT_BUILD_VERSION "-unknown (> 0.1.10)"
#endif

static int print_version() {
// undef might be replaced with #define when building release tar.
#undef BUILD_RELEASE_TAG

#ifdef BUILD_RELEASE_TAG
#define BANT_BUILD_VERSION BUILD_RELEASE_TAG
#else
#define BANT_BUILD_VERSION "(unknown)"
#endif
#endif
fprintf(stderr,
"bant v%s <http://bant.build/>\n"
"Copyright (c) 2024 Henner Zeller. "
Expand Down
3 changes: 2 additions & 1 deletion scripts/run-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

CLANG_FORMAT="${CLANG_FORMAT:-clang-format}"
"${CLANG_FORMAT}" -i $(find bant/ -name "*.h" -o -name "*.cc")
buildifier -lint=fix MODULE.bazel $(find . -name BUILD)
# for now, no -lint=fix as that is version dependent
buildifier MODULE.bazel $(find . -name BUILD)

0 comments on commit b318f56

Please sign in to comment.