Skip to content

Commit

Permalink
Issue #1: Add gitlab-ci and build tools config
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Cohen Arazi <[email protected]>
  • Loading branch information
tomascohen committed Oct 17, 2019
1 parent 7bb7802 commit 5c051fd
Show file tree
Hide file tree
Showing 5 changed files with 4,259 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ inc/
/MANIFEST.bak
/pm_to_blib
/*.zip
node_modules
16 changes: 16 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
image: "node:8-alpine"

stages:
- release

build:
stage: release
script:
- apk add --update zip curl jq
- npm install
- npm install -g gulp-cli
- gulp build
- "UPLOAD_URL=$(curl --request POST --header \"PRIVATE-TOKEN: $PRIVATE_TOKEN\" --form \"file=@$(npm run kpz -s)\" $CI_API_V4_URL/projects/$CI_PROJECT_ID/uploads | jq -r \".url\" )"
- "curl --header \"Content-Type: application/json\" --header \"PRIVATE-TOKEN: $PRIVATE_TOKEN\" --data \"{ \\\"name\\\": \\\"$(npm run name -s)\\\", \\\"tag_name\\\": \\\"$CI_COMMIT_TAG\\\", \\\"description\\\": \\\"release $CI_COMMIT_TAG\\\", \\\"assets\\\": { \\\"links\\\": [{ \\\"name\\\": \\\"$(npm run name -s)\\\", \\\"url\\\": \\\"$CI_PROJECT_URL$UPLOAD_URL\\\" }] } }\" --request POST $CI_API_V4_URL/projects/$CI_PROJECT_ID/releases"
only:
- tags
146 changes: 146 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
const gulp = require('gulp');
const release = require('gulp-github-release');
const fs = require('fs');
const run = require('gulp-run');
const dateTime = require('node-datetime');
const Vinyl = require('vinyl');
const path = require('path');
const stream = require('stream');

const dt = dateTime.create();
const today = dt.format('Y-m-d');

const package_json = JSON.parse(fs.readFileSync('./package.json'));
const release_filename = `${package_json.name}-v${package_json.version}.kpz`;

const pm_name = 'Koha';
const pm_file = pm_name+'.pm';
const pm_file_path = path.join('Koha', 'Plugin', 'Org', 'KC', 'ILL');
const pm_file_path_full = path.join(pm_file_path, pm_file);
const pm_file_path_dist = path.join('dist', pm_file_path);
const pm_file_path_full_dist = path.join(pm_file_path_dist, pm_file);
const pm_bundle_path = path.join(pm_file_path, pm_name);

/**
*
* Array of directories relative to pm_bundle_path where static files will be served
*
* If no static files need to be served, set static_relative_path = []
*
*/
const static_relative_path = [];

var static_absolute_path = [];

if(static_relative_path.length) {
static_absolute_path = static_relative_path.map(dir=>path.join(pm_bundle_path, dir)+'/**/*');
}

console.log(release_filename);
console.log(pm_file_path_full_dist);

gulp.task('static', ()=>{
if(static_absolute_path.length) {
let spec_body = JSON.stringify({
get: {
'x-mojo-to': 'Static#get',
tags: ['pluginStatic'],
responses: {
200: {
description: 'File found',
schema: {
type: 'file'
}
},
404: {
description: 'File not found',
schema: {
type: 'object',
properties: {
error: {
description: "An explanation for the error",
type: "string"
}
}
}
},
400: {
description: 'Bad request',
schema: {
type: 'object',
properties: {
error: {
description: "An explanation for the error",
type: "string"
}
}
}
},
500: {
description: 'Internal server error',
schema: {
type: 'object',
properties: {
error: {
description: "An explanation for the error",
type: "string"
}
}
}
}
}
}
}, null, 2);

return gulp.src(static_absolute_path)
.pipe(new stream.Transform({
objectMode: true,
transform: (file, unused, cb) => {
if(file.stat.isDirectory()) return cb();
let path_name = path.join('/', path.relative(pm_bundle_path, file.base), file.relative);
console.log('creating '+path_name);
let endpoint_spec = '"'+path_name+'": '+ spec_body;
file.contents = Buffer.from(endpoint_spec);
cb(null, file);
}
}))
.pipe(new stream.Transform({
objectMode: true,
transform: function(file, unused, cb) {
!this.bufArray && (this.bufArray = []);
this.bufArray.push(file.contents);
cb();
}
}))
.on('finish', function() {
let file = new Vinyl({
path: 'staticapi.json',
contents: Buffer.from('{\n'+this.bufArray.map(buf=>buf.toString()).join(',\n')+'\n}')
});
this.emit('data', file);
this.end();
})
.pipe(gulp.dest(pm_bundle_path));
}
});

gulp.task('build', ['static'], () => {
run(`
mkdir dist ;
cp -r Koha dist/. ;
sed -i -e "s/{VERSION}/${package_json.version}/g" ${pm_file_path_full_dist} ;
sed -i -e "s/1900-01-01/${today}/g" ${pm_file_path_full_dist} ;
cd dist ;
zip -r ../${release_filename} ./Koha ;
cd .. ;
rm -rf dist ;
`).exec();

});

gulp.task('release', () => {
gulp.src(release_filename)
.pipe(release({
manifest: require('./package.json') // package.json from which default values will be extracted if they're missing
}));
});
Loading

0 comments on commit 5c051fd

Please sign in to comment.