Skip to content

Commit 78b034d

Browse files
authored
Merge pull request #12 from HarperFast/chris/derive-version-from-version-h
Derive prebuild version from version.h, not the release tag
2 parents 6cf7e3e + f5cad14 commit 78b034d

1 file changed

Lines changed: 53 additions & 8 deletions

File tree

.github/workflows/build.yml

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,60 @@ jobs:
2222
should_build: ${{ steps.check-build.outputs.should_build }}
2323
version: ${{ steps.latest-rocksdb.outputs.version }}
2424
release_version: ${{ steps.check-build.outputs.release_version }}
25+
mismatch_note: ${{ steps.latest-rocksdb.outputs.mismatch_note }}
2526
steps:
2627
- name: Get latest RocksDB release
2728
id: latest-rocksdb
2829
shell: bash
2930
run: |
31+
set -euo pipefail
3032
REQUESTED="${{ inputs.rocksdb_version }}"
3133
if [[ -n "$REQUESTED" ]]; then
32-
LATEST="${REQUESTED#v}"
34+
TAG="${REQUESTED#v}"
3335
else
3436
URL="https://api.github.com/repos/facebook/rocksdb/releases/latest"
35-
LATEST=$(curl -s -L -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" -X GET "$URL" | jq -r '.tag_name' | tr -d 'v')
37+
TAG=$(curl -s -L -H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" -X GET "$URL" | jq -r '.tag_name' | tr -d 'v')
3638
fi
37-
echo "Latest RocksDB release: $LATEST"
38-
echo "version=$LATEST" >> $GITHUB_OUTPUT
39+
echo "Latest RocksDB release tag: v$TAG"
40+
41+
# Derive the published version from the bundled version.h, not the tag name.
42+
# version.h is what the compiled library (and rocksdb-js) actually reports, so
43+
# it is our source of truth. Upstream has shipped tags whose name disagrees with
44+
# version.h (e.g. the v11.8.0 tag actually contains 11.8.1).
45+
VERSION_H_URL="https://raw.githubusercontent.com/facebook/rocksdb/v${TAG}/include/rocksdb/version.h"
46+
VERSION_H="$(curl -sfL "$VERSION_H_URL")"
47+
MAJOR="$(printf '%s\n' "$VERSION_H" | sed -n 's/^#define ROCKSDB_MAJOR \([0-9][0-9]*\).*/\1/p')"
48+
MINOR="$(printf '%s\n' "$VERSION_H" | sed -n 's/^#define ROCKSDB_MINOR \([0-9][0-9]*\).*/\1/p')"
49+
PATCH="$(printf '%s\n' "$VERSION_H" | sed -n 's/^#define ROCKSDB_PATCH \([0-9][0-9]*\).*/\1/p')"
50+
if [[ -z "$MAJOR" || -z "$MINOR" || -z "$PATCH" ]]; then
51+
echo "Failed to parse version.h from $VERSION_H_URL" >&2
52+
printf '%s\n' "$VERSION_H" >&2
53+
exit 1
54+
fi
55+
VERSION="${MAJOR}.${MINOR}.${PATCH}"
56+
echo "Version from version.h: $VERSION"
57+
58+
MISMATCH_NOTE=""
59+
if [[ "$VERSION" != "$TAG" ]]; then
60+
MISMATCH_NOTE="**⚠️ Version mismatch:** upstream RocksDB tag v${TAG} does not match its bundled version.h (${VERSION}). This prebuild was built from the v${TAG} tag but is published as v${VERSION} to match the version the compiled library reports."
61+
echo "::warning title=RocksDB version mismatch::tag v${TAG} != version.h ${VERSION}; publishing as v${VERSION}"
62+
echo "=================================================================="
63+
echo " RocksDB VERSION MISMATCH"
64+
echo " upstream tag : v${TAG}"
65+
echo " version.h : ${VERSION}"
66+
echo " Publishing as v${VERSION} (version.h is the source of truth)."
67+
echo "=================================================================="
68+
fi
69+
70+
# version = the upstream tag (used to download the source and link to the
71+
# upstream release); version_h = the version we publish as.
72+
echo "version=$TAG" >> "$GITHUB_OUTPUT"
73+
echo "version_h=$VERSION" >> "$GITHUB_OUTPUT"
74+
{
75+
echo "mismatch_note<<MMEOF"
76+
echo "$MISMATCH_NOTE"
77+
echo "MMEOF"
78+
} >> "$GITHUB_OUTPUT"
3979
4080
- name: Get latest prebuild
4181
id: latest-prebuild
@@ -50,7 +90,10 @@ jobs:
5090
id: check-build
5191
shell: bash
5292
run: |
53-
ROCKSDB_VERSION="${{ steps.latest-rocksdb.outputs.version }}"
93+
# Compare and publish using the version.h-derived version; the tag is only
94+
# the download locator.
95+
ROCKSDB_VERSION="${{ steps.latest-rocksdb.outputs.version_h }}"
96+
TAG_VERSION="${{ steps.latest-rocksdb.outputs.version }}"
5497
REVISION="${{ inputs.prerelease_revision }}"
5598
SHOULD_BUILD=false
5699
@@ -61,7 +104,7 @@ jobs:
61104
fi
62105
RELEASE_VERSION="${ROCKSDB_VERSION}-${REVISION}"
63106
SHOULD_BUILD=true
64-
echo "Building RocksDB v$ROCKSDB_VERSION prerelease as v$RELEASE_VERSION"
107+
echo "Building RocksDB v$ROCKSDB_VERSION (tag v$TAG_VERSION) prerelease as v$RELEASE_VERSION"
65108
elif [[ "$ROCKSDB_VERSION" != "${{ steps.latest-prebuild.outputs.version }}" ]]; then
66109
RELEASE_VERSION="$ROCKSDB_VERSION"
67110
SHOULD_BUILD=true
@@ -330,9 +373,11 @@ jobs:
330373
with:
331374
files: artifacts/**/*.tar.xz
332375
body: |
333-
Automated prebuilds for RocksDB v${{ needs.check.outputs.version }}.
376+
Automated prebuilds for RocksDB v${{ needs.check.outputs.release_version }}.
377+
378+
${{ needs.check.outputs.mismatch_note }}
334379
335-
Release notes: https://github.com/facebook/rocksdb/releases/tag/v${{ needs.check.outputs.version }}
380+
Built from upstream tag v${{ needs.check.outputs.version }} — release notes: https://github.com/facebook/rocksdb/releases/tag/v${{ needs.check.outputs.version }}
336381
name: RocksDB v${{ needs.check.outputs.release_version }}
337382
tag_name: v${{ needs.check.outputs.release_version }}
338383
prerelease: ${{ inputs.prerelease_revision != '' }}

0 commit comments

Comments
 (0)