Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bake in tagged version in src release tar. #16

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]*\)-.*/\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-v${BANT_VERSION}
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-v${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
17 changes: 14 additions & 3 deletions bant/bant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,23 @@ int getopt(int, char *const *, const char *); // NOLINT
#define RED "\033[1;31m"
#define RESET "\033[0m"

// print version coming from BANT_BUILD_VERSION that is generated by
// by workspace status.
// If that didn't happen because we're built as part of being a MODULE.bazel
// dependency, use secondary source or fallback to "unknown"
static int print_version() {
// If BUILD_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)