3proxy/.github/workflows/update-version.yml
Vladimir Dubrovin 754ba7115a
Some checks failed
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Has been cancelled
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Has been cancelled
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Has been cancelled
Derive all build timestamps from BUILDDATE
The build date stored in version.h is now the single time source for a
release. Each package workflow converts it to SOURCE_DATE_EPOCH and passes
that into the build containers, the debian changelog entry is stamped from it
rather than from the build clock, and rpmbuild is told to use it as the build
time and to clamp file mtimes to it.

rpm also records the build host, which is a container id and therefore differs
on every run, so pin it as well - otherwise the timestamps alone do not make
the package reproducible.

Rebuilding the same commit now produces byte identical packages, verified for
both formats by building twice and comparing checksums.

In the version workflow the clock is read exactly once, when a new build date
is minted. YEAR3PROXY is derived from the build date instead of being read
separately, so the two cannot straddle a year boundary and a re-run in a later
year no longer rewrites version.h.
2026-08-22 13:53:29 +03:00

95 lines
3.5 KiB
YAML

name: Update version files
on:
push:
paths:
- RELEASE
workflow_dispatch:
permissions:
contents: read
jobs:
version:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Regenerate version files
run: |
RELEASE=$(tr -d ' \t\r\n' < RELEASE)
if [ -z "$RELEASE" ]; then echo "RELEASE is empty"; exit 1; fi
MAJOR=$(echo "$RELEASE" | cut -d . -f 1)
SUBMAJOR=$(echo "$RELEASE" | cut -d . -f 2)
MINOR=$(echo "$RELEASE" | cut -d . -f 3)
SUBMINOR=$(echo "$RELEASE" | cut -d . -f 4)
[ -n "$SUBMAJOR" ] || SUBMAJOR=0
[ -n "$MINOR" ] || MINOR=0
[ -n "$SUBMINOR" ] || SUBMINOR=0
# The build date is minted once per release and then carried in
# version.h, so that rebuilding the same commit yields the same
# version string and the same package names.
OLDRELEASE=$(sed -n 's/^#define VERSION "3proxy-\(.*\)"$/\1/p' src/version.h 2>/dev/null)
OLDBUILDDATE=$(sed -n 's/^#define BUILDDATE "\(.*\)"$/\1/p' src/version.h 2>/dev/null)
if [ "$OLDRELEASE" = "$RELEASE" ] && [ -n "$OLDBUILDDATE" ]; then
BUILDDATE="$OLDBUILDDATE"
else
BUILDDATE=$(date -u +%y%m%d%H%M%S)
fi
echo "release $RELEASE -> $MAJOR $SUBMAJOR $MINOR $SUBMINOR, build date $BUILDDATE"
SOURCE_DATE_EPOCH=$(date -u -d "20${BUILDDATE:0:2}-${BUILDDATE:2:2}-${BUILDDATE:4:2} ${BUILDDATE:6:2}:${BUILDDATE:8:2}:${BUILDDATE:10:2}" +%s)
YEAR=$(date -u -d @$SOURCE_DATE_EPOCH +%Y)
DEBVERSION=$(head -1 debian/changelog | cut -d "(" -f 2 | cut -d ")" -f 1)
if [ "$DEBVERSION" != "$RELEASE-1" ]; then
mv debian/changelog debian/changelog.old
{ echo "3proxy ($RELEASE-1) buster; urgency=medium"
echo ""
echo " *3proxy $RELEASE initial build"
echo ""
echo " -- z3APA3A <3apa3a@3proxy.org> $(date -R -u -d @$SOURCE_DATE_EPOCH)"
echo ""
cat debian/changelog.old
} > debian/changelog
rm -f debian/changelog.old
fi
mv scripts/rh/3proxy.spec scripts/rh/3proxy.spec.old
{ echo "Name: 3proxy"
echo "Version: $RELEASE"
echo "Release: 1%{?dist}"
tail --lines=+4 scripts/rh/3proxy.spec.old
} > scripts/rh/3proxy.spec
rm -f scripts/rh/3proxy.spec.old
{ echo "#ifndef VERSION"
echo "#define VERSION \"3proxy-$RELEASE\""
echo "#endif"
echo "#ifndef BUILDDATE"
echo "#define BUILDDATE \"$BUILDDATE\""
echo "#endif"
echo "#define MAJOR3PROXY $MAJOR"
echo "#define SUBMAJOR3PROXY $SUBMAJOR"
echo "#define MINOR3PROXY $MINOR"
echo "#define SUBMINOR3PROXY $SUBMINOR"
echo "#define RELEASE3PROXY \"3proxy-$RELEASE(\" BUILDDATE \")\\0\""
echo "#ifndef YEAR3PROXY"
echo "#define YEAR3PROXY \"$YEAR\""
echo "#endif"
} > src/version.h
- name: Commit
run: |
if [ -z "$(git status --porcelain debian/changelog scripts/rh/3proxy.spec src/version.h)" ]; then
echo "version files already up to date"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add debian/changelog scripts/rh/3proxy.spec src/version.h
git commit -m "Update version files for $(tr -d ' \t\r\n' < RELEASE)"
git push