CI/release: populate git info (#12247)

This commit is contained in:
Mihai Fufezan 2025-11-09 22:50:56 +02:00 committed by GitHub
parent 0bd11d5eb9
commit 2931184921
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,20 +8,37 @@ on:
jobs:
source-tarball:
runs-on: ubuntu-latest
container:
image: archlinux
steps:
- name: Checkout repository actions
uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v5
with:
sparse-checkout: .github/actions
fetch-depth: 0
submodules: recursive
- name: Setup base
uses: ./.github/actions/setup_base
- name: Generate version
- name: Populate git info in version.h.in
run: |
cmake -S . -B /tmp/build
git fetch --tags --unshallow || true
COMMIT_HASH=$(git rev-parse HEAD)
BRANCH="${GITHUB_REF_NAME:-$(git rev-parse --abbrev-ref HEAD)}"
COMMIT_MSG=$(git show -s --format=%s | sed 's/[&/]/\\&/g')
COMMIT_DATE=$(git show -s --format=%cd --date=local)
GIT_DIRTY=$(git diff-index --quiet HEAD -- && echo "clean" || echo "dirty")
GIT_TAG=$(git describe --tags --always || echo "unknown")
GIT_COMMITS=$(git rev-list --count HEAD)
echo "Branch: $BRANCH"
echo "Tag: $GIT_TAG"
sed -i \
-e "s|@GIT_COMMIT_HASH@|$COMMIT_HASH|" \
-e "s|@GIT_BRANCH@|$BRANCH|" \
-e "s|@GIT_COMMIT_MESSAGE@|$COMMIT_MSG|" \
-e "s|@GIT_COMMIT_DATE@|$COMMIT_DATE|" \
-e "s|@GIT_DIRTY@|$GIT_DIRTY|" \
-e "s|@GIT_TAG@|$GIT_TAG|" \
-e "s|@GIT_COMMITS@|$GIT_COMMITS|" \
src/version.h.in
- name: Create tarball with submodules
id: tar