2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00

chore(ci): add an action to create a release PR;

This commit is contained in:
Dmitriy Mozgovoy
2023-01-06 01:50:31 +02:00
committed by GitHub
parent abd2cb83a3
commit 8651bf17d4
5 changed files with 229 additions and 23 deletions
+73
View File
@@ -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
+75
View File
@@ -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',
}
}));
+66 -22
View File
@@ -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",
+3 -1
View File
@@ -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"
]
}
}
}
+12
View File
@@ -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}}