Skip to content

Commit 7f9eef1

Browse files
idoqoademidoff
andauthored
PMM-13881: Use VERSION file for exporter version tag (#1094)
* set up VERSION file * add new line * bump version described in version file * simply version checks Co-authored-by: Alex Demidoff <[email protected]> --------- Co-authored-by: Alex Demidoff <[email protected]>
1 parent e1951c5 commit 7f9eef1

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed

.github/workflows/version-check.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Version Check
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
push:
7+
branches: [ main ]
8+
9+
jobs:
10+
version-check:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Get version from VERSION file
20+
id: file-version
21+
run: |
22+
if [ -f "VERSION" ]; then
23+
FILE_VERSION=$(cat VERSION | tr -d '\n\r ')
24+
echo "version=$FILE_VERSION" >> $GITHUB_OUTPUT
25+
echo "VERSION file contains: $FILE_VERSION"
26+
else
27+
echo "VERSION file not found!"
28+
exit 1
29+
fi
30+
31+
- name: Get version from git tag
32+
id: git-version
33+
run: |
34+
GIT_VERSION=$(git describe --tags --abbrev=0 --always)
35+
echo "version=$GIT_VERSION" >> $GITHUB_OUTPUT
36+
echo "Git tag version: $GIT_VERSION"
37+
38+
- name: Install semver comparison tool
39+
run: |
40+
npm install -g semver
41+
42+
- name: Compare versions
43+
run: |
44+
FILE_VERSION="${{ steps.file-version.outputs.version }}"
45+
GIT_VERSION="${{ steps.git-version.outputs.version }}"
46+
47+
echo "Comparing versions:"
48+
echo " VERSION file: $FILE_VERSION"
49+
echo " Git tag: $GIT_VERSION"
50+
51+
# Remove 'v' prefix if present for comparison
52+
FILE_VERSION_CLEAN=$(echo "$FILE_VERSION" | sed 's/^v//')
53+
GIT_VERSION_CLEAN=$(echo "$GIT_VERSION" | sed 's/^v//')
54+
55+
# Check if versions are valid semver
56+
if ! semver "$FILE_VERSION_CLEAN" >/dev/null 2>&1; then
57+
echo "ERROR: VERSION file contains invalid semantic version: $FILE_VERSION"
58+
exit 1
59+
fi
60+
61+
if ! semver "$GIT_VERSION_CLEAN" >/dev/null 2>&1; then
62+
echo "ERROR: Git tag contains invalid semantic version: $GIT_VERSION"
63+
exit 1
64+
fi
65+
66+
# Compare versions: -1 if first < second, 0 if equal, 1 if first > second
67+
if [ ! $(semver -r ">=$GIT_VERSION_CLEAN" "$FILE_VERSION_CLEAN") ]; then
68+
echo "VERSION file ($FILE_VERSION) is behind git tag ($GIT_VERSION)"
69+
echo "The VERSION file must be ahead of or equal to the latest git tag."
70+
exit 1
71+
else
72+
echo "VERSION file ($FILE_VERSION) is ahead of or equal to git tag ($GIT_VERSION)"
73+
fi

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ GO_TEST_EXTRA ?=
66
GO_TEST_COVER_PROFILE ?= cover.out
77
GO_TEST_CODECOV ?=
88

9-
BUILD ?= $(shell date +%FT%T%z)
9+
BUILD_DATE ?= $(shell date +%FT%T%z)
1010
GOVERSION ?= $(shell go version | cut -d " " -f3)
11-
COMPONENT_VERSION ?= $(shell git describe --tags --abbrev=0 --always)
11+
COMPONENT_VERSION ?= $(shell cat VERSION)
1212
COMPONENT_BRANCH ?= $(shell git describe --always --contains --all)
1313
PMM_RELEASE_FULLCOMMIT ?= $(shell git rev-parse HEAD)
14-
GO_BUILD_LDFLAGS = -X main.version=${COMPONENT_VERSION} -X main.buildDate=${BUILD} -X main.commit=${PMM_RELEASE_FULLCOMMIT} -X main.Branch=${COMPONENT_BRANCH} -X main.GoVersion=${GOVERSION} -s -w
14+
GO_BUILD_LDFLAGS = -X main.version=${COMPONENT_VERSION} -X main.buildDate=${BUILD_DATE} -X main.commit=${PMM_RELEASE_FULLCOMMIT} -X main.Branch=${COMPONENT_BRANCH} -X main.GoVersion=${GOVERSION} -s -w
1515
NAME ?= mongodb_exporter
1616
REPO ?= percona/$(NAME)
1717
GORELEASER_FLAGS ?=

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.45.0

0 commit comments

Comments
 (0)