From ec6f739ed789ba65084ff78c74717bc2abd36c61 Mon Sep 17 00:00:00 2001
From: Joseph Weston <joseph.weston08@gmail.com>
Date: Tue, 28 Mar 2017 12:45:44 +0200
Subject: [PATCH] CI: build and optionally upload conda package in a single job

We build conda packages on 'master' (on all forks) by default.
Builds for branches may be triggered manually.
---
 .gitlab-ci.yml | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5213857d..2e9536a6 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -3,7 +3,6 @@ image: kwant/testing
 stages:
   - build
   - test
-  - package
   - deploy
 
 variables:
@@ -82,11 +81,8 @@ check for broken links in doc:
   allow_failure: true
 
 
-create conda package:
-  stage: package
-  only:
-    - master
-    - /^.*-build$/
+.conda-template: &conda_job
+  stage: deploy
   image: condaforge/linux-anvil
   script:
     - yum install -y devtoolset-2-gcc-gfortran
@@ -95,18 +91,26 @@ create conda package:
     - conda build --python 3.5 conda-recipes/kwant-dev
     - conda build --python 3.6 conda-recipes/kwant-dev
     - mv /opt/conda/conda-bld/linux-64/kwant-dev*.tar.bz2 .
+    - if [ ! -z $ANACONDA_TOKEN ]; then anaconda --token=$ANACONDA_TOKEN upload --force kwant-dev*tar.bz2; fi
   artifacts:
     paths:
       - kwant-dev*.tar.bz2
     expire_in: 1 month
 
-upload conda package:
-  stage: deploy
+
+# build on master always
+build and upload conda package:
+  <<: *conda_job
   only:
-    - master@kwant/kwant
-  image: condaforge/linux-anvil
-  script:
-    - anaconda --token=$ANACONDA_TOKEN upload --force kwant-dev*tar.bz2
+    - master
+
+
+# manual triggers for branches other than master possible
+build and upload conda package (manual):
+  <<: *conda_job
+  except:
+    - master
+  when: manual
 
 
 upload coverage:
-- 
GitLab