From cce4972327c7a4974a1e995af3bd697bf50c9dec Mon Sep 17 00:00:00 2001 From: Marc Coury Date: Wed, 26 Aug 2020 00:29:11 +0100 Subject: [PATCH 1/6] Parse changelog to get tag version and body --- dist/index.js | 850 +++++++++++++++++++++++++++-------- package-lock.json | 25 +- package.json | 7 +- src/create-release.js | 31 +- tests/create-release.test.js | 29 ++ 5 files changed, 754 insertions(+), 188 deletions(-) diff --git a/dist/index.js b/dist/index.js index 00c01f12..01cba4f8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2012,7 +2012,74 @@ module.exports = require("https"); /***/ 215: /***/ (function(module) { -module.exports = {"_args":[["@octokit/rest@16.43.1","/Users/mscoutermarsh/code/create-release"]],"_from":"@octokit/rest@16.43.1","_id":"@octokit/rest@16.43.1","_inBundle":false,"_integrity":"sha512-gfFKwRT/wFxq5qlNjnW2dh+qh74XgTQ2B179UX5K1HYCluioWj8Ndbgqw2PVqa1NnVJkGHp2ovMpVn/DImlmkw==","_location":"/@octokit/rest","_phantomChildren":{"@octokit/types":"2.16.0","deprecation":"2.3.1","once":"1.4.0","os-name":"3.1.0"},"_requested":{"type":"version","registry":true,"raw":"@octokit/rest@16.43.1","name":"@octokit/rest","escapedName":"@octokit%2frest","scope":"@octokit","rawSpec":"16.43.1","saveSpec":null,"fetchSpec":"16.43.1"},"_requiredBy":["/@actions/github"],"_resolved":"https://registry.npmjs.org/@octokit/rest/-/rest-16.43.1.tgz","_spec":"16.43.1","_where":"/Users/mscoutermarsh/code/create-release","author":{"name":"Gregor Martynus","url":"https://github.com/gr2m"},"bugs":{"url":"https://github.com/octokit/rest.js/issues"},"bundlesize":[{"path":"./dist/octokit-rest.min.js.gz","maxSize":"33 kB"}],"contributors":[{"name":"Mike de Boer","email":"info@mikedeboer.nl"},{"name":"Fabian Jakobs","email":"fabian@c9.io"},{"name":"Joe Gallo","email":"joe@brassafrax.com"},{"name":"Gregor Martynus","url":"https://github.com/gr2m"}],"dependencies":{"@octokit/auth-token":"^2.4.0","@octokit/plugin-paginate-rest":"^1.1.1","@octokit/plugin-request-log":"^1.0.0","@octokit/plugin-rest-endpoint-methods":"2.4.0","@octokit/request":"^5.2.0","@octokit/request-error":"^1.0.2","atob-lite":"^2.0.0","before-after-hook":"^2.0.0","btoa-lite":"^1.0.0","deprecation":"^2.0.0","lodash.get":"^4.4.2","lodash.set":"^4.3.2","lodash.uniq":"^4.5.0","octokit-pagination-methods":"^1.1.0","once":"^1.4.0","universal-user-agent":"^4.0.0"},"description":"GitHub REST API client for Node.js","devDependencies":{"@gimenete/type-writer":"^0.1.3","@octokit/auth":"^1.1.1","@octokit/fixtures-server":"^5.0.6","@octokit/graphql":"^4.2.0","@types/node":"^13.1.0","bundlesize":"^0.18.0","chai":"^4.1.2","compression-webpack-plugin":"^3.1.0","cypress":"^3.0.0","glob":"^7.1.2","http-proxy-agent":"^4.0.0","lodash.camelcase":"^4.3.0","lodash.merge":"^4.6.1","lodash.upperfirst":"^4.3.1","lolex":"^5.1.2","mkdirp":"^1.0.0","mocha":"^7.0.1","mustache":"^4.0.0","nock":"^11.3.3","npm-run-all":"^4.1.2","nyc":"^15.0.0","prettier":"^1.14.2","proxy":"^1.0.0","semantic-release":"^17.0.0","sinon":"^8.0.0","sinon-chai":"^3.0.0","sort-keys":"^4.0.0","string-to-arraybuffer":"^1.0.0","string-to-jsdoc-comment":"^1.0.0","typescript":"^3.3.1","webpack":"^4.0.0","webpack-bundle-analyzer":"^3.0.0","webpack-cli":"^3.0.0"},"files":["index.js","index.d.ts","lib","plugins"],"homepage":"https://github.com/octokit/rest.js#readme","keywords":["octokit","github","rest","api-client"],"license":"MIT","name":"@octokit/rest","nyc":{"ignore":["test"]},"publishConfig":{"access":"public"},"release":{"publish":["@semantic-release/npm",{"path":"@semantic-release/github","assets":["dist/*","!dist/*.map.gz"]}]},"repository":{"type":"git","url":"git+https://github.com/octokit/rest.js.git"},"scripts":{"build":"npm-run-all build:*","build:browser":"npm-run-all build:browser:*","build:browser:development":"webpack --mode development --entry . --output-library=Octokit --output=./dist/octokit-rest.js --profile --json > dist/bundle-stats.json","build:browser:production":"webpack --mode production --entry . --plugin=compression-webpack-plugin --output-library=Octokit --output-path=./dist --output-filename=octokit-rest.min.js --devtool source-map","build:ts":"npm run -s update-endpoints:typescript","coverage":"nyc report --reporter=html && open coverage/index.html","generate-bundle-report":"webpack-bundle-analyzer dist/bundle-stats.json --mode=static --no-open --report dist/bundle-report.html","lint":"prettier --check '{lib,plugins,scripts,test}/**/*.{js,json,ts}' 'docs/*.{js,json}' 'docs/src/**/*' index.js README.md package.json","lint:fix":"prettier --write '{lib,plugins,scripts,test}/**/*.{js,json,ts}' 'docs/*.{js,json}' 'docs/src/**/*' index.js README.md package.json","postvalidate:ts":"tsc --noEmit --target es6 test/typescript-validate.ts","prebuild:browser":"mkdirp dist/","pretest":"npm run -s lint","prevalidate:ts":"npm run -s build:ts","start-fixtures-server":"octokit-fixtures-server","test":"nyc mocha test/mocha-node-setup.js \"test/*/**/*-test.js\"","test:browser":"cypress run --browser chrome","update-endpoints":"npm-run-all update-endpoints:*","update-endpoints:fetch-json":"node scripts/update-endpoints/fetch-json","update-endpoints:typescript":"node scripts/update-endpoints/typescript","validate:ts":"tsc --target es6 --noImplicitAny index.d.ts"},"types":"index.d.ts","version":"16.43.1"}; +module.exports = {"_args":[["@octokit/rest@16.43.1","/home/marc/src/github.com/mec07/create-release"]],"_from":"@octokit/rest@16.43.1","_id":"@octokit/rest@16.43.1","_inBundle":false,"_integrity":"sha512-gfFKwRT/wFxq5qlNjnW2dh+qh74XgTQ2B179UX5K1HYCluioWj8Ndbgqw2PVqa1NnVJkGHp2ovMpVn/DImlmkw==","_location":"/@octokit/rest","_phantomChildren":{"@octokit/types":"2.16.0","deprecation":"2.3.1","once":"1.4.0","os-name":"3.1.0"},"_requested":{"type":"version","registry":true,"raw":"@octokit/rest@16.43.1","name":"@octokit/rest","escapedName":"@octokit%2frest","scope":"@octokit","rawSpec":"16.43.1","saveSpec":null,"fetchSpec":"16.43.1"},"_requiredBy":["/@actions/github"],"_resolved":"https://registry.npmjs.org/@octokit/rest/-/rest-16.43.1.tgz","_spec":"16.43.1","_where":"/home/marc/src/github.com/mec07/create-release","author":{"name":"Gregor Martynus","url":"https://github.com/gr2m"},"bugs":{"url":"https://github.com/octokit/rest.js/issues"},"bundlesize":[{"path":"./dist/octokit-rest.min.js.gz","maxSize":"33 kB"}],"contributors":[{"name":"Mike de Boer","email":"info@mikedeboer.nl"},{"name":"Fabian Jakobs","email":"fabian@c9.io"},{"name":"Joe Gallo","email":"joe@brassafrax.com"},{"name":"Gregor Martynus","url":"https://github.com/gr2m"}],"dependencies":{"@octokit/auth-token":"^2.4.0","@octokit/plugin-paginate-rest":"^1.1.1","@octokit/plugin-request-log":"^1.0.0","@octokit/plugin-rest-endpoint-methods":"2.4.0","@octokit/request":"^5.2.0","@octokit/request-error":"^1.0.2","atob-lite":"^2.0.0","before-after-hook":"^2.0.0","btoa-lite":"^1.0.0","deprecation":"^2.0.0","lodash.get":"^4.4.2","lodash.set":"^4.3.2","lodash.uniq":"^4.5.0","octokit-pagination-methods":"^1.1.0","once":"^1.4.0","universal-user-agent":"^4.0.0"},"description":"GitHub REST API client for Node.js","devDependencies":{"@gimenete/type-writer":"^0.1.3","@octokit/auth":"^1.1.1","@octokit/fixtures-server":"^5.0.6","@octokit/graphql":"^4.2.0","@types/node":"^13.1.0","bundlesize":"^0.18.0","chai":"^4.1.2","compression-webpack-plugin":"^3.1.0","cypress":"^3.0.0","glob":"^7.1.2","http-proxy-agent":"^4.0.0","lodash.camelcase":"^4.3.0","lodash.merge":"^4.6.1","lodash.upperfirst":"^4.3.1","lolex":"^5.1.2","mkdirp":"^1.0.0","mocha":"^7.0.1","mustache":"^4.0.0","nock":"^11.3.3","npm-run-all":"^4.1.2","nyc":"^15.0.0","prettier":"^1.14.2","proxy":"^1.0.0","semantic-release":"^17.0.0","sinon":"^8.0.0","sinon-chai":"^3.0.0","sort-keys":"^4.0.0","string-to-arraybuffer":"^1.0.0","string-to-jsdoc-comment":"^1.0.0","typescript":"^3.3.1","webpack":"^4.0.0","webpack-bundle-analyzer":"^3.0.0","webpack-cli":"^3.0.0"},"files":["index.js","index.d.ts","lib","plugins"],"homepage":"https://github.com/octokit/rest.js#readme","keywords":["octokit","github","rest","api-client"],"license":"MIT","name":"@octokit/rest","nyc":{"ignore":["test"]},"publishConfig":{"access":"public"},"release":{"publish":["@semantic-release/npm",{"path":"@semantic-release/github","assets":["dist/*","!dist/*.map.gz"]}]},"repository":{"type":"git","url":"git+https://github.com/octokit/rest.js.git"},"scripts":{"build":"npm-run-all build:*","build:browser":"npm-run-all build:browser:*","build:browser:development":"webpack --mode development --entry . --output-library=Octokit --output=./dist/octokit-rest.js --profile --json > dist/bundle-stats.json","build:browser:production":"webpack --mode production --entry . --plugin=compression-webpack-plugin --output-library=Octokit --output-path=./dist --output-filename=octokit-rest.min.js --devtool source-map","build:ts":"npm run -s update-endpoints:typescript","coverage":"nyc report --reporter=html && open coverage/index.html","generate-bundle-report":"webpack-bundle-analyzer dist/bundle-stats.json --mode=static --no-open --report dist/bundle-report.html","lint":"prettier --check '{lib,plugins,scripts,test}/**/*.{js,json,ts}' 'docs/*.{js,json}' 'docs/src/**/*' index.js README.md package.json","lint:fix":"prettier --write '{lib,plugins,scripts,test}/**/*.{js,json,ts}' 'docs/*.{js,json}' 'docs/src/**/*' index.js README.md package.json","postvalidate:ts":"tsc --noEmit --target es6 test/typescript-validate.ts","prebuild:browser":"mkdirp dist/","pretest":"npm run -s lint","prevalidate:ts":"npm run -s build:ts","start-fixtures-server":"octokit-fixtures-server","test":"nyc mocha test/mocha-node-setup.js \"test/*/**/*-test.js\"","test:browser":"cypress run --browser chrome","update-endpoints":"npm-run-all update-endpoints:*","update-endpoints:fetch-json":"node scripts/update-endpoints/fetch-json","update-endpoints:typescript":"node scripts/update-endpoints/typescript","validate:ts":"tsc --target es6 --noImplicitAny index.d.ts"},"types":"index.d.ts","version":"16.43.1"}; + +/***/ }), + +/***/ 228: +/***/ (function(module) { + +module.exports = function(md, options) { + options = options || {}; + options.listUnicodeChar = options.hasOwnProperty('listUnicodeChar') ? options.listUnicodeChar : false; + options.stripListLeaders = options.hasOwnProperty('stripListLeaders') ? options.stripListLeaders : true; + options.gfm = options.hasOwnProperty('gfm') ? options.gfm : true; + + var output = md || ''; + + // Remove horizontal rules (stripListHeaders conflict with this rule, which is why it has been moved to the top) + output = output.replace(/^(-\s*?|\*\s*?|_\s*?){3,}\s*$/gm, ''); + + try { + if (options.stripListLeaders) { + if (options.listUnicodeChar) + output = output.replace(/^([\s\t]*)([\*\-\+]|\d+\.)\s+/gm, options.listUnicodeChar + ' $1'); + else + output = output.replace(/^([\s\t]*)([\*\-\+]|\d+\.)\s+/gm, '$1'); + } + if (options.gfm) { + output = output + // Header + .replace(/\n={2,}/g, '\n') + // Strikethrough + .replace(/~~/g, '') + // Fenced codeblocks + .replace(/`{3}.*\n/g, ''); + } + output = output + // Remove HTML tags + .replace(/<[^>]*>/g, '') + // Remove setext-style headers + .replace(/^[=\-]{2,}\s*$/g, '') + // Remove footnotes? + .replace(/\[\^.+?\](\: .*?$)?/g, '') + .replace(/\s{0,2}\[.*?\]: .*?$/g, '') + // Remove images + .replace(/\!\[.*?\][\[\(].*?[\]\)]/g, '') + // Remove inline links + .replace(/\[(.*?)\][\[\(].*?[\]\)]/g, '$1') + // Remove blockquotes + .replace(/^\s{0,3}>\s?/g, '') + // Remove reference-style links? + .replace(/^\s{1,2}\[(.*?)\]: (\S+)( ".*?")?\s*$/g, '') + // Remove atx-style headers + .replace(/^(\n)?\s{0,}#{1,6}\s+| {0,}(\n)?\s{0,}#{0,} {0,}(\n)?\s{0,}$/gm, '$1$2$3') + // Remove emphasis (repeat the line to remove double emphasis) + .replace(/([\*_]{1,3})(\S.*?\S{0,1})\1/g, '$2') + .replace(/([\*_]{1,3})(\S.*?\S{0,1})\1/g, '$2') + // Remove code blocks + .replace(/(`{3,})(.*?)\1/gm, '$2') + // Remove inline code + .replace(/`(.+?)`/g, '$1') + // Replace two or more newlines with exactly two? Not entirely sure this belongs here... + .replace(/\n{2,}/g, '\n\n'); + } catch(e) { + console.error(e); + return md; + } + return output; +}; + /***/ }), @@ -4102,6 +4169,13 @@ exports.paginateRest = paginateRest; //# sourceMappingURL=index.js.map +/***/ }), + +/***/ 304: +/***/ (function(module) { + +module.exports = require("string_decoder"); + /***/ }), /***/ 323: @@ -4976,72 +5050,253 @@ function octokitValidate(octokit) { /***/ (function(__unusedmodule, exports, __webpack_require__) { "use strict"; + +Object.defineProperty(exports, "__esModule", { value: true }); +const os = __webpack_require__(87); +/** + * Commands + * + * Command Format: + * ##[name key=value;key=value]message + * + * Examples: + * ##[warning]This is the user warning message + * ##[set-secret name=mypassword]definatelyNotAPassword! + */ +function issueCommand(command, properties, message) { + const cmd = new Command(command, properties, message); + process.stdout.write(cmd.toString() + os.EOL); +} +exports.issueCommand = issueCommand; +function issue(name, message) { + issueCommand(name, {}, message); +} +exports.issue = issue; +const CMD_PREFIX = '##['; +class Command { + constructor(command, properties, message) { + if (!command) { + command = 'missing.command'; + } + this.command = command; + this.properties = properties; + this.message = message; + } + toString() { + let cmdStr = CMD_PREFIX + this.command; + if (this.properties && Object.keys(this.properties).length > 0) { + cmdStr += ' '; + for (const key in this.properties) { + if (this.properties.hasOwnProperty(key)) { + const val = this.properties[key]; + if (val) { + // safely append the val - avoid blowing up when attempting to + // call .replace() if message is not a string for some reason + cmdStr += `${key}=${escape(`${val || ''}`)};`; + } + } + } + } + cmdStr += ']'; + // safely append the message - avoid blowing up when attempting to + // call .replace() if message is not a string for some reason + const message = `${this.message || ''}`; + cmdStr += escapeData(message); + return cmdStr; + } +} +function escapeData(s) { + return s.replace(/\r/g, '%0D').replace(/\n/g, '%0A'); +} +function escape(s) { + return s + .replace(/\r/g, '%0D') + .replace(/\n/g, '%0A') + .replace(/]/g, '%5D') + .replace(/;/g, '%3B'); +} +//# sourceMappingURL=command.js.map -Object.defineProperty(exports, "__esModule", { value: true }); -const os = __webpack_require__(87); -/** - * Commands - * - * Command Format: - * ##[name key=value;key=value]message - * - * Examples: - * ##[warning]This is the user warning message - * ##[set-secret name=mypassword]definatelyNotAPassword! - */ -function issueCommand(command, properties, message) { - const cmd = new Command(command, properties, message); - process.stdout.write(cmd.toString() + os.EOL); -} -exports.issueCommand = issueCommand; -function issue(name, message) { - issueCommand(name, {}, message); -} -exports.issue = issue; -const CMD_PREFIX = '##['; -class Command { - constructor(command, properties, message) { - if (!command) { - command = 'missing.command'; - } - this.command = command; - this.properties = properties; - this.message = message; +/***/ }), + +/***/ 449: +/***/ (function(module, __unusedexports, __webpack_require__) { + +(function() { + "use strict"; + + var fs = __webpack_require__(747), + StringDecoder = __webpack_require__(304).StringDecoder; + + function LineReader(fd, cb, separator, encoding, bufferSize) { + var filePosition = 0, + encoding = encoding || 'utf8', + separator = separator || '\n', + bufferSize = bufferSize || 1024, + buffer = new Buffer(bufferSize), + bufferStr = '', + decoder = new StringDecoder(encoding), + closed = false, + eof = false, + separatorIndex = -1; + + function close() { + if (!closed) { + fs.close(fd, function(err) { + if (err) { + throw err; + } + }); + closed = true; + } } - toString() { - let cmdStr = CMD_PREFIX + this.command; - if (this.properties && Object.keys(this.properties).length > 0) { - cmdStr += ' '; - for (const key in this.properties) { - if (this.properties.hasOwnProperty(key)) { - const val = this.properties[key]; - if (val) { - // safely append the val - avoid blowing up when attempting to - // call .replace() if message is not a string for some reason - cmdStr += `${key}=${escape(`${val || ''}`)};`; - } - } - } + + function readToSeparator(cb) { + function readChunk() { + fs.read(fd, buffer, 0, bufferSize, filePosition, function(err, bytesRead) { + var separatorAtEnd; + + if (err) { + throw err; + } + + if (bytesRead < bufferSize) { + eof = true; + close(); + } + + filePosition += bytesRead; + + bufferStr += decoder.write(buffer.slice(0, bytesRead)); + + if (separatorIndex < 0) { + separatorIndex = bufferStr.indexOf(separator); + } + + separatorAtEnd = separatorIndex === bufferStr.length - 1; + if (bytesRead && (separatorIndex === -1 || separatorAtEnd) && !eof) { + readChunk(); + } else { + cb(); + } + }); + } + + readChunk(); + } + + function hasNextLine() { + return bufferStr.length > 0 || !eof; + } + + function nextLine(cb) { + function getLine() { + var ret = bufferStr.substring(0, separatorIndex); + + bufferStr = bufferStr.substring(separatorIndex + separator.length); + separatorIndex = -1; + cb(ret); + } + + if (separatorIndex < 0) { + separatorIndex = bufferStr.indexOf(separator); + } + + if (separatorIndex < 0) { + if (eof) { + if (hasNextLine()) { + separatorIndex = bufferStr.length; + getLine(); + } else { + throw new Error('No more lines to read.'); + } + } else { + readToSeparator(getLine); } - cmdStr += ']'; - // safely append the message - avoid blowing up when attempting to - // call .replace() if message is not a string for some reason - const message = `${this.message || ''}`; - cmdStr += escapeData(message); - return cmdStr; + } else { + getLine(); + } } -} -function escapeData(s) { - return s.replace(/\r/g, '%0D').replace(/\n/g, '%0A'); -} -function escape(s) { - return s - .replace(/\r/g, '%0D') - .replace(/\n/g, '%0A') - .replace(/]/g, '%5D') - .replace(/;/g, '%3B'); -} -//# sourceMappingURL=command.js.map + + this.hasNextLine = hasNextLine; + this.nextLine = nextLine; + this.close = close; + + readToSeparator(cb); + } + + function open(filename, cb, separator, encoding, bufferSize) { + fs.open(filename, 'r', parseInt('666', 8), function(err, fd) { + var reader; + if (err) { + throw err; + } + + reader = new LineReader(fd, function() { + cb(reader); + }, separator, encoding, bufferSize); + }); + } + + function eachLine(filename, cb, separator, encoding, bufferSize) { + var finalFn, + asyncCb = cb.length == 3; + + function finish() { + if (finalFn && typeof finalFn === 'function') { + finalFn(); + } + } + + open(filename, function(reader) { + function newRead() { + if (reader.hasNextLine()) { + setImmediate(readNext); + } else { + finish(); + } + } + + function continueCb(continueReading) { + if (continueReading !== false) { + newRead(); + } else { + finish(); + reader.close(); + } + } + + function readNext() { + reader.nextLine(function(line) { + var last = !reader.hasNextLine(); + + if (asyncCb) { + cb(line, last, continueCb); + } else { + if (cb(line, last) !== false) { + newRead(); + } else { + finish(); + reader.close(); + } + } + }); + } + + newRead(); + }, separator, encoding, bufferSize); + + return { + then: function(cb) { + finalFn = cb; + } + }; + } + + module.exports.open = open; + module.exports.eachLine = eachLine; +}()); + /***/ }), @@ -7019,121 +7274,121 @@ exports.GitHub = GitHub; /***/ (function(__unusedmodule, exports, __webpack_require__) { "use strict"; - -Object.defineProperty(exports, "__esModule", { value: true }); -const command_1 = __webpack_require__(431); -const path = __webpack_require__(622); -/** - * The code to exit an action - */ -var ExitCode; -(function (ExitCode) { - /** - * A code indicating that the action was successful - */ - ExitCode[ExitCode["Success"] = 0] = "Success"; - /** - * A code indicating that the action was a failure - */ - ExitCode[ExitCode["Failure"] = 1] = "Failure"; -})(ExitCode = exports.ExitCode || (exports.ExitCode = {})); -//----------------------------------------------------------------------- -// Variables -//----------------------------------------------------------------------- -/** - * sets env variable for this action and future actions in the job - * @param name the name of the variable to set - * @param val the value of the variable - */ -function exportVariable(name, val) { - process.env[name] = val; - command_1.issueCommand('set-env', { name }, val); -} -exports.exportVariable = exportVariable; -/** - * exports the variable and registers a secret which will get masked from logs - * @param name the name of the variable to set - * @param val value of the secret - */ -function exportSecret(name, val) { - exportVariable(name, val); - command_1.issueCommand('set-secret', {}, val); -} -exports.exportSecret = exportSecret; -/** - * Prepends inputPath to the PATH (for this action and future actions) - * @param inputPath - */ -function addPath(inputPath) { - command_1.issueCommand('add-path', {}, inputPath); - process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`; -} -exports.addPath = addPath; -/** - * Gets the value of an input. The value is also trimmed. - * - * @param name name of the input to get - * @param options optional. See InputOptions. - * @returns string - */ -function getInput(name, options) { - const val = process.env[`INPUT_${name.replace(' ', '_').toUpperCase()}`] || ''; - if (options && options.required && !val) { - throw new Error(`Input required and not supplied: ${name}`); - } - return val.trim(); -} -exports.getInput = getInput; -/** - * Sets the value of an output. - * - * @param name name of the output to set - * @param value value to store - */ -function setOutput(name, value) { - command_1.issueCommand('set-output', { name }, value); -} -exports.setOutput = setOutput; -//----------------------------------------------------------------------- -// Results -//----------------------------------------------------------------------- -/** - * Sets the action status to failed. - * When the action exits it will be with an exit code of 1 - * @param message add error issue message - */ -function setFailed(message) { - process.exitCode = ExitCode.Failure; - error(message); -} -exports.setFailed = setFailed; -//----------------------------------------------------------------------- -// Logging Commands -//----------------------------------------------------------------------- -/** - * Writes debug message to user log - * @param message debug message - */ -function debug(message) { - command_1.issueCommand('debug', {}, message); -} -exports.debug = debug; -/** - * Adds an error issue - * @param message error issue message - */ -function error(message) { - command_1.issue('error', message); -} -exports.error = error; -/** - * Adds an warning issue - * @param message warning issue message - */ -function warning(message) { - command_1.issue('warning', message); -} -exports.warning = warning; + +Object.defineProperty(exports, "__esModule", { value: true }); +const command_1 = __webpack_require__(431); +const path = __webpack_require__(622); +/** + * The code to exit an action + */ +var ExitCode; +(function (ExitCode) { + /** + * A code indicating that the action was successful + */ + ExitCode[ExitCode["Success"] = 0] = "Success"; + /** + * A code indicating that the action was a failure + */ + ExitCode[ExitCode["Failure"] = 1] = "Failure"; +})(ExitCode = exports.ExitCode || (exports.ExitCode = {})); +//----------------------------------------------------------------------- +// Variables +//----------------------------------------------------------------------- +/** + * sets env variable for this action and future actions in the job + * @param name the name of the variable to set + * @param val the value of the variable + */ +function exportVariable(name, val) { + process.env[name] = val; + command_1.issueCommand('set-env', { name }, val); +} +exports.exportVariable = exportVariable; +/** + * exports the variable and registers a secret which will get masked from logs + * @param name the name of the variable to set + * @param val value of the secret + */ +function exportSecret(name, val) { + exportVariable(name, val); + command_1.issueCommand('set-secret', {}, val); +} +exports.exportSecret = exportSecret; +/** + * Prepends inputPath to the PATH (for this action and future actions) + * @param inputPath + */ +function addPath(inputPath) { + command_1.issueCommand('add-path', {}, inputPath); + process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`; +} +exports.addPath = addPath; +/** + * Gets the value of an input. The value is also trimmed. + * + * @param name name of the input to get + * @param options optional. See InputOptions. + * @returns string + */ +function getInput(name, options) { + const val = process.env[`INPUT_${name.replace(' ', '_').toUpperCase()}`] || ''; + if (options && options.required && !val) { + throw new Error(`Input required and not supplied: ${name}`); + } + return val.trim(); +} +exports.getInput = getInput; +/** + * Sets the value of an output. + * + * @param name name of the output to set + * @param value value to store + */ +function setOutput(name, value) { + command_1.issueCommand('set-output', { name }, value); +} +exports.setOutput = setOutput; +//----------------------------------------------------------------------- +// Results +//----------------------------------------------------------------------- +/** + * Sets the action status to failed. + * When the action exits it will be with an exit code of 1 + * @param message add error issue message + */ +function setFailed(message) { + process.exitCode = ExitCode.Failure; + error(message); +} +exports.setFailed = setFailed; +//----------------------------------------------------------------------- +// Logging Commands +//----------------------------------------------------------------------- +/** + * Writes debug message to user log + * @param message debug message + */ +function debug(message) { + command_1.issueCommand('debug', {}, message); +} +exports.debug = debug; +/** + * Adds an error issue + * @param message error issue message + */ +function error(message) { + command_1.issue('error', message); +} +exports.error = error; +/** + * Adds an warning issue + * @param message warning issue message + */ +function warning(message) { + command_1.issue('warning', message); +} +exports.warning = warning; //# sourceMappingURL=core.js.map /***/ }), @@ -8547,6 +8802,214 @@ module.exports = (promise, onFinally) => { }; +/***/ }), + +/***/ 734: +/***/ (function(module, __unusedexports, __webpack_require__) { + +var EOL = __webpack_require__(87).EOL +var lineReader = __webpack_require__(449) +var removeMarkdown = __webpack_require__(228) + +// patterns +var semver = /\[?v?([\w\d.-]+\.[\w\d.-]+[a-zA-Z0-9])\]?/ +var date = /.*[ ](\d\d?\d?\d?[-/.]\d\d?[-/.]\d\d?\d?\d?).*/ +var subhead = /^###/ +var listitem = /^[*-]/ + +var defaultOptions = { removeMarkdown: true } + +/** + * Changelog parser. + * + * @param {string|object} options - changelog file string or options object containing file string + * @param {string} [options.filePath] - path to changelog file + * @param {string} [options.text] - changelog text (filePath alternative) + * @param {boolean} [options.removeMarkdown=true] - changelog file string to parse + * @param {function} [callback] - optional callback + * @returns {Promise} - parsed changelog object + */ +function parseChangelog (options, callback) { + if (typeof options === 'undefined') throw new Error('missing options argument') + if (typeof options === 'string') options = { filePath: options } + if (typeof options === 'object') { + var hasFilePath = typeof options.filePath !== 'undefined' + var hasText = typeof options.text !== 'undefined' + var invalidFilePath = typeof options.filePath !== 'string' + var invalidText = typeof options.text !== 'string' + + if (!hasFilePath && !hasText) { + throw new Error('must provide filePath or text') + } + + if (hasFilePath && invalidFilePath) { + throw new Error('invalid filePath, expected string') + } + + if (hasText && invalidText) { + throw new Error('invalid text, expected string') + } + } + + var opts = Object.assign({}, defaultOptions, options) + var changelog = parse(opts) + + if (typeof callback === 'function') { + changelog + .then(function (log) { callback(null, log) }) + .catch(function (err) { callback(err) }) + } + + // otherwise, invoke callback + return changelog +} + +/** + * Internal parsing logic. + * + * @param {options} options - options object + * @param {string} [options.filePath] - path to changelog file + * @param {string} [options.text] - changelog text (filePath alternative) + * @param {boolean} [options.removeMarkdown] - remove markdown + * @returns {Promise} - parsed changelog object + */ +function parse (options) { + var filePath = options.filePath + var text = options.text + var data = { + log: { versions: [] }, + current: null + } + + // allow `handleLine` to mutate log/current data as `this`. + var cb = handleLine.bind(data, options) + + return new Promise(function (resolve, reject) { + function done () { + // push last version into log + if (data.current) { + pushCurrent(data) + } + + // clean up description + data.log.description = clean(data.log.description) + if (data.log.description === '') delete data.log.description + + resolve(data.log) + } + + if (text) { + text.split(/\r\n?|\n/mg).forEach(cb) + done() + } else { + lineReader.eachLine(filePath, cb, EOL).then(done) + } + }) +} + +/** + * Handles each line and mutates data object (bound to `this`) as needed. + * + * @param {object} options - options object + * @param {boolean} options.removeMarkdown - whether or not to remove markdown + * @param {string} line - line from changelog file + */ +function handleLine (options, line) { + // skip line if it's a link label + if (line.match(/^\[[^[\]]*\] *?:/)) return + + // set title if it's there + if (!this.log.title && line.match(/^# ?[^#]/)) { + this.log.title = line.substring(1).trim() + return + } + + // new version found! + if (line.match(/^##? ?[^#]/)) { + if (this.current && this.current.title) pushCurrent(this) + + this.current = versionFactory() + + if (semver.exec(line)) this.current.version = semver.exec(line)[1] + + this.current.title = line.substring(2).trim() + + if (this.current.title && date.exec(this.current.title)) this.current.date = date.exec(this.current.title)[1] + + return + } + + // deal with body or description content + if (this.current) { + this.current.body += line + EOL + + // handle case where current line is a 'subhead': + // - 'handleize' subhead. + // - add subhead to 'parsed' data if not already present. + if (subhead.exec(line)) { + var key = line.replace('###', '').trim() + + if (!this.current.parsed[key]) { + this.current.parsed[key] = [] + this.current._private.activeSubhead = key + } + } + + // handle case where current line is a 'list item': + if (listitem.exec(line)) { + const log = options.removeMarkdown ? removeMarkdown(line) : line + // add line to 'catch all' array + this.current.parsed._.push(log) + + // add line to 'active subhead' if applicable (eg. 'Added', 'Changed', etc.) + if (this.current._private.activeSubhead) { + this.current.parsed[this.current._private.activeSubhead].push(log) + } + } + } else { + this.log.description = (this.log.description || '') + line + EOL + } +} + +function versionFactory () { + return { + version: null, + title: null, + date: null, + body: '', + parsed: { + _: [] + }, + _private: { + activeSubhead: null + } + } +} + +function pushCurrent (data) { + // remove private properties + delete data.current._private + + data.current.body = clean(data.current.body) + data.log.versions.push(data.current) +} + +function clean (str) { + if (!str) return '' + + // trim + str = str.trim() + // remove leading newlines + str = str.replace(new RegExp('[' + EOL + ']*'), '') + // remove trailing newlines + str = str.replace(new RegExp('[' + EOL + ']*$'), '') + + return str +} + +module.exports = parseChangelog + + /***/ }), /***/ 742: @@ -8782,6 +9245,21 @@ exports.request = request; const core = __webpack_require__(470); const { GitHub, context } = __webpack_require__(469); const fs = __webpack_require__(747); +const parseChangelog = __webpack_require__(734); + +function getChangelogVersionInfo(filename) { + parseChangelog(filename) + .then(result => { + if (result && result.versions && result.versions.length > 0) { + return result.versions[0]; + } + return null; + }) + .catch(err => { + console.log(err); + return null; + }); +} async function run() { try { @@ -8812,15 +9290,27 @@ async function run() { } } + const changelogPath = core.getInput('changelog_path', { required: false }); + let changelogBody = null; + let changelogTag = null; + if (changelogPath !== '' && !!changelogPath) { + const versionInfo = getChangelogVersionInfo(changelogPath); + console.log(versionInfo); + if (versionInfo) { + changelogBody = versionInfo.body; + changelogTag = `v${versionInfo.version}`; + } + } + // Create a release // API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release // Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-create-release const createReleaseResponse = await github.repos.createRelease({ owner, repo, - tag_name: tag, + tag_name: changelogTag || tag, name: releaseName, - body: bodyFileContent || body, + body: bodyFileContent || changelogBody || body, draft, prerelease, target_commitish: commitish diff --git a/package-lock.json b/package-lock.json index fcfaa592..e01a2ce9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1245,6 +1245,15 @@ "supports-color": "^5.3.0" } }, + "changelog-parser": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/changelog-parser/-/changelog-parser-2.8.0.tgz", + "integrity": "sha512-ZtSwN0hY7t+WpvaXqqXz98RHCNhWX9HsvCRAv1aBLlqJ7BpKtqdM6Nu6JOiUhRAWR7Gov0aN0fUnmflTz0WgZg==", + "requires": { + "line-reader": "^0.2.4", + "remove-markdown": "^0.2.2" + } + }, "chardet": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", @@ -4330,6 +4339,11 @@ "type-check": "~0.3.2" } }, + "line-reader": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/line-reader/-/line-reader-0.2.4.tgz", + "integrity": "sha1-xDkrWH3qOFgMlnhXDm6OSfzlJiI=" + }, "lines-and-columns": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.1.6.tgz", @@ -5061,9 +5075,9 @@ "dev": true }, "prettier": { - "version": "1.18.2", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.18.2.tgz", - "integrity": "sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw==", + "version": "1.19.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", + "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", "dev": true }, "pretty-format": { @@ -5198,6 +5212,11 @@ "integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==", "dev": true }, + "remove-markdown": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/remove-markdown/-/remove-markdown-0.2.2.tgz", + "integrity": "sha1-ZrDO66n7d8qWNrsbAwfOIaMqEqY=" + }, "remove-trailing-separator": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz", diff --git a/package.json b/package.json index 176a6bdf..e04b244c 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "dependencies": { "@actions/core": "^1.0.0", "@actions/exec": "^1.0.0", - "@actions/github": "^2.2.0" + "@actions/github": "^2.2.0", + "changelog-parser": "^2.8.0" }, "devDependencies": { "@zeit/ncc": "^0.20.4", @@ -33,9 +34,9 @@ "eslint-plugin-jsx-a11y": "^6.2.1", "eslint-plugin-prettier": "^2.7.0", "eslint-plugin-react": "^7.12.4", + "husky": "^3.0.5", "jest": "^24.8.0", - "prettier": "^1.16.4", - "husky": "^3.0.5" + "prettier": "1.19.1" }, "jest": { "testEnvironment": "node", diff --git a/src/create-release.js b/src/create-release.js index 98d0b397..c8b47140 100644 --- a/src/create-release.js +++ b/src/create-release.js @@ -1,6 +1,21 @@ const core = require('@actions/core'); const { GitHub, context } = require('@actions/github'); const fs = require('fs'); +const parseChangelog = require('changelog-parser'); + +function getChangelogVersionInfo(filename) { + parseChangelog(filename) + .then(result => { + if (result && result.versions && result.versions.length > 0) { + return result.versions[0]; + } + return null; + }) + .catch(err => { + console.log(err); + return null; + }); +} async function run() { try { @@ -31,15 +46,27 @@ async function run() { } } + const changelogPath = core.getInput('changelog_path', { required: false }); + let changelogBody = null; + let changelogTag = null; + if (changelogPath !== '' && !!changelogPath) { + const versionInfo = getChangelogVersionInfo(changelogPath); + console.log(versionInfo); + if (versionInfo) { + changelogBody = versionInfo.body; + changelogTag = `v${versionInfo.version}`; + } + } + // Create a release // API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release // Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-create-release const createReleaseResponse = await github.repos.createRelease({ owner, repo, - tag_name: tag, + tag_name: changelogTag || tag, name: releaseName, - body: bodyFileContent || body, + body: bodyFileContent || changelogBody || body, draft, prerelease, target_commitish: commitish diff --git a/tests/create-release.test.js b/tests/create-release.test.js index 7b7df422..286d2b3e 100644 --- a/tests/create-release.test.js +++ b/tests/create-release.test.js @@ -6,6 +6,7 @@ const core = require('@actions/core'); const { GitHub, context } = require('@actions/github'); const fs = require('fs'); const run = require('../src/create-release.js'); +const parseChangelog = require('changelog-parser'); /* eslint-disable no-undef */ describe('Create Release', () => { @@ -154,6 +155,34 @@ describe('Create Release', () => { }); }); + test('Release tag and body based on changelog', async () => { + core.getInput = jest + .fn() + .mockReturnValueOnce('refs/tags/v1.0.0') + .mockReturnValueOnce('myRelease') + .mockReturnValueOnce('') // <-- The default value for body in action.yml + .mockReturnValueOnce('false') + .mockReturnValueOnce('false') + .mockReturnValueOnce(null) + .mockReturnValueOnce('') + .mockReturnValueOnce('CHANGELOG.md'); + + parseChangelog = jest.fn().mockReturnValueOnce({version: '0.4.1', body: '### Changed\n\n- Automate github releases'}); + + await run(); + + expect(createRelease).toHaveBeenCalledWith({ + owner: 'owner', + repo: 'repo', + tag_name: 'v0.4.1', + name: 'myRelease', + body: '### Changed\n\n- Automate github releases', + draft: false, + prerelease: false, + target_commitish: 'sha' + }); + }); + test('Outputs are set', async () => { core.getInput = jest .fn() From 654dc1a90d29fa6fd1756749851521373b99658e Mon Sep 17 00:00:00 2001 From: Marc Coury Date: Wed, 26 Aug 2020 10:58:21 +0100 Subject: [PATCH 2/6] A bit more progress --- dist/index.js | 5 ++++- src/create-release.js | 5 ++++- tests/create-release.test.js | 6 ++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 01cba4f8..7b8c69e8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9291,16 +9291,19 @@ async function run() { } const changelogPath = core.getInput('changelog_path', { required: false }); + console.log('changelogPath = ', changelogPath); let changelogBody = null; let changelogTag = null; if (changelogPath !== '' && !!changelogPath) { const versionInfo = getChangelogVersionInfo(changelogPath); - console.log(versionInfo); + console.log('versionInfo = ', versionInfo); if (versionInfo) { changelogBody = versionInfo.body; changelogTag = `v${versionInfo.version}`; } } + console.log('changelogBody = ', changelogBody); + console.log('changelogTag = ', changelogTag); // Create a release // API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release diff --git a/src/create-release.js b/src/create-release.js index c8b47140..a5bc94ce 100644 --- a/src/create-release.js +++ b/src/create-release.js @@ -47,16 +47,19 @@ async function run() { } const changelogPath = core.getInput('changelog_path', { required: false }); + console.log('changelogPath = ', changelogPath); let changelogBody = null; let changelogTag = null; if (changelogPath !== '' && !!changelogPath) { const versionInfo = getChangelogVersionInfo(changelogPath); - console.log(versionInfo); + console.log('versionInfo = ', versionInfo); if (versionInfo) { changelogBody = versionInfo.body; changelogTag = `v${versionInfo.version}`; } } + console.log('changelogBody = ', changelogBody); + console.log('changelogTag = ', changelogTag); // Create a release // API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release diff --git a/tests/create-release.test.js b/tests/create-release.test.js index 286d2b3e..fba4d87b 100644 --- a/tests/create-release.test.js +++ b/tests/create-release.test.js @@ -1,12 +1,12 @@ jest.mock('@actions/core'); jest.mock('@actions/github'); jest.mock('fs'); +jest.mock('changelog-parser'); const core = require('@actions/core'); const { GitHub, context } = require('@actions/github'); const fs = require('fs'); const run = require('../src/create-release.js'); -const parseChangelog = require('changelog-parser'); /* eslint-disable no-undef */ describe('Create Release', () => { @@ -167,7 +167,9 @@ describe('Create Release', () => { .mockReturnValueOnce('') .mockReturnValueOnce('CHANGELOG.md'); - parseChangelog = jest.fn().mockReturnValueOnce({version: '0.4.1', body: '### Changed\n\n- Automate github releases'}); + parseChangelog = jest + .fn() + .mockReturnValueOnce({ versions: [{ version: '0.4.1', body: '### Changed\n\n- Automate github releases' }] }); await run(); From de4994210692d0aea1b324b0acf63cddef9c2d31 Mon Sep 17 00:00:00 2001 From: Marc Coury Date: Wed, 26 Aug 2020 12:06:54 +0100 Subject: [PATCH 3/6] Fix it --- dist/index.js | 32 +++++++++++++++----------------- src/create-release.js | 32 +++++++++++++++----------------- tests/create-release.test.js | 8 +++----- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7b8c69e8..3bbb183e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9247,18 +9247,19 @@ const { GitHub, context } = __webpack_require__(469); const fs = __webpack_require__(747); const parseChangelog = __webpack_require__(734); -function getChangelogVersionInfo(filename) { - parseChangelog(filename) - .then(result => { - if (result && result.versions && result.versions.length > 0) { - return result.versions[0]; - } - return null; - }) - .catch(err => { - console.log(err); - return null; - }); +async function getChangelogVersionInfo(filename) { + try { + const result = await parseChangelog(filename); + + if (result && result.versions && result.versions.length > 0) { + return result.versions[0]; + } + + return null; + } catch (e) { + console.log(e); + return null; + } } async function run() { @@ -9291,19 +9292,16 @@ async function run() { } const changelogPath = core.getInput('changelog_path', { required: false }); - console.log('changelogPath = ', changelogPath); + let changelogBody = null; let changelogTag = null; if (changelogPath !== '' && !!changelogPath) { - const versionInfo = getChangelogVersionInfo(changelogPath); - console.log('versionInfo = ', versionInfo); + const versionInfo = await getChangelogVersionInfo(changelogPath); if (versionInfo) { changelogBody = versionInfo.body; changelogTag = `v${versionInfo.version}`; } } - console.log('changelogBody = ', changelogBody); - console.log('changelogTag = ', changelogTag); // Create a release // API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release diff --git a/src/create-release.js b/src/create-release.js index a5bc94ce..5243531d 100644 --- a/src/create-release.js +++ b/src/create-release.js @@ -3,18 +3,19 @@ const { GitHub, context } = require('@actions/github'); const fs = require('fs'); const parseChangelog = require('changelog-parser'); -function getChangelogVersionInfo(filename) { - parseChangelog(filename) - .then(result => { - if (result && result.versions && result.versions.length > 0) { - return result.versions[0]; - } - return null; - }) - .catch(err => { - console.log(err); - return null; - }); +async function getChangelogVersionInfo(filename) { + try { + const result = await parseChangelog(filename); + + if (result && result.versions && result.versions.length > 0) { + return result.versions[0]; + } + + return null; + } catch (e) { + console.log(e); + return null; + } } async function run() { @@ -47,19 +48,16 @@ async function run() { } const changelogPath = core.getInput('changelog_path', { required: false }); - console.log('changelogPath = ', changelogPath); + let changelogBody = null; let changelogTag = null; if (changelogPath !== '' && !!changelogPath) { - const versionInfo = getChangelogVersionInfo(changelogPath); - console.log('versionInfo = ', versionInfo); + const versionInfo = await getChangelogVersionInfo(changelogPath); if (versionInfo) { changelogBody = versionInfo.body; changelogTag = `v${versionInfo.version}`; } } - console.log('changelogBody = ', changelogBody); - console.log('changelogTag = ', changelogTag); // Create a release // API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release diff --git a/tests/create-release.test.js b/tests/create-release.test.js index fba4d87b..ca2bfd01 100644 --- a/tests/create-release.test.js +++ b/tests/create-release.test.js @@ -1,7 +1,8 @@ jest.mock('@actions/core'); jest.mock('@actions/github'); jest.mock('fs'); -jest.mock('changelog-parser'); +jest.mock('changelog-parser', () => jest.fn().mockReturnValue({ versions: [{ version: '0.4.1', body: '### Changed\n\n- Automate github releases' }] })); + const core = require('@actions/core'); const { GitHub, context } = require('@actions/github'); @@ -156,6 +157,7 @@ describe('Create Release', () => { }); test('Release tag and body based on changelog', async () => { + core.getInput = jest .fn() .mockReturnValueOnce('refs/tags/v1.0.0') @@ -167,10 +169,6 @@ describe('Create Release', () => { .mockReturnValueOnce('') .mockReturnValueOnce('CHANGELOG.md'); - parseChangelog = jest - .fn() - .mockReturnValueOnce({ versions: [{ version: '0.4.1', body: '### Changed\n\n- Automate github releases' }] }); - await run(); expect(createRelease).toHaveBeenCalledWith({ From da23c049a4f0307492193587adb75ef22774bc44 Mon Sep 17 00:00:00 2001 From: Marc Coury Date: Wed, 26 Aug 2020 12:11:35 +0100 Subject: [PATCH 4/6] fix linting --- dist/index.js | 2 -- src/create-release.js | 2 -- tests/create-release.test.js | 6 +++--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/dist/index.js b/dist/index.js index 3bbb183e..ba8ccdf4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9250,14 +9250,12 @@ const parseChangelog = __webpack_require__(734); async function getChangelogVersionInfo(filename) { try { const result = await parseChangelog(filename); - if (result && result.versions && result.versions.length > 0) { return result.versions[0]; } return null; } catch (e) { - console.log(e); return null; } } diff --git a/src/create-release.js b/src/create-release.js index 5243531d..5cc0e233 100644 --- a/src/create-release.js +++ b/src/create-release.js @@ -6,14 +6,12 @@ const parseChangelog = require('changelog-parser'); async function getChangelogVersionInfo(filename) { try { const result = await parseChangelog(filename); - if (result && result.versions && result.versions.length > 0) { return result.versions[0]; } return null; } catch (e) { - console.log(e); return null; } } diff --git a/tests/create-release.test.js b/tests/create-release.test.js index ca2bfd01..90afab6d 100644 --- a/tests/create-release.test.js +++ b/tests/create-release.test.js @@ -1,8 +1,9 @@ jest.mock('@actions/core'); jest.mock('@actions/github'); jest.mock('fs'); -jest.mock('changelog-parser', () => jest.fn().mockReturnValue({ versions: [{ version: '0.4.1', body: '### Changed\n\n- Automate github releases' }] })); - +jest.mock('changelog-parser', () => + jest.fn().mockReturnValue({ versions: [{ version: '0.4.1', body: '### Changed\n\n- Automate github releases' }] }) +); const core = require('@actions/core'); const { GitHub, context } = require('@actions/github'); @@ -157,7 +158,6 @@ describe('Create Release', () => { }); test('Release tag and body based on changelog', async () => { - core.getInput = jest .fn() .mockReturnValueOnce('refs/tags/v1.0.0') From 47d34036bd20d02c784684d465078a6a3e09dcf8 Mon Sep 17 00:00:00 2001 From: Marc Coury Date: Wed, 26 Aug 2020 12:14:40 +0100 Subject: [PATCH 5/6] make package.json same as before --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e04b244c..02448cc9 100644 --- a/package.json +++ b/package.json @@ -34,9 +34,9 @@ "eslint-plugin-jsx-a11y": "^6.2.1", "eslint-plugin-prettier": "^2.7.0", "eslint-plugin-react": "^7.12.4", - "husky": "^3.0.5", "jest": "^24.8.0", - "prettier": "1.19.1" + "prettier": "^1.16.4", + "husky": "^3.0.5" }, "jest": { "testEnvironment": "node", From a03700657b33455240f5e5867f6e1f8d276b7823 Mon Sep 17 00:00:00 2001 From: Marc Coury Date: Wed, 26 Aug 2020 12:28:02 +0100 Subject: [PATCH 6/6] Update the readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 93486e3e..70be570e 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,14 @@ For more information on these inputs, see the [API Documentation](https://develo - `body_path`: A file with contents describing the release. Optional, and not needed if using `body`. - `draft`: `true` to create a draft (unpublished) release, `false` to create a published one. Default: `false` - `prerelease`: `true` to identify the release as a prerelease. `false` to identify the release as a full release. Default `false` +- `changelog_path`: Sets the tag to the latest version found in the changelog file and sets the body to the content of the latest change. Optional, and not needed if using `tag_name` and `body`. #### `body_path` The `body_path` is valuable for dynamically creating a `.md` within code commits and even within the Github Action steps leading up to the `create-release`. +#### `changelog_path` +The `changelog_path` is valuable for creating a release based on the latest change in the changelog. The tag is set to the version of the latest change with a v in front, e.g. `v{latest_version}`. The version is expected to be [semver](http://semver.org/) compliant. The body is set to the contents of the latest change in the changelog. The changelog parser works on changelogs that follow the format laid out in: https://keepachangelog.com/en/1.0.0/, the underlying library is (changelog-parser)[https://www.npmjs.com/package/changelog-parser]. + ### Outputs For more information on these outputs, see the [API Documentation](https://developer.github.com/v3/repos/releases/#response-4) for an example of what these outputs look like