diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000000..bb766f359d --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,73 @@ +name: Release PR +on: + workflow_dispatch: + inputs: + type: + type: choice + description: Choose release type + options: + - auto + - patch + - minor + - major + default: auto + beta: + type: boolean + description: Prerelease + default: false +jobs: + releaseIt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: git config + run: | + git config user.name "${GITHUB_ACTOR}" + git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: 16 + cache: npm + - name: npm credentials + run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN + - run: npm install + - name: release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TYPE_ARG: ${{ fromJSON('{"auto":"", "patch":"--patch", "minor":"--minor", "major":"--major"}')[github.event.inputs.type] }} + BETA_ARG: ${{ github.event.inputs.beta == 'true' && '--preRelease=beta' || '' }} + run: npm run release -- --ci --verbose $TYPE_ARG $BETA_ARG + - name: get-npm-version + id: package-version + uses: martinbeentjes/npm-get-version-action@main + - name: Extract release notes + id: extract-release-notes + uses: ffurrer2/extract-release-notes@v1 + - name: Generate PR body + id: body + uses: mathiasvr/command-output@v1 + with: + run: node ./bin/pr.js + - name: Create pull request + uses: peter-evans/create-pull-request@v4 + with: + branch: release + delete-branch: true + title: '[Release] v${{ steps.package-version.outputs.current-version}}' + body: | + ${{ steps.body.outputs.stdout }} + ## Release notes: + ${{ steps.extract-release-notes.outputs.release_notes }} + labels: | + release + automated pr + signoff: false + team-reviewers: | + owners + maintainers + #assignees: jasonsaayman + #reviewers: jasonsaayman + draft: true diff --git a/bin/pr.js b/bin/pr.js new file mode 100644 index 0000000000..4a6db09923 --- /dev/null +++ b/bin/pr.js @@ -0,0 +1,75 @@ +import util from "util"; +import cp from "child_process"; +import Handlebars from "handlebars"; +import fs from "fs/promises"; +import prettyBytes from 'pretty-bytes'; +import {gzipSize} from 'gzip-size'; + +const exec = util.promisify(cp.exec); + +const getBlobHistory = async (filepath, maxCount= 5) => { + const log = (await exec( + `git log --max-count=${maxCount} --no-walk --tags=v* --oneline --format=%H%d -- ${filepath}` + )).stdout; + + const commits = []; + + let match; + + const regexp = /^(\w+) \(tag: (v?[.\d]+)\)$/gm; + + while((match = regexp.exec(log))) { + commits.push({ + sha: match[1], + tag: match[2], + size: await getBlobSize(filepath, match[1]) + }) + } + + return commits; +} + +const getBlobSize = async (filepath, sha ='HEAD') => { + const size = (await exec( + `git cat-file -s ${sha}:${filepath}` + )).stdout; + + return size ? +size : 0; +} + +const generateFileReport = async (files) => { + const stat = {}; + + for(const [name, file] of Object.entries(files)) { + const commits = await getBlobHistory(file); + + stat[file] = { + name, + size: (await fs.stat(file)).size, + path: file, + gzip: await gzipSize(String(await fs.readFile(file))), + commits, + history: commits.map(({tag, size}) => `${prettyBytes(size)} (${tag})`).join(' ← ') + } + } + + return stat; +} + +const generateBody = async ({files, template = './templates/pr.hbs'} = {}) => { + const data = { + files: await generateFileReport(files) + }; + + Handlebars.registerHelper('filesize', (bytes)=> prettyBytes(bytes)); + + return Handlebars.compile(String(await fs.readFile(template)))(data); +} + +console.log(await generateBody({ + files: { + 'Browser build (UMD)' : './dist/axios.min.js', + 'Browser build (ESM)' : './dist/esm/axios.min.js', + } +})); + diff --git a/package-lock.json b/package-lock.json index 222092dcd3..f47f460cba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "axios", - "version": "1.2.1", + "version": "1.2.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "axios", - "version": "1.2.1", + "version": "1.2.2", "license": "MIT", "dependencies": { "follow-redirects": "^1.15.0", @@ -38,6 +38,7 @@ "fs-extra": "^10.1.0", "get-stream": "^3.0.0", "gulp": "^4.0.2", + "gzip-size": "^7.0.0", "handlebars": "^4.7.7", "husky": "^8.0.2", "istanbul-instrumenter-loader": "^3.0.1", @@ -55,6 +56,7 @@ "minimist": "^1.2.7", "mocha": "^10.0.0", "multer": "^1.4.4", + "pretty-bytes": "^6.0.0", "release-it": "^15.5.1", "rollup": "^2.67.0", "rollup-plugin-auto-external": "^2.0.0", @@ -8803,9 +8805,9 @@ } }, "node_modules/duplexer": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", - "integrity": "sha512-sxNZ+ljy+RA1maXoUReeqBBpBC6RLKmg5ewzV+x+mSETmWNoKdZN6vcQjpFROemza23hGFskJtFNoUWUaQ+R4Q==", + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.2.tgz", + "integrity": "sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg==", "dev": true }, "node_modules/duplexer3": { @@ -12241,6 +12243,21 @@ "node": ">= 0.10" } }, + "node_modules/gzip-size": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/gzip-size/-/gzip-size-7.0.0.tgz", + "integrity": "sha512-O1Ld7Dr+nqPnmGpdhzLmMTQ4vAsD+rHwMm1NLUmoUFFymBOMKxCCrtDxqdBRYXdeEPEi3SyoR4TizJLQrnKBNA==", + "dev": true, + "dependencies": { + "duplexer": "^0.1.2" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/handlebars": { "version": "4.7.7", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.7.tgz", @@ -15007,6 +15024,18 @@ "node": ">=0.12.0" } }, + "node_modules/maxmin/node_modules/pretty-bytes": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-3.0.1.tgz", + "integrity": "sha512-eb7ZAeUTgfh294cElcu51w+OTRp/6ItW758LjwJSK72LDevcuJn0P4eD71PLMDGPwwatXmAmYHTkzvpKlJE3ow==", + "dev": true, + "dependencies": { + "number-is-nan": "^1.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/md5.js": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", @@ -17835,15 +17864,15 @@ } }, "node_modules/pretty-bytes": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-3.0.1.tgz", - "integrity": "sha512-eb7ZAeUTgfh294cElcu51w+OTRp/6ItW758LjwJSK72LDevcuJn0P4eD71PLMDGPwwatXmAmYHTkzvpKlJE3ow==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-6.0.0.tgz", + "integrity": "sha512-6UqkYefdogmzqAZWzJ7laYeJnaXDy2/J+ZqiiMtS7t7OfpXWTlaeGMwX8U6EFvPV/YWWEKRkS8hKS4k60WHTOg==", "dev": true, - "dependencies": { - "number-is-nan": "^1.0.0" - }, "engines": { - "node": ">=0.10.0" + "node": "^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/pretty-hrtime": { @@ -30851,9 +30880,9 @@ } }, "duplexer": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", - "integrity": "sha512-sxNZ+ljy+RA1maXoUReeqBBpBC6RLKmg5ewzV+x+mSETmWNoKdZN6vcQjpFROemza23hGFskJtFNoUWUaQ+R4Q==", + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.2.tgz", + "integrity": "sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg==", "dev": true }, "duplexer3": { @@ -33683,6 +33712,15 @@ "glogg": "^1.0.0" } }, + "gzip-size": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/gzip-size/-/gzip-size-7.0.0.tgz", + "integrity": "sha512-O1Ld7Dr+nqPnmGpdhzLmMTQ4vAsD+rHwMm1NLUmoUFFymBOMKxCCrtDxqdBRYXdeEPEi3SyoR4TizJLQrnKBNA==", + "dev": true, + "requires": { + "duplexer": "^0.1.2" + } + }, "handlebars": { "version": "4.7.7", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.7.tgz", @@ -35797,6 +35835,15 @@ "requires": { "duplexer": "^0.1.1" } + }, + "pretty-bytes": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-3.0.1.tgz", + "integrity": "sha512-eb7ZAeUTgfh294cElcu51w+OTRp/6ItW758LjwJSK72LDevcuJn0P4eD71PLMDGPwwatXmAmYHTkzvpKlJE3ow==", + "dev": true, + "requires": { + "number-is-nan": "^1.0.0" + } } } }, @@ -38037,13 +38084,10 @@ "dev": true }, "pretty-bytes": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-3.0.1.tgz", - "integrity": "sha512-eb7ZAeUTgfh294cElcu51w+OTRp/6ItW758LjwJSK72LDevcuJn0P4eD71PLMDGPwwatXmAmYHTkzvpKlJE3ow==", - "dev": true, - "requires": { - "number-is-nan": "^1.0.0" - } + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-6.0.0.tgz", + "integrity": "sha512-6UqkYefdogmzqAZWzJ7laYeJnaXDy2/J+ZqiiMtS7t7OfpXWTlaeGMwX8U6EFvPV/YWWEKRkS8hKS4k60WHTOg==", + "dev": true }, "pretty-hrtime": { "version": "1.0.3", diff --git a/package.json b/package.json index 6677081617..ead5298ed8 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "fs-extra": "^10.1.0", "get-stream": "^3.0.0", "gulp": "^4.0.2", + "gzip-size": "^7.0.0", "handlebars": "^4.7.7", "husky": "^8.0.2", "istanbul-instrumenter-loader": "^3.0.1", @@ -109,6 +110,7 @@ "minimist": "^1.2.7", "mocha": "^10.0.0", "multer": "^1.4.4", + "pretty-bytes": "^6.0.0", "release-it": "^15.5.1", "rollup": "^2.67.0", "rollup-plugin-auto-external": "^2.0.0", @@ -186,4 +188,4 @@ "@commitlint/config-conventional" ] } -} \ No newline at end of file +} diff --git a/templates/pr.hbs b/templates/pr.hbs new file mode 100644 index 0000000000..7fb0f5ab7a --- /dev/null +++ b/templates/pr.hbs @@ -0,0 +1,12 @@ +{{#if files}} + + ### Build info + + {{#each files}} + - {{ name}} ({{ path }}) {{ filesize size }} ({{ filesize gzip }} gzipped) + {{#each commits}} + - {{ tag }} - {{filesize size}} + {{/each}} + {{/each}} + +{{/if}}