From 5378bd3e9202d13bbed1774b960eea9591340f26 Mon Sep 17 00:00:00 2001 From: FAURE Adrien <adrien.faure@inria.fr> Date: Thu, 24 Mar 2022 12:23:54 +0000 Subject: [PATCH] ci for debian packaging --- .gitlab-ci.yml | 67 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c81b13c..7eda19d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,9 @@ -default: +stages: + - test + - debian-build + - release + +.default: image: python:${PYTHON_VERSION}-slim-${DEBIAN_VERSION} before_script: - python --version @@ -7,6 +12,8 @@ default: pytest: stage: test + image: !reference [.default,image] + before_script: !reference [.default,before_script] script: - pytest --cov-report=term-missing --junitxml=pytest.xml coverage: '/^TOTAL.+ ([1-9]?[0-9]%|100%)$/' @@ -21,3 +28,61 @@ pytest: DEBIAN_VERSION: ['stretch', 'buster', 'bullseye'] - PYTHON_VERSION: ['3.8', '3.9', '3.10'] DEBIAN_VERSION: ['buster', 'bullseye'] + +create-debian-packages: + image: debian:$DEBIAN_VERSION + stage: debian-build + rules: + - if: $CI_COMMIT_BRANCH =~ /^debian.*$/ + - if: $CI_COMMIT_TAG =~ /^debian\/.*$/ + variables: + DEBIAN_VERSION: "bookworm" + DEBIAN_FRONTEND: "noninteractive" + DEBIAN_PRIORITY: "critical" + DEBCONF_NOWARNINGS: "yes" + before_script: + - apt-get update + - apt-get -y install git + - apt-get -y install dpkg-dev fakeroot lintian python3-sphinx python-all debhelper po-debconf dh-make python3-all python3-setuptools dh-python python3-sphinx-rtd-theme tree + # Get the tag name, or the commit + - COMMIT_OR_TAG="${CI_COMMIT_TAG:-$CI_COMMIT_SHA}" + # Remove / from the tagname as it is used in file name later + - export COMMIT_OR_TAG=$(echo $COMMIT_OR_TAG | sed 's#/#-#g') + # Save this variable for the release job + - echo "COMMIT_OR_TAG=$COMMIT_OR_TAG" >> job.env + script: + # Building the debian package. + - dpkg-buildpackage -b -rfakeroot -us -uc + - mv ../*.deb ../*.buildinfo ../*.changes . && tar cvf procset-${COMMIT_OR_TAG}.tar.gz *.deb *.buildinfo *.changes + after_script: + - echo "JOB_ID=$CI_JOB_ID" >> job.env + artifacts: + paths: + # Since I can't use the variable create in *_script here, I use a wildcard + - procset-*.tar.gz + expire_in: never + reports: + dotenv: job.env + +# Release job for the debian package, it relies on the artifacts of create-debian-packages. +release-for-debian: + stage: release + rules: + - if: $CI_COMMIT_TAG =~ /^debian\/.*$/ + needs: + # We want the test to pass + - job: pytest + - job: create-debian-packages + artifacts: true + image: registry.gitlab.com/gitlab-org/release-cli:latest + script: + - echo 'running release_job for $CI_COMMIT_TAG' + release: + name: 'Release $CI_COMMIT_TAG' + description: 'Created using the release-cli' + tag_name: '$CI_COMMIT_TAG' + ref: '$CI_COMMIT_TAG' + assets: + links: + - name: procset-${COMMIT_OR_TAG}.tar.gz + url: https://gitlab.inria.fr/adfaure/procset.py/-/jobs/${JOB_ID}/artifacts/raw/procset-${COMMIT_OR_TAG}.tar.gz -- GitLab