Skip to content

Commit 997c8b7

Browse files
committed
ci(gh-actions): add gulpfile, add workflows configuration
1 parent 2962c71 commit 997c8b7

File tree

4 files changed

+6245
-2312
lines changed

4 files changed

+6245
-2312
lines changed

.github/workflows/release.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Picker Plugins
2+
on:
3+
push:
4+
branches: [ develop, rewrite-sdk ]
5+
create:
6+
tags:
7+
- v*
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Setup repository env
14+
uses: actions/setup-node@v1
15+
with:
16+
node-version: '12.x'
17+
- name: Install deps
18+
run: npm install
19+
- name: Bundle packages
20+
run: npm run build:prod
21+
- name: Run tests
22+
run: npm run test
23+
- name: Build Docs
24+
run: npm run docs:build
25+
- name: Release packages
26+
run: npx gulp publish
27+
env:
28+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
29+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
30+
AWS_REGION: ${{ secrets.AWS_REGION }}
31+
32+
- name: Publush to NPM
33+
if: startsWith(github.ref, 'refs/tags/')
34+
run: npm publish
35+
env:
36+
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
37+
- name: Deploy docs
38+
uses: crazy-max/ghaction-github-pages@v2
39+
with:
40+
target_branch: gh-pages
41+
build_dir: example/build
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+

Gulpfile.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
const gulp = require('gulp');
2+
const sri = require('gulp-sri');
3+
const branch = require('git-branch');
4+
const pkgVersion = require('./package.json').version;
5+
const path = require('path');
6+
7+
// S3 CLIENT CONFIG
8+
const s3 = require('gulp-s3-upload')({ useIAM:true });
9+
10+
// DEPLOYMENT CONFIGURATION OPTIONS
11+
const source = ['dist/*.js', 'dist/*.map', 'dist/*.json']; // source for deploy
12+
const sourceSRI = ['dist/*.js', 'dist/*.map']; // source for sri generation
13+
const Bucket = 'static.filestackapi.com' // upload bucked
14+
const ACL = 'public-read'; // upload acl
15+
const deployPath = 'filestack-react'; // upload path
16+
const deploymentBranch = 'master'; // branch for upload production version
17+
const cacheControll = { // cache controll for each version
18+
latest: 1,
19+
version: 30,
20+
beta: 0,
21+
};
22+
23+
// HELPERS
24+
const getDeployPath = (inputPath, version) => `${deployPath}/${version}/${path.basename(inputPath)}`;
25+
const getMajorVersion = (version) => version.split('.')[0];
26+
27+
// GENERATE SRI TAG
28+
gulp.task('sri', () => {
29+
return gulp.src(sourceSRI)
30+
.pipe(sri({
31+
fileName: 'dist/manifest.json',
32+
transform: (o) => {
33+
let newOb = {};
34+
for (const el in o) {
35+
newOb[el.replace('dist/', '')] = { sri: o[el] };
36+
};
37+
38+
return newOb;
39+
}
40+
}))
41+
.pipe(gulp.dest('.'));
42+
});
43+
44+
// DEPLOYMENTS
45+
gulp.task('publish:beta', () => {
46+
return gulp.src(source)
47+
.pipe(s3({
48+
Bucket,
49+
ACL,
50+
CacheControl: `max-age=${cacheControll.beta * 86400}`,
51+
keyTransform: (path) => getDeployPath(path, 'beta'),
52+
}));
53+
});
54+
55+
gulp.task('publish:latest', () => {
56+
return gulp.src(source)
57+
.pipe(s3({
58+
Bucket,
59+
ACL,
60+
CacheControl: `max-age=${cacheControll.latest * 86400}`,
61+
keyTransform: (path) => getDeployPath(path, `${getMajorVersion(pkgVersion)}.x.x`),
62+
}));
63+
});
64+
65+
gulp.task('publish', gulp.series(() => {
66+
const currentBranch = branch.sync();
67+
console.info(`Current branch is "${currentBranch}"`)
68+
69+
if (currentBranch !== deploymentBranch) {
70+
return gulp.start('publish:beta');
71+
}
72+
73+
return gulp.src(source)
74+
.pipe(s3({
75+
Bucket,
76+
ACL,
77+
CacheControl: `max-age=${cacheControll.version * 86400}`,
78+
keyTransform: (path) => getDeployPath(path, pkgVersion),
79+
}));
80+
}, () => {
81+
const currentBranch = branch.sync();
82+
if (currentBranch !== deploymentBranch) {
83+
return;
84+
}
85+
86+
return gulp.start('publish:latest');
87+
}));

0 commit comments

Comments
 (0)