From 226df041c35d743518221a53edf6e389e78160c9 Mon Sep 17 00:00:00 2001
From: Kwangjin Lee <k.lee-5@student.tudelft.nl>
Date: Fri, 23 Aug 2024 16:00:40 +0200
Subject: [PATCH] Update 2 files

- /build-page.sh
- /.gitlab-ci.yml
---
 .gitlab-ci.yml | 14 ++++++++++----
 build-page.sh  | 23 ++++-------------------
 2 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1757416..28de565 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -22,13 +22,19 @@ build-page:
     - |
       if [ "$CI_COMMIT_BRANCH" == "publish" ]; then
         ./build-page.sh "/" true
-      else
+      elif [ "$CI_COMMIT_BRANCH" == "main" ]; then
         ./build-page.sh "/draft" false
+      else
+        echo "Branch $CI_COMMIT_BRANCH is not configured for building."
+        exit 1
       fi
   artifacts:
     paths:
       - public
-
+  rules:
+    - if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "publish"
+    - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "publish"
+      when: always
 
 deploy-draft:
   stage: deploy
@@ -37,7 +43,7 @@ deploy-draft:
     - |
       curl -X POST https://mude.citg.tudelft.nl/hooks/website-deploy-draft \
         -H "Content-Type: application/json" \
-        -H "X-Gitlab-Token: glpat-sQ82fiSMo1kCi2TpgSfr" \
+        -H "X-Gitlab-Token: YOUR_SECRET_TOKEN" \
         -d '{
           "object_kind": "pipeline",
           "object_attributes": {
@@ -59,7 +65,7 @@ deploy-production:
     - |
       curl -X POST https://mude.citg.tudelft.nl/hooks/website-deploy \
         -H "Content-Type: application/json" \
-        -H "X-Gitlab-Token: glpat-sQ82fiSMo1kCi2TpgSfr" \
+        -H "X-Gitlab-Token: YOUR_SECRET_TOKEN" \
         -d '{
           "object_kind": "pipeline",
           "object_attributes": {
diff --git a/build-page.sh b/build-page.sh
index ba649a3..dfd5020 100644
--- a/build-page.sh
+++ b/build-page.sh
@@ -7,30 +7,15 @@ PAGE_ROOT=$(echo "$PAGE_ROOT" | sed 's:/*$::')
 
 if [ "$IS_PUBLISH_DEPLOYMENT" = true ]; then
     echo "Using publish deployment strategy"
-    # Remove the banner which identifies the site as a draft
-    if ! command -v yq &>/dev/null; then
-        echo "yq could not be found, the draft banner cannot be removed"
-        echo "Please install yq (with APT or via https://github.com/mikefarah/yq#install) and try again"
-    else
-        cp _config.yml _config.yml.bak
-        yq -i '.is_draft = false' _config.yml
-        echo "is_draft set to false in _config.yml"
-    fi
+    CONFIG_FILE="_config.yml"
 else
     echo "Using draft deployment strategy"
-    # Ensure the draft flag is true for non-publish deployments
-    if ! command -v yq &>/dev/null; then
-        echo "yq could not be found, the draft banner cannot be enforced"
-        echo "Please install yq (with APT or via https://github.com/mikefarah/yq#install) and try again"
-    else
-        cp _config.yml _config.yml.bak
-        yq -i '.is_draft = true' _config.yml
-        echo "is_draft set to true in _config.yml"
-    fi
+    CONFIG_FILE="_config_draft.yml"
 fi
 
+echo "Using configuration file: $CONFIG_FILE"
 echo "Publishing to page root: \"$PAGE_ROOT\""
-bundle exec jekyll build -d public -b "$PAGE_ROOT"
+bundle exec jekyll build -d public -b "$PAGE_ROOT" --config "$CONFIG_FILE"
 
 # Check the build result
 if [ $? -ne 0 ]; then
-- 
GitLab