From 59025a14e07ad6e8be35e2c4040f46d963e15dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Taymans?= Date: Tue, 11 Jul 2023 16:52:23 +0200 Subject: [PATCH] [ADD] build and release in CI This will produce the following behaviour: When a commit with a title like "Bump to version x.y.z" is committed to main branch (either by merging a merge request or by pushing it directly to the main branch), a build of the project is triggered and the result is pushed on PyPI. Also a release on the github project is created with the version of the program as title and the content of the commit message as description. This will help deploying release of oow. It will also warn followers that a new version is released by a notification if they choose to. PYPI_USER and PYPI_TOKEN are value set on the gitlab settings of the project and can only be viewed by maintainers. --- .gitlab-ci.yml | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f454544..2fb50b3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,8 @@ stages: - lint - test + - build + - release pre-commit: stage: lint @@ -41,3 +43,45 @@ pytest: tests/cli_08_estimate_workload_test.py tests/cli_20_install_from_csv_test.py tests/cli_21_generate_module_analysis_test.py + +build: + stage: build + image: python:latest + rules: + # Do not run this job when a tag is created manually + - if: $CI_COMMIT_TAG + when: never + # Run this job when commits are pushed or merged to the default branch + # and the commit message contains "Bump to version" + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE =~ /^Bump to version.+/ + script: + - pip install poetry + - poetry --version + - poetry build + - poetry publish --username $PYPI_USER --password $PYPI_TOKEN + - echo "VERSION=$(poetry version --short)" >> variables.env + artifacts: + reports: + # Use artifacts:reports:dotenv to expose the variables to other jobs + dotenv: variables.env + +release: + stage: release + image: registry.gitlab.com/gitlab-org/release-cli:latest + needs: + - job: build + artifacts: true + rules: + # Do not run this job when a tag is created manually + - if: $CI_COMMIT_TAG + when: never + # Run this job when commits are pushed or merged to the default branch + # and the commit message contains "Bump to version" + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE =~ /^Bump to version.+/ + script: + - echo "running release_job for $VERSION" + release: + name: "$VERSION" + description: "$CI_COMMIT_DESCRIPTION" + tag_name: "$VERSION" + ref: "$CI_COMMIT_SHA"