From 5d05704b0293a6ad2c1685be8434fe28804d42d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20Loipf=C3=BChrer?= <michael.loipfuehrer@stusta.de>
Date: Sat, 24 Jul 2021 15:54:47 +0200
Subject: [PATCH] push releases to pypi

---
 .gitlab-ci.yml       | 19 ++++++++++++++++---
 README.md            |  8 ++++++++
 wahlfang/__init__.py |  2 +-
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 78b447a..10399fd 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -7,8 +7,8 @@ stages:
   - release
 
 variables:
-    PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
-    PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic"
+  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
+  PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic"
 
 all_tests:
   stage: test
@@ -105,4 +105,17 @@ release_job:
         - name: "wahlfang-${CI_COMMIT_TAG}.tar.gz"
           url: "${PACKAGE_REGISTRY_URL}/${CI_COMMIT_TAG}/wahlfang.tar.gz"
 
-# TODO: automatically push to pypi.org when generating a release
\ No newline at end of file
+publish_job:
+  stage: release
+  needs:
+    - job: package
+      artifacts: true
+  rules:
+    - if: $CI_COMMIT_TAG # only run when we publish a new tag
+  before_script:
+    - pip3 install virtualenv
+    - virtualenv -q .venv
+    - source .venv/bin/activate
+    - pip install -U twine
+  script:
+    - python -m twine upload dist/*
\ No newline at end of file
diff --git a/README.md b/README.md
index e94e86b..56b6396 100644
--- a/README.md
+++ b/README.md
@@ -53,6 +53,14 @@ $ python3 wahlfang/manage.py migrate
 ```
 Don't forget to add the new migration file to git. If the CI pipeline fails this is most likely the reason for it.
 
+## Releasing
+The release process is automated in the gitlab ci.
+
+To make a new release bump the package version number in `wahlfang.__init__.py` and tag the commit with the same version
+number. The CI will then build the package, publish it as a gitlab release and push it to pypi.
+
+The pypi credentials must be set in the gitlab CI settings via the env variables `TWINE_USERNAME` and `TWINE_PASSWORD`.
+
 ## Development References
 
 - Django 3: https://docs.djangoproject.com/en/3.2/
diff --git a/wahlfang/__init__.py b/wahlfang/__init__.py
index cd7ca49..a6221b3 100644
--- a/wahlfang/__init__.py
+++ b/wahlfang/__init__.py
@@ -1 +1 @@
-__version__ = '1.0.1'
+__version__ = '1.0.2'
-- 
GitLab