about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2025-11-04 02:38:41 +0000
committerArun Isaac2025-11-04 13:36:48 +0000
commit5ab44479ccb368f50b8fa768a719abd43d189053 (patch)
treeaa6054b52190a01d3aae9ab22f5daee1a756fb65
parentde8d5a774b96976c0ed3ed529870f89fd1b4a9aa (diff)
downloadguix-forge-5ab44479ccb368f50b8fa768a719abd43d189053.tar.gz
guix-forge-5ab44479ccb368f50b8fa768a719abd43d189053.tar.lz
guix-forge-5ab44479ccb368f50b8fa768a719abd43d189053.zip
forge: Promote website CI job to its own field.
With the website CI job in its own field, we can reduce boilerplate
around installing the built website at the correct path.
-rw-r--r--doc/forge.skb13
-rw-r--r--guix/forge/forge.scm28
2 files changed, 36 insertions, 5 deletions
diff --git a/doc/forge.skb b/doc/forge.skb
index 1703544..de6f1bc 100644
--- a/doc/forge.skb
+++ b/doc/forge.skb
@@ -564,9 +564,11 @@ gunicorn is run in]))))))
          [File-like object representing directory to serve as the
 document root of the guix-forge web interface])
        (record-field "websites-directory"
-         [Directory containing websites for each project. Each project
-must put its website here in a subdirectory with the same name as the
-project. This is usually achieved using a CI job.])
+         [Directory containing websites for each project. Each
+project's website is put in a subdirectory with the same name as the
+project. Project websites are built by the ,(abbr :short "CI" :long
+"continuous integration") job configured in its ,(record-field-ref
+"<forge-project>" "website-ci-job").])
        (record-field "projects"
          [List of ,(record-ref "<forge-project>") objects describing
 projects managed by guix-forge]))
@@ -592,8 +594,11 @@ remote.])
 will be served at ,(samp "/<name>/") on the ,(record-field-ref
 "<forge-configuration>" "web-domain") configured in ,(record-ref
 "<forge-configuration>").])
+       (record-field "website-ci-job"
+         [,(record-ref "<forge-laminar-job>") object describing ,(abbr
+:short "CI" :long "continuous integration") job to build website])
        (record-field "ci-jobs"
-         [List of ,(record-ref "<forge-laminar-job>") objects
+         [List of other ,(record-ref "<forge-laminar-job>") objects
 describing ,(abbr :short "CI" :long "continuous integration") jobs to
 configure])
        (record-field "ci-jobs-trigger"
diff --git a/guix/forge/forge.scm b/guix/forge/forge.scm
index 31728dc..63bc68d 100644
--- a/guix/forge/forge.scm
+++ b/guix/forge/forge.scm
@@ -63,6 +63,7 @@
             forge-project-repository-branch
             forge-project-web-domain
             forge-project-tissue?
+            forge-project-website-ci-job
             forge-project-ci-jobs
             forge-project-ci-jobs-trigger
             forge-project-parallel-ci-job-runs
@@ -91,6 +92,10 @@
               (default #f))
   (tissue? forge-project-tissue?
            (default #f))
+  (website-ci-job forge-project-website-ci-job
+                  ;; TODO: Add default website builder.
+                  (default #f)
+                  (thunked))
   (ci-jobs forge-project-ci-jobs
            (default '()) (thunked))
   (ci-jobs-trigger forge-project-ci-jobs-trigger ; one of 'post-receive-hook, 'cron, 'webhook
@@ -485,6 +490,17 @@ that were built."
                                           (package-channels pkg))))))))
                 inferior))))))))
 
+(define (switch-symlinks-gexp link target)
+  "Return a G-expression that links @var{link} to @var{target}. @var{target} is a
+singleton list of targets as returned by @code{guix-channel-job-gexp}."
+  (with-imported-modules '((guix build utils))
+    #~(begin
+        (use-modules (guix build utils))
+
+        (switch-symlinks #$link
+                         (match #$target
+                           ((target) target))))))
+
 (define (forge-nginx-server-blocks config)
   "Return list of @code{<nginx-server-configuration>} extensions for
 forge configuration @var{config}."
@@ -548,7 +564,17 @@ value of the returned list is a @code{<forge-laminar-job>} object."
                         (inherit job)
                         (contexts (cons (forge-project-name project)
                                         (forge-laminar-job-contexts job)))))
-                     (forge-project-ci-jobs project)))
+                     ;; Prepend website CI job to the other CI jobs.
+                     (if (forge-project-website-ci-job project)
+                         (cons (forge-laminar-job
+                                (inherit (forge-project-website-ci-job project))
+                                (run (switch-symlinks-gexp
+                                      (string-append (forge-configuration-websites-directory config)
+                                                     "/"
+                                                     (forge-project-name project))
+                                      (forge-laminar-job-run (forge-project-website-ci-job project)))))
+                               (forge-project-ci-jobs project))
+                         (forge-project-ci-jobs project))))
               (forge-configuration-projects config)))
 
 (define (forge-ci-job-contexts config)