From 4d7cecf9ad2fcf0b9da03786071d9aceed9dbff9 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 9 Oct 2023 12:21:35 +0200 Subject: [PATCH] Enhance 'make dist', add GitHub release workflow - a new file VERSION is the only place storing the FLINT version - generate src/flint.h from src/flint.h.in so we can insert the version - revise `make dist` to call a helper script `dev/make_dist.sh`, which creates all relevant archives, which include files generated by autoconf - add GitHub Workflows to tests creation and usability of these archives on various conditions --- .github/workflows/release.yml | 146 ++++++++++++++++++++++++++++++++++ .gitignore | 1 + CMakeLists.txt | 5 +- Makefile.in | 7 +- VERSION | 1 + bootstrap.sh | 1 + configure.ac | 17 ++-- dev/make_dist.sh | 53 ++++++++++++ doc/source/conf.py | 18 ++--- src/{flint.h => flint.h.in} | 8 +- 10 files changed, 231 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 VERSION create mode 100755 dev/make_dist.sh rename src/{flint.h => flint.h.in} (98%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..6a94bf144c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,146 @@ +# This workflow takes care of creating release archives for the +# Flint distribution. It is run for all PR and branch pushes as usual, +# but also on tags whose name starts with `vX.Y` with X, Y numbers +# (the idea is to use v1.2.3 or v1.2.3-beta3) +# +# For builds triggered by a tag, the tag is turned into a GitHub release and +# the produced archives are attached to that. +name: "Wrap releases" + +on: + workflow_dispatch: + pull_request: + push: + tags: + - v[1-9]+.[0-9]+.[0-9] # allow v1.2.3 + - v[1-9]+.[0-9]+.[0-9]-* # allow v1.2.3-beta3 etc. + branches: + - trunk + - flint-* + schedule: + # Every day at 3:33 AM UTC + - cron: '33 3 * * *' + +concurrency: + # group by workflow and ref; the last slightly strange component ensures that for pull + # requests, we limit to 1 concurrent job, but for the trunk branch we don't + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.ref != 'refs/heads/trunk' || github.run_number }} + # Cancel intermediate builds, but only if it is a pull request build. + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} + +jobs: + make-archive: + runs-on: ubuntu-latest + outputs: + get-version: ${{ steps.get-version.outputs.version }} + + steps: + - uses: actions/checkout@v4 + + - name: "Setup" + run: | + sudo apt-get install -y autoconf libtool-bin + autoconf --version + libtool --version + + - name: "Record FLINT version" + id: get-version + run: | + # special treatment for tags: these are used for actual releases, so + # we force the version in the VERSION file and in the tag to match + if ${{ startsWith(github.ref, 'refs/tags/v') }} ; then + version=${GITHUB_REF#refs/tags/v} + else + version=$(cat VERSION) + fi + echo "version=${version}" + echo "version=${version}" >> $GITHUB_OUTPUT + + - name: "Bootstrap" + run: | + ./bootstrap.sh + + - name: "Create source archive" + run: dev/make_dist.sh ${{ steps.get-version.outputs.version }} + + - name: "Upload source archive as artifact" + uses: actions/upload-artifact@v3 + with: + if-no-files-found: error + name: flint + path: flint-${{ steps.get-version.outputs.version }}.* + retention-days: 1 + + test-archive: + needs: make-archive + runs-on: ubuntu-latest + env: + FLINT_VERSION: ${{ needs.make-archive.outputs.get-version }} + MAKE: "make -j --output-sync=target" + TESTCFLAGS: "-Wall -O1" + steps: + - name: "Download archive from previous job" + uses: actions/download-artifact@v3 + with: + name: flint + + - name: "Setup" + run: | + sudo apt-get install -y libgmp-dev + sudo apt-get install -y libmpfr-dev + # now *remove* autotools to verify we can build with out it + sudo apt-get remove -y autoconf + sudo apt-get remove -y automake + sudo apt-get remove -y libtool-bin + + - name: "Extract" + run: | + tar -xf flint-$FLINT_VERSION.tar.gz + mv flint-$FLINT_VERSION flint # to simplify code + + - name: "Configure" + run: | + cd flint + # *no* call to bootstrap.sh ! + ./configure + + - name: "Compile library" + run: | + cd flint + $MAKE + ldd libflint.so + + - name: "Compile tests" + run: | + cd flint + export FLINT_TEST_MULTIPLIER=0.1 + $MAKE tests + + - name: "Check" + run: | + cd flint + export FLINT_TEST_MULTIPLIER=0.1 + $MAKE check + + upload-archive: + needs: [make-archive, test-archive] + runs-on: ubuntu-latest + if: ${{ startsWith(github.ref, 'refs/tags/v') }} + steps: + - name: "Download archive from previous job" + uses: actions/download-artifact@v3 + with: + name: flint + + - name: Release + uses: softprops/action-gh-release@v1 + with: + fail_on_unmatched_files: true + files: | + flint-${{ needs.make-archive.outputs.get-version }}.tar.gz + flint-${{ needs.make-archive.outputs.get-version }}.tar.xz + flint-${{ needs.make-archive.outputs.get-version }}.zip + +# TODO: we could / should perhaps also test `make install` ? +# TODO: also trigger a documentation build and upload the result? +# TODO: if desired, we could e.g. also upload the archive to a server via scp diff --git a/.gitignore b/.gitignore index e9aedcaa6f..5aa6e0df6b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ src/fmpz/fmpz.c src/config.h src/config.h.in src/fft_tuning.h +src/flint.h src/flint-config.h build/ config/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 59b2539851..461667f10c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,7 +211,10 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/CMake/cmake_config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/flint-config.h ) - +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/flint.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/src/flint.h +) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/src/fmpz/link/fmpz_${MEMORY_MANAGER}.c ${CMAKE_CURRENT_SOURCE_DIR}/src/fmpz/fmpz.c diff --git a/Makefile.in b/Makefile.in index f3a5a68894..5464086b10 100644 --- a/Makefile.in +++ b/Makefile.in @@ -16,9 +16,7 @@ ABS_FLINT_DIR:='$(patsubst %/,%, $(dir $(abspath $(lastword $(MAKEFILE_LIST))))) ABS_SRC_DIR:=$(ABS_FLINT_DIR)/$(SRC_DIR) ABS_BUILD_DIR:=$(ABS_FLINT_DIR)/$(SRC_DIR) -FLINT_MAJOR:=@FLINT_MAJOR@ -FLINT_MINOR:=@FLINT_MINOR@ -FLINT_PATCH:=@FLINT_PATCH@ +FLINT_VERSION:=@FLINT_VERSION@ FLINT_MAJOR_SO:=@FLINT_MAJOR_SO@ FLINT_MINOR_SO:=@FLINT_MINOR_SO@ FLINT_PATCH_SO:=@FLINT_PATCH_SO@ @@ -765,8 +763,7 @@ endif ################################################################################ dist: - git archive --format tar --prefix flint-$(FLINT_MAJOR).$(FLINT_MINOR).$(FLINT_PATCH)/ origin/flint-$(FLINT_MAJOR).$(FLINT_MINOR) > ../flint-$(FLINT_MAJOR).$(FLINT_MINOR).$(FLINT_PATCH).tar; gzip ../flint-$(FLINT_MAJOR).$(FLINT_MINOR).$(FLINT_PATCH).tar - git archive --format zip --prefix flint-$(FLINT_MAJOR).$(FLINT_MINOR).$(FLINT_PATCH)/ origin/flint-$(FLINT_MAJOR).$(FLINT_MINOR) > ../flint-$(FLINT_MAJOR).$(FLINT_MINOR).$(FLINT_PATCH).zip + dev/make_dist.sh $(FLINT_VERSION) ################################################################################ # debugging diff --git a/VERSION b/VERSION new file mode 100644 index 0000000000..2468aa9eae --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +3.0.0-dev diff --git a/bootstrap.sh b/bootstrap.sh index c6311d4e3d..8d8bc67af7 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,4 +1,5 @@ #!/bin/sh +set -e rm -rf autom4te.cache diff --git a/configure.ac b/configure.ac index 7137370a4b..8a81c83860 100644 --- a/configure.ac +++ b/configure.ac @@ -29,7 +29,7 @@ AH_TOP(FLINT_COPYRIGHT_C) AC_PREREQ(2.59) -define(FLINT_VERSION,[3.0.0-dev]) +m4_define(FLINT_VERSION,m4_include([VERSION])) AC_INIT(FLINT, FLINT_VERSION, [https://github.com/flintlib/flint/issues/], flint, [https://flintlib.org/]) AC_CONFIG_AUX_DIR([config]) @@ -68,9 +68,6 @@ AC_LANG(C) # 3.0.0 => 18.0.0 # NOTE: This must be after AC_INIT -FLINT_MAJOR=3 -FLINT_MINOR=0 -FLINT_PATCH=0 FLINT_MAJOR_SO=18 FLINT_MINOR_SO=0 FLINT_PATCH_SO=0 @@ -1006,6 +1003,16 @@ fi # substitutions and definitions ################################################################################ +AC_SUBST([FLINT_VERSION], FLINT_VERSION) + +# split version into major/minor/patch using POSIX variable substitutions +tail=FLINT_VERSION +FLINT_MAJOR=${tail%%.*} +tail=${tail#*.} +FLINT_MINOR=${tail%%.*} +tail=${tail#*.} +FLINT_PATCH=${tail%-*} + AC_SUBST(FLINT_MAJOR) AC_SUBST(FLINT_MINOR) AC_SUBST(FLINT_PATCH) @@ -1119,7 +1126,7 @@ fi # epilog ################################################################################ -AC_CONFIG_FILES([Makefile flint.pc]) +AC_CONFIG_FILES([Makefile flint.pc src/flint.h]) AC_OUTPUT dnl Shorten the original help message diff --git a/dev/make_dist.sh b/dev/make_dist.sh new file mode 100755 index 0000000000..b2c4e27a02 --- /dev/null +++ b/dev/make_dist.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +# +# This script is called by `make dist` and `.github/workflows/release.yml` +# in order to create a flint release tarball. It must be called from within +# the root directory of the flint source tree. +# +set -ex + +# first argument: the FLINT version in the form 1.2.3 or 1.2.3-something +# if not given, uses the version in the VERSION file +flint_version=$1 + +# second, optional argument: the git revision from which to make the +# release; default is to use the HEAD commit. +git_ref=${2:-HEAD} + +# prefix used for the content of the tarball, and also the basename of +# the final archive. +archive_prefix="flint-$flint_version" + +echo "Exporting from git" +git archive --format tar.gz --prefix "${archive_prefix}/" ${git_ref} > ${archive_prefix}.tar.gz + +echo "Extracting" +tar -xf ${archive_prefix}.tar.gz +rm ${archive_prefix}.tar.gz + +echo "Adding / patching / removing files" +# copy some files that should be included in the distribution archive +cp -r config ${archive_prefix}/ +cp configure ${archive_prefix}/ +cp src/config.h.in ${archive_prefix}/src/ + +# remove some things we don't want to install +cd ${archive_prefix} +rm -rf .[a-z]* # no dot files +rm -rf dev + +# update VERSION file +echo $flint_version > VERSION + +# return to top directory +cd .. + +# create the source archives +echo "Create .tar.gz" +tar -cvzf ${archive_prefix}.tar.gz ${archive_prefix} + +echo "Create .tar.xz" +tar -cJf ${archive_prefix}.tar.xz ${archive_prefix} + +echo "Create .zip" +zip -9 -r ${archive_prefix}.zip ${archive_prefix} diff --git a/doc/source/conf.py b/doc/source/conf.py index f84d103aae..66f0cc8adf 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -25,18 +25,14 @@ copyright = u'2009-2023, The Flint development team' author = u'The Flint development team' -# The short X.Y version -version = u'' - - -for _line in open("../../configure.ac").readlines(): - if _line.startswith("define(FLINT_VERSION,"): - _i1 = _line.find('[') - _i2 = _line.find(']', _i1 + 1) - version = _line[_i1+1:_i2] - # The full version, including alpha/beta/rc tags -release = version +with open("../../VERSION") as f: + release = f.read().rstrip() + +# The short X.Y version +# (for now identical to "release", we may wish to chop of alpha/beta/rc tags +# and maybe even drop the patch level?) +version = release # -- General configuration --------------------------------------------------- diff --git a/src/flint.h b/src/flint.h.in similarity index 98% rename from src/flint.h rename to src/flint.h.in index 16de54d88b..11746bb73a 100644 --- a/src/flint.h +++ b/src/flint.h.in @@ -91,10 +91,10 @@ extern "C" { /* flint version number */ -#define __FLINT_VERSION 3 -#define __FLINT_VERSION_MINOR 0 -#define __FLINT_VERSION_PATCHLEVEL 0 -#define FLINT_VERSION "3.0.0-dev" +#define __FLINT_VERSION @FLINT_MAJOR@ +#define __FLINT_VERSION_MINOR @FLINT_MINOR@ +#define __FLINT_VERSION_PATCHLEVEL @FLINT_PATCH@ +#define FLINT_VERSION "@FLINT_VERSION@" #define __FLINT_RELEASE_NUM(a,b,c) ((a)*10000 + (b)*100 + (c)) #define __FLINT_RELEASE __FLINT_RELEASE_NUM(__FLINT_VERSION, __FLINT_VERSION_MINOR, __FLINT_VERSION_PATCHLEVEL)