aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/command/deploy/release.lux
blob: c159555b965600d469f89319c3943731ab5f054f (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
(.require
 [library
  [lux (.except)
   ["[0]" ffi (.only import)]
   [abstract
    ["[0]" monad (.only do)]]
   [control
    ["[0]" pipe]
    ["[0]" try (.only Try)]
    ["[0]" io (.only IO)]
    [concurrency
     ["[0]" async (.only Async)]]
    [function
     [predicate (.only Predicate)]]]
   [data
    [binary (.only Binary)]
    ["[0]" text (.only)
     ["%" \\format]
     [encoding
      ["[0]" utf8]]]
    [collection
     ["[0]" set]
     ["[0]" dictionary]]
    [format
     ["[0]" tar]
     ["[0]" xml]]]
   [meta
    [compiler
     [meta
      ["[0]" export]
      ["[0]" archive]
      ["[0]" context]
      ["[0]" packager
       ["[1]" jvm]]]]]
   [world
    ["[0]" environment
     [/ (.only Environment)]
     ["[1]" \\parser]]
    [console (.only Console)]
    ["[0]" shell (.only Shell)]
    ["[0]" file]]]]
 ["[0]" //
  ["[1][0]" snapshot]
  ["/[1]" //
   ["[1][0]" install]
   ["/[1]" //
    [command (.only Command)]
    ["/" profile]
    ["[1][0]" action]
    ["[1][0]" pom]
    ["[1][0]" package]
    ["[1][0]" hash]
    ["[1][0]" dependency
     ["[1]/[0]" deployment]
     ["[1]/[0]" status]]
    ["[1][0]" repository (.only Repository)
     ["[1]/[0]" origin]
     ["[1]/[0]" local]]
    ["[1][0]" artifact (.only Artifact)
     ["[1]/[0]" type]
     ["[1]/[0]" extension (.only Extension)]]]]])

(import java/lang/String
  "[1]::[0]"
  (toLowerCase [] java/lang/String))

(import java/lang/System
  "[1]::[0]"
  ("static" getProperty [java/lang/String] "io" "try" java/lang/String))

(def windows?
  (IO (Try Bit))
  (of (try.with io.monad) each
      (|>> java/lang/String::toLowerCase ffi.of_string (text.starts_with? "windows"))
      (java/lang/System::getProperty (ffi.as_string "os.name"))))

(def dummy_jar
  Binary
  (|> (packager.package (context.jvm "")
                        (dictionary.empty text.hash)
                        archive.empty
                        {.#None})
      try.trusted
      (pipe.when
        {.#Left it}
        it
        
        {.#Right _}
        (undefined))))

(with_template [<name> <extension>]
  [(def <name>
     (-> Text Text)
     (text.suffix <extension>))]

  [asc ".asc"]
  [pom ////artifact/extension.pom]
  [tar ////artifact/extension.lux_library]
  [jar ////artifact/extension.jvm_library]
  [sha1 ////artifact/extension.sha1]
  [md5 ////artifact/extension.md5]
  )

(with_template [<name> <suffix>]
  [(def <name>
     (-> Text Text)
     (|>> (text.suffix <suffix>) ..jar))]

  [javadoc "-javadoc"]
  [sources "-sources"]
  )

(def .public release?
  (Predicate Artifact)
  (|>> //snapshot.snapshot? not))

(def (install_dummies! environment local fs artifact)
  (-> (Environment Async) (Repository Async) (file.System Async) Artifact (Async (Try Any)))
  (do (try.with async.monad)
    [.let [$artifact (////artifact.uri (the ////artifact.#version artifact) artifact)]
     _ (of local upload (..jar $artifact) ..dummy_jar)
     _ (of local upload (..javadoc $artifact) ..dummy_jar)
     _ (of local upload (..sources $artifact) ..dummy_jar)]
    (in [])))

(def (signed it)
  (-> Text [Text Text])
  [it (..asc it)])

(def (release_unsigned_artifact! local remote uri)
  (-> (Repository Async) (Repository Async) Text (Async (Try Binary)))
  (do [! ////action.monad]
    [it (of local download uri)
     _ (of remote upload uri it)]
    (in it)))

(def (release_signed_artifact! local remote [artifact signature])
  (-> (Repository Async) (Repository Async) [Text Text] (Async (Try Any)))
  (do [! ////action.monad]
    [it (..release_unsigned_artifact! local remote artifact)
     _ (|> it
           ////hash.md5
           (of ////hash.md5_codec encoded)
           (of utf8.codec encoded)
           (of remote upload (..md5 artifact)))
     _ (|> it
           ////hash.sha1
           (of ////hash.sha1_codec encoded)
           (of utf8.codec encoded)
           (of remote upload (..sha1 artifact)))
     _ (..release_unsigned_artifact! local remote signature)]
    (in [])))

(def .public (do! environment shell console local remote fs artifact profile)
  (-> (Environment Async) (Shell Async) (Console Async) (Repository Async) (Repository Async) (file.System Async) Artifact (Command Any))
  (do [! ////action.monad]
    [_ (///install.do! console fs local profile)
     _ (install_dummies! environment local fs artifact)
     .let [@root (////repository/local.root environment fs)
           $bundle (////artifact.bundle (the ////artifact.#version artifact) artifact)
           / (of fs separator)
           @local (%.format @root / $bundle)]
     windows? (async.future ..windows?)
     process (is (Async (Try (shell.Process Async)))
                 (of shell execute [environment.empty @local
                                    (if windows?
                                      ["cmd" (list "/c" "for %file in (.\*) do gpg.exe -ab %file")]
                                      ["sh" (list "-c" "for file in *.*; do gpg -ab $file; done")])]))
     exit (is (Async (Try shell.Exit))
              (of process await []))
     .let [$artifact (////artifact.uri (the ////artifact.#version artifact) artifact)]
     _ (monad.each ! (release_signed_artifact! local remote)
                   (list (..signed (..pom $artifact))
                         (..signed (..tar $artifact))
                         (..signed (..jar $artifact))
                         (..signed (..javadoc $artifact))
                         (..signed (..sources $artifact))))]
    (in [])))