Skip to content

Commit 700e4c2

Browse files
committed
chore(ci): sync paralell demo builds via s3
1 parent 3139c97 commit 700e4c2

File tree

4 files changed

+92
-2
lines changed

4 files changed

+92
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ $RECYCLE.BIN/
2222
.DS_Store
2323
Thumbs.db
2424
UserInterfaceState.xcuserstate
25+
.env
2526

2627
.package.tmp.json
2728

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"del": "2.2.2",
6969
"dgeni": "^0.4.7",
7070
"dgeni-packages": "^0.16.10",
71+
"dotenv": "4.0.0",
7172
"event-stream": "3.3.4",
7273
"file-loader": "0.9.0",
7374
"fs-extra": "^2.0.0",
@@ -120,6 +121,7 @@
120121
"rollup-plugin-node-resolve": "3.0.0",
121122
"rollup-plugin-uglify": "1.0.1",
122123
"run-sequence": "1.2.2",
124+
"s3": "4.4.0",
123125
"sassdoc": "2.2.1",
124126
"semver": "5.3.0",
125127
"serve-static": "1.11.1",

scripts/docs/deploy.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ function run {
1919
cd ..
2020
VERSION=$(readJsonProp "package.json" "version")
2121

22-
#compile API Demos
22+
# download and copy over API Demos
23+
./node_modules/.bin/gulp demos.download
2324
./node_modules/.bin/gulp docs.demos --production=true
2425

2526
# if release, copy old version to seperate folder and blow out docs root api

scripts/gulp/tasks/demos.prod.ts

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as glob from 'glob';
44
import { task } from 'gulp';
55
import * as del from 'del';
66
import * as runSequence from 'run-sequence';
7+
import * as s3 from 's3';
78
import { argv } from 'yargs';
89

910

@@ -12,6 +13,9 @@ import { createTempTsConfig, getFolderInfo, runAppScriptsBuild, writePolyfills }
1213

1314
import * as pAll from 'p-all';
1415

16+
import * as dotenv from 'dotenv';
17+
dotenv.config();
18+
1519
task('demos.prepare', (done: Function) => {
1620
runSequence('demos.clean', 'demos.polyfill', 'demos.sass', (err: any) => done(err));
1721
});
@@ -95,9 +99,19 @@ function buildDemo(filePath: string) {
9599
const appNgModulePath = join(dirname(filePath), 'app.module.ts');
96100
const distDir = join(distTestRoot, 'www');
97101

98-
return runAppScriptsBuild(appEntryPoint, appNgModulePath, ionicAngularDir, distDir, pathToWriteFile, ionicAngularDir, sassConfigPath, copyConfigPath).then(() => {
102+
return runAppScriptsBuild(
103+
appEntryPoint,
104+
appNgModulePath,
105+
ionicAngularDir,
106+
distDir,
107+
pathToWriteFile,
108+
ionicAngularDir,
109+
sassConfigPath,
110+
copyConfigPath
111+
).then(() => {
99112
const end = Date.now();
100113
console.log(`${filePath} took a total of ${(end - start) / 1000} seconds to build`);
114+
uploadToS3(pathToWriteFile);
101115
});
102116
}
103117

@@ -112,6 +126,78 @@ function chunkArrayInGroups(arr, size) {
112126
return result;
113127
}
114128

129+
function uploadToS3(path) {
130+
// fail silently if envars not present
131+
if (!process.env.AWS_KEY || !process.env.AWS_SECRET) {
132+
return new Promise((resolve) => {resolve();});
133+
}
134+
135+
let client = s3.createClient({
136+
s3Options: {
137+
accessKeyId: process.env.AWS_KEY,
138+
secretAccessKey: process.env.AWS_SECRET
139+
},
140+
});
141+
142+
// get demo name from path
143+
let demo = path.split('/')[path.split('/').length - 2];
144+
145+
let params = {
146+
localDir: path.replace('tsconfig.json',''),
147+
deleteRemoved: true,
148+
s3Params: {
149+
Bucket: "ionic-demos",
150+
Prefix: demo,
151+
},
152+
};
153+
154+
var uploader = client.uploadDir(params);
155+
156+
return new Promise((resolve, reject) => {
157+
uploader.on('error', function(err) {
158+
console.error("s3 Upload Error:", err.stack);
159+
reject();
160+
});
161+
uploader.on('end', function() {
162+
console.log(demo, " demo uploaded to s3");
163+
resolve();
164+
});
165+
});
166+
}
167+
168+
task('demos.download', (done: Function) => {
169+
if (!process.env.AWS_KEY || !process.env.AWS_SECRET) {
170+
return new Promise((resolve) => {resolve();});
171+
}
172+
173+
let client = s3.createClient({
174+
s3Options: {
175+
accessKeyId: process.env.AWS_KEY,
176+
secretAccessKey: process.env.AWS_SECRET
177+
},
178+
});
179+
180+
let params = {
181+
localDir: join(process.cwd(), 'dist', 'demos', 'src'),
182+
s3Params: {
183+
Bucket: "ionic-demos",
184+
},
185+
};
186+
187+
let uploader = client.downloadDir(params);
188+
189+
return new Promise((resolve, reject) => {
190+
uploader.on('error', function(err) {
191+
console.error("s3 Download Error:", err.stack);
192+
reject();
193+
});
194+
uploader.on('end', function() {
195+
console.log("Demos downloaded from s3");
196+
resolve();
197+
});
198+
});
199+
})
200+
115201
task('demos.clean', (done: Function) => {
116202
// this is a super hack, but it works for now
117203
if (argv.skipClean) {

0 commit comments

Comments
 (0)