From a12ce5bc6652fb67492d9b580d475937e73a7d76 Mon Sep 17 00:00:00 2001
From: vtexier <vit@free.fr>
Date: Sat, 15 Jun 2019 11:34:30 +0200
Subject: [PATCH] [enh] #96 fix gitlab-ci errors adding make commands for build
 and deploy

Add requirements_deploy.txt file
Update build and deploy commands in README accordingly
---
 .gitlab-ci.yml          | 34 +++++++++++++++-------------------
 Makefile                | 14 +++++++++++++-
 README.rst              | 18 ++++++++++--------
 requirements_deploy.txt |  3 +++
 4 files changed, 41 insertions(+), 28 deletions(-)
 create mode 100644 requirements_deploy.txt

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index e53823be..64cfcaa3 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -17,7 +17,7 @@ image: registry.duniter.org/docker/python3/duniterpy-builder:0.0.4
     GIT_STRATEGY: none
   tags:
     - github
-  script:
+  after_script:
     - rm -rf ./*
     - rm -rf .git
     - git clone --mirror $CI_REPOSITORY_URL .
@@ -48,16 +48,6 @@ image: registry.duniter.org/docker/python3/duniterpy-builder:0.0.4
       - setup.py
       - tests/**/*.py
 
-.release_pip: &release_pip
-  script:
-    - pip install twine
-    - twine upload dist/* --username duniter --password $PYPI_PASSWORD
-
-.release_pip_test: &release_pip_test
-  script:
-    - pip install twine
-    - twine upload dist/* --username duniter --password $PYPI_PASSWORD --repository-url https://test.pypi.org/legacy/
-
 # TASKS
 format:
   <<: *pyenv
@@ -88,26 +78,32 @@ check:
     - make mypy
     - make pylint
 
-build: &build
+build:
   <<: *pyenv
   <<: *changes
   stage: build
   script:
     - pip install -r requirements.txt
-    - pip install wheel
-    - python setup.py sdist bdist_wheel
+    - pip install -r requirements_deploy.txt
+    - make build
 
 releases:
   <<: *pyenv
-  <<: *build
-  <<: *release_pip
   <<: *push_to_github
   stage: release
   when: manual
+  script:
+    - pip install -r requirements.txt
+    - pip install -r requirements_deploy.txt
+    - make build
+    - make deploy PYPI_PASSWORD=${PYPI_PASSWORD}
 
 release_test:
   <<: *pyenv
-  <<: *build
-  <<: *release_pip_test
   stage: release
-  when: manual
\ No newline at end of file
+  when: manual
+  script:
+    - pip install -r requirements.txt
+    - pip install -r requirements_deploy.txt
+    - make build
+    - make deploy_test PYPI_PASSWORD=${PYPI_PASSWORD}
diff --git a/Makefile b/Makefile
index 962854a8..34b25197 100644
--- a/Makefile
+++ b/Makefile
@@ -33,4 +33,16 @@ check-format:
 format:
 	black duniterpy
 	black tests
-	black examples
\ No newline at end of file
+	black examples
+
+# build a whell package in dist folder
+build:
+	python setup.py sdist bdist_wheel
+
+# upload on PyPi repository
+deploy:
+	twine upload dist/* --username duniter --password ${PYPI_PASSWORD}
+
+# upload on PyPi test repository
+deploy_test:
+	twine upload dist/* --username duniter --password ${PYPI_PASSWORD} --repository-url https://test.pypi.org/legacy/
diff --git a/README.rst b/README.rst
index 2dc5427f..c57b61b3 100644
--- a/README.rst
+++ b/README.rst
@@ -105,21 +105,23 @@ Packaging and deploy
 Pypi
 ++++
 
-In the development pyenv environment, install the following tools::
+In the development pyenv environment, install the build and deploy tools::
 
-    pip install --upgrade pip setuptools wheel
+    pip install --upgrade -r requirements_deploy.txt
 
-    pip install twine
-
-Change the version number (semantic version number)::
+Change and commit and tag the new version number (semantic version number)::
 
     ./release.sh 0.42.3
 
 Build the Pypi package in the ``dist`` folder::
 
-    python setup.py sdist bdist_wheel
+    make build
+
+Deploy the package on the Pypi test repository (use a space before make to not keep command with password in shell history)::
+
+    [SPACE]make deploy_test PYPI_PASSWORD=xxxx
 
-Deploy the package on the Pypi repository::
+Deploy the package on the Pypi repository (use a space before make to not keep command with password in shell history)::
 
-    twine upload dist/*
+    [SPACE]make deploy PYPI_PASSWORD=xxxx
 
diff --git a/requirements_deploy.txt b/requirements_deploy.txt
new file mode 100644
index 00000000..ba996edc
--- /dev/null
+++ b/requirements_deploy.txt
@@ -0,0 +1,3 @@
+setuptools
+wheel
+twine
\ No newline at end of file
-- 
GitLab