summaryrefslogtreecommitdiff
path: root/update-channel.scm
blob: 5e0d9fd1c612fbcb36e7327b6e6f0852a71924f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
;; webid-oidc, implementation of the Solid specification
;; Copyright (C) 2020, 2021  Vivien Kraus

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Affero General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU Affero General Public License for more details.

;; You should have received a copy of the GNU Affero General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

(use-modules (gnu packages bash))
(use-modules (gnu packages base))
(use-modules (gnu packages tex))
(use-modules (gnu packages code))
(use-modules (gnu packages version-control))
(use-modules (guix build-system gnu))
(use-modules (guix packages))
(use-modules (guix gexp))
(use-modules (guix modules))
(use-modules (guix build utils))
(use-modules (guix store))
(use-modules (ice-9 textual-ports))
(use-modules (ice-9 rdelim))

(unsetenv "GIT_DIR")

(let ((tmp-dirname (tmpnam))
      (git
       (run-with-store
        (open-connection)
        (package-file git "bin/git")))
      (bash
       (run-with-store
        (open-connection)
        (package-file bash "bin/bash")))
      (tar
       (run-with-store
        (open-connection)
        (package-file tar "bin/tar"))))
  (format (current-error-port) "Found the required programs:
- git:  ~a
- bash: ~a
- tar:  ~a
"
          git bash tar)
  (format (current-error-port) "Using temporary directory ~a\n" tmp-dirname)
  (mkdir tmp-dirname)
  (mkdir (string-append tmp-dirname "/source"))
  (invoke git "archive" "master" "-o" (string-append tmp-dirname "/source/source.tar.gz"))
  (with-directory-excursion
   (string-append tmp-dirname "/source")
   (invoke tar "xf" (string-append tmp-dirname "/source/source.tar.gz"))
   (delete-file (string-append tmp-dirname "/source/source.tar.gz")))
  (with-directory-excursion
   tmp-dirname
   (invoke bash "-c" (format #f "guix hash -r source > hash")))
  (invoke bash "-c" (format #f "~a describe --tags --always > ~a/version" git tmp-dirname))
  (invoke bash "-c" (format #f "~a rev-parse master > ~a/commit" git tmp-dirname))
  (let ((hash (call-with-input-file (string-append tmp-dirname "/hash") read-line))
        (version (call-with-input-file (string-append tmp-dirname "/version") read-line))
        (commit (call-with-input-file (string-append tmp-dirname "/commit") read-line))
        (interned-modules
         (run-with-store
          (open-connection)
          (interned-file (string-append tmp-dirname "/source/guix") "ci-checkout" #:recursive? #t)))
        (base-repository (getcwd)))
    (delete-file-recursively tmp-dirname)
    (invoke git "clone" (format #f "~a/../webid-oidc-channel" base-repository) tmp-dirname)
    (with-directory-excursion
     tmp-dirname
     (invoke git "rm" "-f" "-r" "--ignore-unmatch" ".")
     (copy-recursively interned-modules "." #:follow-symlinks? #t)
     (chmod "vkraus/packages/webid-oidc.scm" #o644)
     (let ((port (open-file "vkraus/packages/webid-oidc.scm" "a")))
       (write `(define-public webid-oidc
                 (webid-oidc-release ,version ,commit ,hash))
              port)
       (display "\n" port)
       (write `(define-public webid-oidc-html
                 (webid-oidc-htmlize webid-oidc))
              port)
       (display "\n" port)
       (write `(define-public webid-oidc:website
                 (make-website webid-oidc))
              port)
       (display "\n" port)
       (close-port port))
     (invoke git "add" "-A")
     (invoke bash "-c" (format #f "~a diff-index --quiet HEAD || ~a commit -m 'Update package'"
                               git git))
     (invoke git "push" "origin" "master"))))

#~(system* #$(file-append hello "/bin/hello"))