From 403fede3f51db5363fa53f01c511829cec5f0a69 Mon Sep 17 00:00:00 2001
From: Chris Coley <chris@codingallnight.com>
Date: Sun, 23 Apr 2023 01:31:50 -0700
Subject: [PATCH 1/6] Add support for branch subdirectories

---
 .gitlab-ci.yml             | 10 ++++++----
 {public => src}/index.html |  2 +-
 {public => src}/style.css  |  0
 3 files changed, 7 insertions(+), 5 deletions(-)
 rename {public => src}/index.html (94%)
 rename {public => src}/style.css (100%)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 313b5c4..5c50814 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,13 +1,15 @@
 image: alpine:latest
 
+workflow:
+  rules:
+    - if: $CI_COMMIT_BRANCH
+
 pages:
   stage: deploy
   tags:
     - docker
   script:
-  - echo 'Nothing to do...'
+    - cp -r src public/$CI_COMMIT_BRANCH
   artifacts:
     paths:
-    - public
-  only:
-  - master
+    - public/CI_COMMIT_BRANCH
diff --git a/public/index.html b/src/index.html
similarity index 94%
rename from public/index.html
rename to src/index.html
index 6652c7d..1f9332b 100644
--- a/public/index.html
+++ b/src/index.html
@@ -13,7 +13,7 @@
       <a href="https://gitlab.com/pages/">Other Examples</a>
     </div>
 
-    <h1>Hello World!</h1>
+    <h1>Hello World! Dev Branch</h1>
 
     <p>
       This is a simple plain-HTML website on GitLab Pages, without any fancy static site generator.
diff --git a/public/style.css b/src/style.css
similarity index 100%
rename from public/style.css
rename to src/style.css
-- 
GitLab


From e34077c1732114071840de3d208e2881739fb346 Mon Sep 17 00:00:00 2001
From: Chris Coley <chris@codingallnight.com>
Date: Sun, 23 Apr 2023 01:33:24 -0700
Subject: [PATCH 2/6] Make sure the branch subdirectory exists

---
 .gitlab-ci.yml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5c50814..bba6a9b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -9,7 +9,8 @@ pages:
   tags:
     - docker
   script:
+    - mkdir -p public/$CI_COMMIT_BRANCH
     - cp -r src public/$CI_COMMIT_BRANCH
   artifacts:
     paths:
-    - public/CI_COMMIT_BRANCH
+    - public/$CI_COMMIT_BRANCH
-- 
GitLab


From 9582ca672bb57a48d68a5e45a001c44f038f7397 Mon Sep 17 00:00:00 2001
From: Chris Coley <chris@codingallnight.com>
Date: Sun, 23 Apr 2023 01:34:58 -0700
Subject: [PATCH 3/6] Copy contents of src directory, not the directory itself

---
 .gitlab-ci.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index bba6a9b..e8a4e07 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -10,7 +10,7 @@ pages:
     - docker
   script:
     - mkdir -p public/$CI_COMMIT_BRANCH
-    - cp -r src public/$CI_COMMIT_BRANCH
+    - cp -r src/* public/$CI_COMMIT_BRANCH
   artifacts:
     paths:
     - public/$CI_COMMIT_BRANCH
-- 
GitLab


From 9714d18d0131dff2807706ec78ed97f03d8c21f7 Mon Sep 17 00:00:00 2001
From: Chris Coley <chris@codingallnight.com>
Date: Sun, 23 Apr 2023 01:56:19 -0700
Subject: [PATCH 4/6] Use publicly browsable artifacts instead of pages

---
 .gitlab-ci.yml | 13 +++++++++----
 src/index.html |  5 ++++-
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index e8a4e07..95a58e2 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -4,13 +4,18 @@ workflow:
   rules:
     - if: $CI_COMMIT_BRANCH
 
-pages:
+deploy-docs:
   stage: deploy
   tags:
     - docker
   script:
-    - mkdir -p public/$CI_COMMIT_BRANCH
-    - cp -r src/* public/$CI_COMMIT_BRANCH
+    - mkdir -p public
+    - cp -r src/* public/
+    - sed -i "s/%%BRANCH%%/$CI_BRANCH_NAME/g" public/index.html
+    - printenv
   artifacts:
     paths:
-    - public/$CI_COMMIT_BRANCH
+      - public/
+  environment:
+    name: $CI_COMMIT_BRANCH
+    url: "https://$CI_PAGES_URL/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public/index.html"
diff --git a/src/index.html b/src/index.html
index 1f9332b..ac6769c 100644
--- a/src/index.html
+++ b/src/index.html
@@ -13,11 +13,14 @@
       <a href="https://gitlab.com/pages/">Other Examples</a>
     </div>
 
-    <h1>Hello World! Dev Branch</h1>
+    <h1>Hello World!</h1>
 
     <p>
       This is a simple plain-HTML website on GitLab Pages, without any fancy static site generator.
     </p>
+    <p>
+      It was built on the %%BRANCH%% branch
+    </p>
   </body>
 </html>
 
-- 
GitLab


From 6fc8890ba258195c730109040d41d4ecc13ce803 Mon Sep 17 00:00:00 2001
From: Chris Coley <chris@codingallnight.com>
Date: Sun, 23 Apr 2023 02:03:02 -0700
Subject: [PATCH 5/6] Fix the environment URL

---
 .gitlab-ci.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 95a58e2..c4e9c7f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -11,11 +11,11 @@ deploy-docs:
   script:
     - mkdir -p public
     - cp -r src/* public/
-    - sed -i "s/%%BRANCH%%/$CI_BRANCH_NAME/g" public/index.html
+    - sed -i "s/%%BRANCH%%/$CI_COMMIT_BRANCH/g" public/index.html
     - printenv
   artifacts:
     paths:
       - public/
   environment:
     name: $CI_COMMIT_BRANCH
-    url: "https://$CI_PAGES_URL/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public/index.html"
+    url: "https://$CI_PROJECT_NAMESPACE.$CI_PAGES_DOMAIN/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public/index.html"
-- 
GitLab


From 4406d02805c9b14e56b808367a4bb429093aab55 Mon Sep 17 00:00:00 2001
From: Chris Coley <chris@codingallnight.com>
Date: Sun, 23 Apr 2023 02:19:44 -0700
Subject: [PATCH 6/6] clean up the deployment script

---
 .gitlab-ci.yml | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c4e9c7f..43390fc 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -9,10 +9,8 @@ deploy-docs:
   tags:
     - docker
   script:
-    - mkdir -p public
-    - cp -r src/* public/
-    - sed -i "s/%%BRANCH%%/$CI_COMMIT_BRANCH/g" public/index.html
-    - printenv
+    - sed -i "s/%%BRANCH%%/$CI_COMMIT_BRANCH/g" src/index.html
+    - mv src public
   artifacts:
     paths:
       - public/
-- 
GitLab