Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const cli = {
}
},
// computes & installs dependencies for h5p library
setup: async function(library, version, download) {
setup: async function(library, version, download, branch) {
const isUrl = ['http', 'git@'].includes(library.slice(0, 4)) ? true : false;
const url = library;
const missingOptionals = {};
Expand All @@ -196,6 +196,11 @@ const cli = {
const entry = await this.register(url);
library = logic.machineToShort(Object.keys(entry)[0]);
}
// branch is interpolated into a git clone shell command, so reject unsafe refs
if (branch && !/^[\w./-]+$/.test(branch)) {
console.log(`> error: invalid branch name "${branch}"`);
return;
}
let toSkip = [];
const action = parseInt(download) ? 'download' : 'clone';
const latest = version ? false : true;
Expand All @@ -217,9 +222,9 @@ const cli = {
}
toSkip = [];
console.log(`> ${action} ${library} library "view" dependencies into "${config.folders.libraries}" folder`);
toSkip = await logic.getWithDependencies(action, library, 'view', latest, toSkip);
toSkip = await logic.getWithDependencies(action, library, 'view', latest, toSkip, branch);
console.log(`> ${action} ${library} library "edit" dependencies into "${config.folders.libraries}" folder`);
toSkip = await logic.getWithDependencies(action, library, 'edit', latest, toSkip);
toSkip = await logic.getWithDependencies(action, library, 'edit', latest, toSkip, branch);
if (Object.keys(missingOptionals).length) {
console.log('!!! missing optional libraries');
for (let item in missingOptionals) {
Expand Down
18 changes: 11 additions & 7 deletions logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,9 @@ module.exports = {
/* clones/downloads dependencies to libraries folder using git and runs relevant npm commands
mode - 'view' or 'edit' to fetch non-editor or editor libraries
latest - if true master branch versions of libraries are used
toSkip - optional array of libraries to skip; after a library is parsed by the function it's auto-added to the array so it's skipped for efficiency */
getWithDependencies: async (action, library, mode, latest, toSkip = []) => {
toSkip - optional array of libraries to skip; after a library is parsed by the function it's auto-added to the array so it's skipped for efficiency
branch - optional git branch/ref to clone for the target library only; its dependencies still use master/tag */
getWithDependencies: async (action, library, mode, latest, toSkip = [], branch = null) => {
const list = await module.exports.computeDependencies(library, mode);
for (let item in list) {
if (toSkip.indexOf(item) != -1) {
Expand All @@ -443,21 +444,24 @@ module.exports = {
}
const label = `${list[item].id}-${list[item].version.major}.${list[item].version.minor}`;
const listVersion = `${list[item].version.major}.${list[item].version.minor}.${list[item].version.patch}`;
const version = latest ? 'master' : listVersion;
// only the library under test follows the PR branch; its deps stay on master/tag
const useBranch = branch && item === library;
const version = useBranch ? branch : (latest ? 'master' : listVersion);
const folder = `${config.folders.libraries}/${label}`;
if (fs.existsSync(folder)) {
if (latest && !process.env.H5P_NO_UPDATES) {
if (latest && !useBranch && !process.env.H5P_NO_UPDATES) {
console.log(`>> ~ updating to ${list[item].repoName} ${listVersion}`);
execSync(`git checkout master`, { cwd: folder, stdio : 'pipe' });
console.log(execSync('git pull origin', { cwd: folder }).toString());
}
else {
console.log(`>> ~ skipping updates for ${list[item].repoName} ${listVersion}`);
// branch libs are intentionally left as-is on re-runs (fresh CI runners never hit this)
console.log(`>> ~ skipping updates for ${list[item].repoName} ${useBranch ? branch : listVersion}`);
}
continue;
}
console.log(`>> + installing ${list[item].repoName} ${listVersion}`);
if (action == 'download') {
console.log(`>> + installing ${list[item].repoName} ${useBranch ? branch : listVersion}`);
if (action == 'download' && !useBranch) {
await module.exports.download(list[item].org, list[item].repoName, version, folder);
}
else {
Expand Down