From 2ea84fb8c469409fab8dcd3b678214ed974a6818 Mon Sep 17 00:00:00 2001 From: AndrewQuijano Date: Sun, 27 Oct 2024 21:34:00 -0400 Subject: [PATCH] Dynamically set the version of Panda Debian package in Control file based on the release version from GitHub --- .github/workflows/publish_docker.yml | 2 +- panda/debian/.gitignore | 3 ++- panda/debian/Dockerfile | 8 +++++++- panda/debian/control | 2 +- panda/debian/setup.sh | 22 +++++++++++++++++++--- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/.github/workflows/publish_docker.yml b/.github/workflows/publish_docker.yml index 25db2724909..b5ed42f700c 100644 --- a/.github/workflows/publish_docker.yml +++ b/.github/workflows/publish_docker.yml @@ -46,7 +46,7 @@ jobs: - name: Build package working-directory: panda/debian - run: ./setup.sh Ubuntu ${{ matrix.ubuntu_version }} + run: ./setup.sh Ubuntu ${{ matrix.ubuntu_version }} ${{ needs.create_release.outputs.v-version }} - name: Upload wheel and debian packages to release uses: softprops/action-gh-release@v2 diff --git a/panda/debian/.gitignore b/panda/debian/.gitignore index 7bbf39a4c32..b6c92bba57e 100644 --- a/panda/debian/.gitignore +++ b/panda/debian/.gitignore @@ -1 +1,2 @@ -panda.deb +*.deb +*.whl diff --git a/panda/debian/Dockerfile b/panda/debian/Dockerfile index 8d45e844161..bb988c1b85c 100644 --- a/panda/debian/Dockerfile +++ b/panda/debian/Dockerfile @@ -1,7 +1,9 @@ +ARG PACKAGE_VERSION="" + # First run the main Dockerfile to build the base image and name it panda. Then we run here # to generate a debian package -FROM debian:buster-slim +FROM debian:bookworm-slim # Install necessary tools for packaging RUN apt-get -qq update && \ @@ -21,6 +23,10 @@ COPY --from=panda /usr/local/share/panda /package-root/usr/local/share/panda # Create DEBIAN directory and control file COPY control /package-root/DEBIAN/control +# Update control file with the correct version +ARG PACKAGE_VERSION +RUN sed -i "s/^Version:.*/Version: ${PACKAGE_VERSION}/" /package-root/DEBIAN/control + # Update control file with dependencies # Build time. We only select dependencies that are not commented out or blank RUN dependencies=$(grep '^[a-zA-Z]' /tmp/build_dep.txt | tr '\n' ',' | sed 's/,,\+/,/g'| sed 's/,$//') && \ diff --git a/panda/debian/control b/panda/debian/control index c5457a4457d..0b103dd8af3 100644 --- a/panda/debian/control +++ b/panda/debian/control @@ -1,5 +1,5 @@ Package: pandare -Version: 3.1.0 +Version: Architecture: all BUILD_DEPENDS_LIST DEPENDS_LIST diff --git a/panda/debian/setup.sh b/panda/debian/setup.sh index b28dc85c7e2..58fd78cfa19 100755 --- a/panda/debian/setup.sh +++ b/panda/debian/setup.sh @@ -25,17 +25,33 @@ if [[ $# -eq 1 ]]; then echo " To build a package for current Ubuntu version:" echo " $0" echo " To build a package for a specific OS/version (only Ubuntu supported for now):" - echo " $0 " + echo " $0 " exit 1 fi if [[ $# -eq 2 ]]; then version=$2 - else version=$(lsb_release -r | awk '{print $2}') fi +if [[ $# -eq 3 ]]; then + tag_version=$3 +else + tag_version='v3.1.0' +fi + +# Remove leading 'v' if present, e. g. v1.5.1 -> 1.5.1 +if [[ "$tag_version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + tag_version=${tag_version:1} +fi + +# Check if the version follows the format X.Y.Z, e. g. 1.5.1 or 1.9.1 +if [[ ! "$tag_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "ERROR: Version must be in the format X.Y.Z, provided tag version: $tag_version" + exit 1 +fi + # Check if the given version is supported if [[ ! -f "../dependencies/ubuntu_${version}_base.txt" ]]; then echo "ERROR: Ubuntu ${version} is not supported, no dependencies file found" @@ -53,7 +69,7 @@ docker run --rm -v $(pwd):/out panda bash -c "cp /panda/panda/python/core/dist/* DOCKER_BUILDKIT=1 docker build --target panda -t panda --build-arg BASE_IMAGE="ubuntu:${version}" ../.. # Now build the packager container from that -docker build -t packager . +docker build -t packager --build-arg PACKAGE_VERSION="${tag_version}" . # Copy deb file out of container to host docker run --rm -v $(pwd):/out packager bash -c "cp /pandare.deb /out"