From 82695d0ac3d0f1c9f7576e09b5b6bb65f654b62e Mon Sep 17 00:00:00 2001
From: Moul <moul@moul.re>
Date: Tue, 17 Dec 2024 16:23:54 +0100
Subject: [PATCH] CI: Introduce website stage (#433)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

trigger job only on default branch

`htmlcov` is necessary at the root of the repository
to build the website with the coverage in

Push on `pages` branch with an access token
set in CI/CD variables

The access token has to be renew every year,
since it’s the maximum lifespan of an access token

Access token has to be created on a project basis with
`repository_write` checked and Developer role

https://www.benjaminrancourt.ca/how-to-push-to-a-git-repository-from-a-gitlab-ci-pipeline/
https://stackoverflow.com/questions/51716044
https://stackoverflow.com/questions/25409700
https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html
---
 .gitlab-ci.yml | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index b58aa828..98030dc2 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,7 +2,7 @@ stages:
   - checks
   - tests
   - package
-  - coverage
+  - website
 
 variables:
   DOCKER_IMAGE: "registry.duniter.org/docker/python3/poetry"
@@ -216,14 +216,18 @@ release:
     tag_name: "$CI_COMMIT_TAG"
     description: "$CI_COMMIT_TAG"
 
-pages:
-  extends: .changes
+website:
+  stage: website
   needs: ["tests:3.12:cov"]
+  variables:
+    RELEASE: "0.12"
   rules:
-    - if: $CI_COMMIT_BRANCH == "main"
-  stage: coverage
-  script: mv cov_html/ public/
-  artifacts:
-    paths:
-      - public
-    expire_in: 2 days
+    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
+  script:
+    - poetry install --only docs
+    - git fetch origin pages --depth=1
+    - git config user.name $GITLAB_USER_NAME
+    - git config user.email $GITLAB_USER_EMAIL
+    - poetry run mike deploy $RELEASE
+    - git remote set-url origin "https://${TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
+    - git push origin pages
-- 
GitLab