Skip to content

Update run-clang-tidy-cached. #228

Update run-clang-tidy-cached.

Update run-clang-tidy-cached. #228

Workflow file for this run

name: ci
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
Test:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create Cache Timestamp
id: cache_timestamp
uses: nanzm/[email protected]
with:
format: 'YYYY-MM-DD-HH-mm-ss'
- name: Mount bazel cache
uses: actions/cache@v4
with:
path: "~/.cache/bazel"
key: bazelcache_test_${{ steps.cache_timestamp.outputs.time }}
restore-keys: bazelcache_test_
- name: Test
run: |
export CC=gcc-13
export CXX=g++-13
bazel test --noshow_progress --keep_going ...
MacOsBuild:
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Test
run: |
bazel test --noshow_progress --keep_going ...
- name: Build
run: |
bazel build --noshow_progress -c opt bant:bant
bazel-bin/bant/bant -V # Print version
# TODO: package ?
CodeFormatting:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Dependencies
run: |
go install github.com/bazelbuild/buildtools/buildifier@latest
echo "PATH=$PATH:$(go env GOPATH)/bin/" >> $GITHUB_ENV
- name: Run formatting style check
run: |
clang-format-17 --version
CLANG_FORMAT=clang-format-17 scripts/run-format.sh
git diff > /tmp/format-diff
if [ -s "/tmp/format-diff" ]; then
echo "Difference to optimal formatting"
cat /tmp/format-diff
echo
echo "=================== To Fix ==========================="
echo "Run scripts/run-format.sh"
echo "then"
echo " git commit -a --amend"
echo " git push -f"
exit 1
fi
RunBantOnBant:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build Project genrules
run: |
# Genrules for bant to see every file.
bazel build //bant:version-header
- name: Get Bant
run: |
# TODO: provide this as action where we simply say with version=...
VERSION="v0.1.6"
STATIC_VERSION="bant-${VERSION}-linux-static-x86_64"
wget "https://github.com/hzeller/bant/releases/download/${VERSION}/${STATIC_VERSION}.tar.gz"
tar xvzf "${STATIC_VERSION}.tar.gz"
mkdir -p bin
ln -sf ../"${STATIC_VERSION}/bin/bant" bin/
bin/bant -V
- name: Run bant on bant
run: |
bin/bant dwyu ...
ClangTidy:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Dependencies
run: |
sudo apt-get install clang-tidy-18
- name: Create Cache Timestamp
id: cache_timestamp
uses: nanzm/[email protected]
with:
format: 'YYYY-MM-DD-HH-mm-ss'
- name: Mount clang-tidy cache
uses: actions/cache@v4
with:
path: |
~/.cache/clang-tidy
~/.cache/bazel
key: clang-tidy-cache_${{ steps.cache_timestamp.outputs.time }}
restore-keys: clang-tidy-cache_
- name: Build Compilation DB
run: |
scripts/make-compilation-db.sh
- name: Run clang-tidy
run: |
clang-tidy-18 --version
CLANG_TIDY=clang-tidy-18 scripts/run-clang-tidy-cached.cc \
|| ( cat bant_clang-tidy.out ; exit 1)
# TODO: can this be done _after_ the tagging had taken place ?
BuildStaticBinary:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create Cache Timestamp
id: cache_timestamp
uses: nanzm/[email protected]
with:
format: 'YYYY-MM-DD-HH-mm-ss'
- name: Mount bazel cache
uses: actions/cache@v4
with:
path: "~/.cache/bazel"
key: bazelcache_release_${{ steps.cache_timestamp.outputs.time }}
restore-keys: bazelcache_release_
- name: Build
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
mkdir -p "${OUT}/bin"
install bazel-bin/bant/bant "${OUT}/bin"
strip "${OUT}/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}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.OUT }}
path: ${{ env.OUT }}.tar.gz
release-tagging:
name: Version Tagging
runs-on: ubuntu-24.04
if: ${{github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/main')}}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Tag with MODULES.bazel version if not already.
run: |
version_from_module_bazel() {
git annotate -l MODULE.bazel \
| awk '/module/ { in_module=1; }
/version/ { if (in_module) { print $0; nextfile; } }' \
| sed 's/\(^[0-9a-f]*\).*version[ ]*=[ ]*"\([0-9.]*\)".*/\1 \2/p;d'
}
git config --local user.name "Development Bot"
git config --local user.email "[email protected]"
# We want to tag whenever the version in MODULE.bazel changes.
# So extract the hash of when the current version was entered.
read TAG_HASH TAG_VERSION <<<$(version_from_module_bazel)
echo "Bant Version v${TAG_VERSION} at hash ${TAG_HASH}"
# If this is the first time we see this tag: apply.
if [ -z "$(git tag -l "v${TAG_VERSION}")" ]; then
git tag -a "v${TAG_VERSION}" ${TAG_HASH} -m "Update to v${TAG_VERSION}"
git push origin "v${TAG_VERSION}"
else
echo "Tag already applied"
fi