-
Notifications
You must be signed in to change notification settings - Fork 2
/
task.cfc
212 lines (177 loc) · 8.43 KB
/
task.cfc
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/**
* Publish missing Lucee engines to ForgeBox
*/
component {
property name='semanticVersion' inject='semanticVersion@semver';
property name="progressableDownloader" inject="ProgressableDownloader";
property name="progressBar" inject="ProgressBar";
function run() {
loadModule( 'modules/s3sdk' )
var s3 = getInstance( name='AmazonS3@S3SDK', initArguments={
accessKey=getSystemSetting( 'S3_ACCESS_KEY' ),
secretKey=getSystemSetting( 'S3_SECRET' ),
defaultBucketName='downloads.ortussolutions.com'
} );
command( 'config set' ).params( 'endpoints.forgebox.apitoken'=getSystemSetting( 'FORGEBOX_TOKEN' ) ).flags( 'quiet' ).run();
// -------------------------------------------------------------------------------
print.text( 'Getting Lucee Versions: ' ).toConsole();
// This is every version of Lucee ever published since 5.0.0
http url="https://release.lucee.org/rest/update/provider/list?extended=true" result="local.luceeVersions";
if( isJSON( local.luceeVersions.fileContent ) ) {
local.luceeVersions = deserializeJSON( local.luceeVersions.fileContent ).map( (k,v)=>{
// Convert 1.2.3.4-foo to 1.2.3-foo+4 (semver)
return {
version : v.version.reReplace( '([0-9]*\.[0-9]*\.[0-9]*)(\.)([0-9]*)(-.*)?', '\1\4+\3' ),
luceeVersion : v.version,
fb : v.fb ?: '',
fbl : v.fbl ?: ''
}
// These versions don't have jars, so ignore
} )
.valueArray()
.filter( (v)=>!v.version.reFindNoCase( '(5\.3\.1\+91|5\.3\.3\+67|5\.3\.1\+91|5\.3\.3\+67|5\.3\.8\+84)' ) ) // snapshot|rc|beta|alpha
} else {
print.line( local.luceeVersions );
throw( 'Response from Lucee API is not JSON.' );
}
if( !local.luceeVersions.len() ) {
throw( 'Lucee has amnesia and has forgotten all its versions!' );
}
print.line( local.luceeVersions.len() & ' found ( #local.luceeVersions.first().version# - #local.luceeVersions.last().version# )' ).toConsole()
// -------------------------------------------------------------------------------
print.text( 'Getting ForgeBox Lucee Versions: ' ).toConsole();
var forgeboxVersions = command( 'forgebox show lucee --json' ).run( returnOutput=true );
forgeboxVersions = deserializeJSON( print.unansi( forgeboxVersions ) ).versions.map( (v)=>v.version );
print.line( forgeboxVersions.len() & ' found ( #forgeboxVersions.last()# - #forgeboxVersions.first()# )' ).toConsole()
// -------------------------------------------------------------------------------
print.text( 'Getting ForgeBox Lucee LIGHT Versions: ' ).toConsole();
var forgeboxLightVersions = command( 'forgebox show lucee-light --json' ).run( returnOutput=true );
forgeboxLightVersions = deserializeJSON( print.unansi( forgeboxLightVersions ) ).versions.map( (v)=>v.version );
print.line( forgeboxLightVersions.len() & ' found ( #forgeboxLightVersions.last()# - #forgeboxLightVersions.first()# )' ).toConsole()
// -------------------------------------------------------------------------------
var minVersion = '5.2.8';
print.line( 'looking for missing versions starting at #minVersion#' )
var missingVersions = []
// Lucee versions later than minVersion and not in ForgeBox
.append( luceeVersions.filter( (lv)=>len( lv.fb) && !forgeboxVersions.findNoCase( lv.version ) && semanticVersion.isNew( minVersion, lv.version ) ).map( (v)=>duplicate(v).append({light:false}) ), true )
// Add in Lucee Light versions later than minVersion and not in ForgeBox
.append( luceeVersions.filter( (lv)=>len( lv.fbl) && !forgeboxLightVersions.findNoCase( lv.version ) && semanticVersion.isNew( minVersion, lv.version ) ).map( (v)=>duplicate(v).append({light:true}) ), true );
print.line( missingVersions.len() & ' missing versions found' ).line().line().toConsole()
//print.line( missingVersions ).toConsole()
//return ;
// -------------------------------------------------------------------------------
var CFEngineURL = 'https://cdn.lucee.org/';
if( directoryExists( resolvePath( 'download' ) ) ) {
directoryDelete( resolvePath( 'download' ), true )
}
directoryCreate( resolvePath( 'download' ), true, true );
var errors = false;
// Process each version
for( var v in missingVersions ) {
try {
print.Greenline( 'Processing #v.version##(v.light?' Light':'')# ...' ).toConsole()
var localPath = resolvePath( 'download/downloaded-#v.version##(v.light?'-light':'')#.zip' )
var s3URI = v.light ? v.fbl : v.fb;
var Ortuss3URI='lucee/lucee/#v.luceeVersion#/cf-engine-#v.luceeVersion##(v.light?'-light':'')#.zip'
// Download CF Engine from Lucee's update server
if( !fileExists( localPath ) ) {
var downloadURL = CFEngineURL & s3URI;
print.line( 'Downloading #downloadURL# ...' ).toConsole()
progressableDownloader.download(
downloadURL,
localPath,
( status )=>progressBar.update( argumentCollection = status ),
( newURL )=>{}
);
}
var fileSize = getFileInfo( localPath ).size;
// Is download larger than 10MB. Sometimes Lucee will return a "jar not found" JSON response
if( fileSize < 10*1000*1000 ) {
print.redLine( 'Downloaded file #localPath# too small [#round(fileSize/1000)#K], ignoring.' )
fileDelete( localPath )
} else if ( fileSize > 250*1000*1000 ) {
// also ignore files larger than 250mb
print.redLine( 'Downloaded file #localPath# was too large [#numberFormat(round(fileSize/1000))#K].' )
fileDelete( localPath )
} else {
print.redLine( 'Downloaded file #localPath# is [#numberFormat(round(fileSize/1000))#K].' )
// Push file to Ortus S3 bucket
if(!s3.objectExists( uri=Ortuss3URI ) ) {
print.line( 'Uploading #Ortuss3URI# ...' ).toConsole()
var s3Tries = 0;
try {
s3.putObject( uri=Ortuss3URI, data=fileReadBinary( localPath ), contentType='application/octet-stream' );
// Sometimes S3 will reset the connection, so try a couple times before giving up
} catch( any e ){
print.line( e.message ).toConsole()
s3Tries++
if( s3Tries < 3 ) {
sleep( 1000 )
retry;
}
rethrow;
}
}
// Seed a temporary box.json file so we can publish this version to ForgeBox
directoryCreate( resolvePath( 'temp' ), true, true );
fileWrite( resolvePath( 'temp/box.json' ), '{
"name":"Lucee#(v.light?' Light':'')# CF Engine",
"version":"#v.version#",
"createPackageDirectory":false,
"location":"https://downloads.ortussolutions.com/lucee/lucee/#v.luceeVersion#/cf-engine-#v.luceeVersion##(v.light?'-light':'')#.zip",
"slug":"lucee#(v.light?'-light':'')#",
"shortDescription":"Lucee#(v.light?' Light':'')# WAR engine for CommandBox servers.",
"type":"cf-engines"
}' )
try {
print.line( 'Pubishing to ForgeBox...' ).toConsole()
// Run publish in the same directory as our temp box.json
command( 'publish' ).inWorkingDirectory( resolvePath( 'temp' ) ).run();
} catch( any e ){
// ForgeBox keeps throwing these but we don't know why. When it does, the package is still published just fine so ingore them
if( e.detail contains '408' ) {
print
.line( e.message )
.line( e.detail )
.toConsole()
slackMessage( e.detail );
} else {
rethrow;
}
}
slackMessage( "Lucee #(v.light?' Light':'')# #v.version# published to ForgeBox." );
}
} catch( any e ) {
errors = true;
var stackContext = "missing stack";
if ( ArrayLen(e.tagContext) gt 0 ) {
stackContext = e.tagContext[ 1 ].template & ':' & e.tagContext[ 1 ].line;
}
print
.redLine( e.message )
.redLine( e.detail )
.redLine( stackContext )
.toConsole();
slackMessage( "Error publishing Lucee #(v.light?' Light':'')# #v.version#. #chr(10)# #e.message# #chr(10)# #e.detail# #chr(10)# #stackContext# " );
}
print.line().line().toConsole()
}
if( errors ) {
print.redLine( 'Errors encountered on one or more versions' ).toConsole();
return 1;
} else {
// Peanut Butter Jelly Time!
print.greenLine( 'Complete!' );
}
}
function slackMessage( required string message ) {
var payload = serializeJSON( {"text":message} );
http url=getSystemSetting( 'SLACK_WEBHOOK_URL' ) method="post" result='local.cfhttp' {
cfhttpparam( type="body", value='#payload#');
}
if( local.cfhttp.status_code != '200' ) {
print.redLine( 'Error Sending Slack message: #local.cfhttp.statuscode# #local.cfhttp.fileContent# ' );
print.redLine( payload );
}
}
}