-
-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci): add an action to create a release PR;
- Loading branch information
1 parent
abd2cb8
commit 8651bf1
Showing
5 changed files
with
229 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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,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', | ||
} | ||
})); | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}} |