-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validate-new-release command to check the diff of a plugins.xml file
checks the diff of plugins.xml (in a PR for example), extracts the data of the new plugins, downloading their package file and validating the checksum
- Loading branch information
Showing
9 changed files
with
142 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const crypto = require('crypto') | ||
const fs = require('fs') | ||
/** | ||
* Calculates the md5 check sum of a file | ||
*/ | ||
module.exports = function checksumFile (path, hashName = 'md5') { | ||
return new Promise((resolve, reject) => { | ||
const hash = crypto.createHash(hashName) | ||
const stream = fs.createReadStream(path) | ||
stream.on('error', err => reject(err)) | ||
stream.on('data', chunk => hash.update(chunk)) | ||
stream.on('end', () => resolve(hash.digest('hex'))) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const https = require('follow-redirects').https | ||
const fs = require('fs') | ||
|
||
/** | ||
* Downloads a file from the internet following the redirect (which is needed for Github links) | ||
*/ | ||
module.exports = (package, fileName) => { | ||
return new Promise((resolve, reject) => { | ||
const file = fs.createWriteStream(fileName) | ||
const req = https.get(package, function (response) { | ||
response.pipe(file) | ||
response.on('end', resolve) | ||
}) | ||
req.on('error', function (err) { | ||
console.log('Request error: ' + err.message) | ||
reject(err) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* scraps a fragment of xml to get the package url, MD5 etc.. | ||
* @param {string} lines the diffed lines showing what changed in a plugins.xml file | ||
*/ | ||
const extractReleaseData = lines => { | ||
const { | ||
groups: { package } | ||
} = /<package>(?<package>[^ $]*)<\/package>/g.exec(lines) | ||
|
||
const { | ||
groups: { md5 } | ||
} = /md5=\"(?<md5>[^ $]*)\"/g.exec(lines) | ||
|
||
return { | ||
md5, | ||
package | ||
} | ||
} | ||
|
||
module.exports = extractReleaseData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const shell = require('shelljs') | ||
const chalk = require('chalk') | ||
const downloadPackage = require('./download-package') | ||
const extractReleaseData = require('./extract-release-data') | ||
const checksumFile = require('./checkSumFile') | ||
|
||
module.exports = async args => { | ||
console.log(chalk.blueBright(`Checking new release`)) | ||
const diffFile = __dirname + '/diff.temp' | ||
const command = shell.exec(`git diff origin/master | grep ^+[^+]`) | ||
const changedLines = command.stdout | ||
|
||
// Extract release, md5 data from diff | ||
const { package: packageUrl, md5: expectedMD5 } = extractReleaseData( | ||
changedLines | ||
) | ||
console.log(chalk.blueBright(`Package url: ${packageUrl}`)) | ||
console.log(chalk.blueBright(`MD5: ${expectedMD5}`)) | ||
|
||
// Downlaod package | ||
const downloadedFileName = __dirname + '/downloaded_package.tar.gz' | ||
await downloadPackage(packageUrl, downloadedFileName) | ||
|
||
// Calculate MD5 of downloaded file | ||
const md5 = await checksumFile(downloadedFileName) | ||
|
||
if (md5 === expectedMD5) { | ||
console.log(chalk.greenBright(`The MD5 of the downloaded file is correct`)) | ||
} else { | ||
console.log( | ||
chalk.redBright( | ||
`The MD5 of the downloaded is incorrect. Expected ${expectedMD5}, Actual ${md5}` | ||
) | ||
) | ||
shell.rm(downloadedFileName) | ||
shell.exit(1) | ||
} | ||
|
||
console.log(chalk.blueBright(`MD5 of downloaded package: ${md5}`)) | ||
|
||
// check contents of tar file | ||
shell.exec(`tar -tf ${downloadedFileName}`) // ToDO .. check contents of the tar file | ||
|
||
shell.rm(downloadedFileName) | ||
|
||
if (command.code !== 0) { | ||
shell.echo('Error: checking new release failed') | ||
shell.exit(1) | ||
} | ||
} |