From ff77d222e4c21d73a9d6c6b0cab583977e86ee6b Mon Sep 17 00:00:00 2001 From: Vladimir Dubrovin <3proxy@3proxy.ru> Date: Sat, 22 Aug 2026 13:34:35 +0300 Subject: [PATCH] Regenerate version files from RELEASE in a workflow The version files were derived from RELEASE by a script kept outside this repository, so bumping RELEASE and updating src/version.h, the spec version and debian/changelog were separate manual steps. Do it in a workflow triggered by a change to RELEASE. It writes the same content the external script produced, verified byte for byte against the current tree. The build date is now minted once, when RELEASE changes, and stored in version.h rather than taken from the clock of whichever build is running. The package workflows read it from there, so rebuilding a commit produces the same version string and the same package file names. Re-running the workflow without a RELEASE change keeps the existing build date and makes no commit. --- .github/workflows/build-rpm-arm64.yml | 4 +- .github/workflows/build-rpm-armhf.yml | 4 +- .github/workflows/build-rpm-x86-64.yml | 4 +- .github/workflows/update-version.yml | 93 ++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/update-version.yml diff --git a/.github/workflows/build-rpm-arm64.yml b/.github/workflows/build-rpm-arm64.yml index faa1770..6a87ae3 100644 --- a/.github/workflows/build-rpm-arm64.yml +++ b/.github/workflows/build-rpm-arm64.yml @@ -26,7 +26,9 @@ jobs: run: | pwd echo "RELEASE=$(cat RELEASE)" >> $GITHUB_ENV - echo "VERSION=$(date +%y%m%d%H%M%S)" >> $GITHUB_ENV + BUILDDATE=$(sed -n 's/^#define BUILDDATE "\(.*\)"$/\1/p' src/version.h) + [ -n "$BUILDDATE" ] || BUILDDATE=$(date +%y%m%d%H%M%S) + echo "VERSION=$BUILDDATE" >> $GITHUB_ENV - name: echo env run: echo "release $RELEASE version $VERSION" - name: Linux libraries diff --git a/.github/workflows/build-rpm-armhf.yml b/.github/workflows/build-rpm-armhf.yml index ac579ad..fbac061 100644 --- a/.github/workflows/build-rpm-armhf.yml +++ b/.github/workflows/build-rpm-armhf.yml @@ -26,7 +26,9 @@ jobs: run: | pwd echo "RELEASE=$(cat RELEASE)" >> $GITHUB_ENV - echo "VERSION=$(date +%y%m%d%H%M%S)" >> $GITHUB_ENV + BUILDDATE=$(sed -n 's/^#define BUILDDATE "\(.*\)"$/\1/p' src/version.h) + [ -n "$BUILDDATE" ] || BUILDDATE=$(date +%y%m%d%H%M%S) + echo "VERSION=$BUILDDATE" >> $GITHUB_ENV - name: configure deb env run: | mkdir ~/debian diff --git a/.github/workflows/build-rpm-x86-64.yml b/.github/workflows/build-rpm-x86-64.yml index fd855e1..a8336bd 100644 --- a/.github/workflows/build-rpm-x86-64.yml +++ b/.github/workflows/build-rpm-x86-64.yml @@ -26,7 +26,9 @@ jobs: run: | pwd echo "RELEASE=$(cat RELEASE)" >> $GITHUB_ENV - echo "VERSION=$(date +%y%m%d%H%M%S)" >> $GITHUB_ENV + BUILDDATE=$(sed -n 's/^#define BUILDDATE "\(.*\)"$/\1/p' src/version.h) + [ -n "$BUILDDATE" ] || BUILDDATE=$(date +%y%m%d%H%M%S) + echo "VERSION=$BUILDDATE" >> $GITHUB_ENV - name: echo env run: echo "release $RELEASE version $VERSION" - name: Linux libraries diff --git a/.github/workflows/update-version.yml b/.github/workflows/update-version.yml new file mode 100644 index 0000000..8d1939f --- /dev/null +++ b/.github/workflows/update-version.yml @@ -0,0 +1,93 @@ +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 + YEAR=$(date +%Y) + 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 +%y%m%d%H%M%S) + fi + echo "release $RELEASE -> $MAJOR $SUBMAJOR $MINOR $SUBMINOR, build date $BUILDDATE" + + 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)" + 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