Skip to content

Commit a8c2a38

Browse files
authored
Derive version tag directly from ffc.h (#19)
1 parent 5f617b2 commit a8c2a38

File tree

6 files changed

+45
-9
lines changed

6 files changed

+45
-9
lines changed

.github/workflows/release.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ jobs:
1818
id: version
1919
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
2020

21+
- name: Verify tag and single-header are in sync
22+
run: |
23+
expected_tag="$(make -s print_version_tag)"
24+
if [ "${GITHUB_REF_NAME}" != "${expected_tag}" ]; then
25+
echo "error: tag ${GITHUB_REF_NAME} does not match src/api.h version ${expected_tag}"
26+
exit 1
27+
fi
28+
29+
make ffc.h
30+
git diff --exit-code ffc.h
31+
2132
- name: Generate checksum
2233
run: sha256sum ffc.h > ffc.h.sha256
2334

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: test example exhaustive fetch-supplemental-data supplemental_tests
1+
.PHONY: test example exhaustive fetch-supplemental-data supplemental_tests print_version_tag
22

33
# Detect linux and define _DEFAULT_SOURCE if so
44
UNAME_S := $(shell uname -s)
@@ -17,6 +17,12 @@ out/example: ffc.h example.c | out
1717
example: out/example
1818
./out/example
1919

20+
out/print_version_tag: tools/print_version_tag.c src/api.h | out
21+
clang $(CLANG_FLAGS) -I. tools/print_version_tag.c -o out/print_version_tag
22+
23+
print_version_tag: out/print_version_tag
24+
./out/print_version_tag
25+
2026
out:
2127
mkdir -p out
2228

@@ -61,4 +67,3 @@ exhaustive: out/test_exhaustive_runner
6167

6268
out/test_exhaustive_runner: ffc.h test_src/test_exhaustive.c | out
6369
clang $(CLANG_FLAGS) -pthread -I. -Itest_src test_src/test_exhaustive.c -o out/test_exhaustive_runner -lm
64-

ffc.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,14 @@ extern "C" {
115115

116116
#define FFC_VERSION_YEAR 26
117117
#define FFC_VERSION_MONTH 03
118-
#define FFC_VERSION_BUILD 02
118+
#define FFC_VERSION_BUILD 03
119119
#define FFC_VERSION ((FFC_VERSION_YEAR << 16) | (FFC_VERSION_MONTH << 8) | (FFC_VERSION_BUILD))
120+
#define FFC_VERSION_STRINGIFY_(x) #x
121+
#define FFC_VERSION_STRINGIFY(x) FFC_VERSION_STRINGIFY_(x)
122+
#define FFC_VERSION_STRING \
123+
FFC_VERSION_STRINGIFY(FFC_VERSION_YEAR) "." \
124+
FFC_VERSION_STRINGIFY(FFC_VERSION_MONTH) "." \
125+
FFC_VERSION_STRINGIFY(FFC_VERSION_BUILD)
120126

121127
#include <stddef.h>
122128
#include <stdint.h>

src/api.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33

44
#define FFC_VERSION_YEAR 26
55
#define FFC_VERSION_MONTH 03
6-
#define FFC_VERSION_BUILD 02
6+
#define FFC_VERSION_BUILD 03
77
#define FFC_VERSION ((FFC_VERSION_YEAR << 16) | (FFC_VERSION_MONTH << 8) | (FFC_VERSION_BUILD))
8+
#define FFC_VERSION_STRINGIFY_(x) #x
9+
#define FFC_VERSION_STRINGIFY(x) FFC_VERSION_STRINGIFY_(x)
10+
#define FFC_VERSION_STRING \
11+
FFC_VERSION_STRINGIFY(FFC_VERSION_YEAR) "." \
12+
FFC_VERSION_STRINGIFY(FFC_VERSION_MONTH) "." \
13+
FFC_VERSION_STRINGIFY(FFC_VERSION_BUILD)
814

915
#include <stddef.h>
1016
#include <stdint.h>

tools/print_version_tag.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "src/api.h"
2+
3+
#include <stdio.h>
4+
5+
int main(void) {
6+
printf("v" FFC_VERSION_STRING "\n");
7+
return 0;
8+
}

tools/release.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
set -e
22
set -x
33

4-
if [ -z "$1" ]; then
5-
echo "usage: $0 <n>"
4+
if [ "$#" -ne 0 ]; then
5+
echo "usage: $0"
66
exit 1
77
fi
88

9-
year="$(date +%y)"
10-
month="$(date +%m)"
11-
tag="v${year}.${month}.$1"
9+
make ffc.h
10+
git diff --exit-code ffc.h
11+
tag="$(make -s print_version_tag)"
1212

1313
echo "releasing version ${tag}"
1414
git tag -a "${tag}" -m "${tag}"

0 commit comments

Comments
 (0)