From 5ae1296a484fd52cde0e8981d6f2cb85d4b30aa5 Mon Sep 17 00:00:00 2001
From: Luke Marlin <luke.marlin@viacesi.fr>
Date: Sat, 13 Mar 2021 19:09:05 +0100
Subject: [PATCH] Add CI

The CI builds, tags, create a release and a generic pages and finally
publishes to Gitlab pages automatically.
For development branches, it will only build.
---
 .gitlab-ci.yml | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++
 publishconf.py |  3 +++
 2 files changed, 60 insertions(+)
 create mode 100644 .gitlab-ci.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..ab3711c
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,57 @@
+stages:
+  - build
+  - package
+  - release
+  - deploy
+
+build-job:
+  image: python:slim
+  stage: build
+  rules:
+    - if: '$CI_COMMIT_BRANCH'
+  script:
+    - mkdir -p /usr/share/man/man1 # Because of https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=863199
+    - apt-get update && apt-get install -y plantuml graphviz
+    - pip install -r requirements.txt
+    - pelican content -s publishconf.py -e OUTPUT_PATH=public/
+  artifacts:
+    paths:
+      - public/
+    name: build
+    expire_in: 7 days
+package-job:
+  stage: package
+  tags: [redshift] # Used to prevent runner 1000i100 from picking up this stage
+  image: curlimages/curl:latest
+  script:
+    - PACKAGE_VERSION="$(date +%Y.%m).${CI_PIPELINE_IID}"
+    - PACKAGE_REGISTRY_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/releases/${PACKAGE_VERSION}"
+    - echo 'Creating generic package'
+    - cd public/
+    - tar cvf $HOME/website.tar *
+    - ls -al
+    - 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file $HOME/website.tar ${PACKAGE_REGISTRY_URL}/website.tar'
+  rules:
+    - if: '$CI_COMMIT_BRANCH == "master"'
+release-job:
+  stage: release
+  tags: [redshift] # Used to prevent runner 1000i100 from picking up this stage
+  image: registry.gitlab.com/gitlab-org/release-cli:latest
+  rules:
+    - if: '$CI_COMMIT_BRANCH == "master"'
+  script:
+    - PACKAGE_VERSION="$(date +%Y.%m).${CI_PIPELINE_IID}"
+    - PACKAGE_REGISTRY_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/releases/${PACKAGE_VERSION}"
+    - echo 'Creating release'
+    - release-cli create --name "$PACKAGE_VERSION" --tag-name $PACKAGE_VERSION --assets-link "{\"name\":\"wesbite.tar\",\"url\":\"$PACKAGE_REGISTRY_URL/website.tar\"}"
+
+pages:
+  stage: deploy
+  tags: [redshift]
+  rules:
+    - if: '$CI_COMMIT_BRANCH == "master"'
+  script:
+    - echo "Publishing to Gitlab pages"
+  artifacts:
+    paths:
+      - public/
\ No newline at end of file
diff --git a/publishconf.py b/publishconf.py
index 1532565..aa1c2a6 100644
--- a/publishconf.py
+++ b/publishconf.py
@@ -1,5 +1,8 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*- #
+import sys
+sys.path.append('.')
+
 from pelicanconf import *
 
 SITEURL = u'https://duniter.org/en'
-- 
GitLab