mirror of
https://github.com/tenrok/axios.git
synced 2026-05-15 11:59:42 +03:00
chore(ci): add tag resolution for npm releases based on package version; (#6404)
This commit is contained in:
@@ -42,6 +42,10 @@ jobs:
|
||||
id: tag_version
|
||||
with:
|
||||
tag: "v${{ steps.package-version.outputs.current-version }}"
|
||||
############# RESOLVE NPM TAG ##############
|
||||
- name: NPM TAG
|
||||
id: 'npm_tag'
|
||||
run: node ./bin/resolveNPMTag.js
|
||||
############# GITHUB RELEASE ##############
|
||||
- name: "Create a GitHub release v${{ steps.package-version.outputs.current-version }}"
|
||||
uses: ncipollo/release-action@v1
|
||||
@@ -53,7 +57,7 @@ jobs:
|
||||
${{ steps.extract-release-notes.outputs.release_notes }}
|
||||
############# NPM RELEASE ##############
|
||||
- name: Publish the release to NPM
|
||||
run: npm publish --provenance --access public
|
||||
run: npm publish --provenance --access public --tag ${{ steps.npm_tag.outputs.tag || 'latest' }}
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
||||
notify:
|
||||
|
||||
@@ -1,41 +1,8 @@
|
||||
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;
|
||||
}
|
||||
import {getBlobHistory} from './repo.js';
|
||||
|
||||
const generateFileReport = async (files) => {
|
||||
const stat = {};
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
import util from "util";
|
||||
import cp from "child_process";
|
||||
|
||||
export const exec = util.promisify(cp.exec);
|
||||
|
||||
export const getBlobSize = async (filepath, sha ='HEAD') => {
|
||||
const size = (await exec(
|
||||
`git cat-file -s ${sha}:${filepath}`
|
||||
)).stdout;
|
||||
|
||||
return size ? +size : 0;
|
||||
}
|
||||
|
||||
export 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;
|
||||
}
|
||||
|
||||
export const getTags = async (pattern = 'v*', sort = '-v:refname') => {
|
||||
const log = (await exec(
|
||||
`git tag -l ${pattern} --sort=${sort}`
|
||||
)).stdout;
|
||||
|
||||
return log.split(/\r?\n/);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import {exec, getTags} from "./repo.js";
|
||||
import fs from "fs";
|
||||
import {colorize} from "./helpers/colorize.js";
|
||||
|
||||
const {version} = JSON.parse(fs.readFileSync('./package.json'));
|
||||
|
||||
const [major] = version.split('.');
|
||||
const tags = await getTags();
|
||||
const latestTag = (tags[0] || '').replace(/^v/, '');
|
||||
|
||||
const isBeta = !/^v?(\d+).(\d)+.(\d)+$/.test(version);
|
||||
const isLatest = latestTag === version;
|
||||
|
||||
let tag = isBeta ? 'next' : isLatest ? 'latest' : `v${major}`;
|
||||
|
||||
console.log(colorize()`Version [${version}] [${isBeta ? 'prerelease' : 'release'}] latest [${latestTag}]=> NPM Tag [${tag}]`);
|
||||
|
||||
await exec(`echo "tag=${tag}" >> $GITHUB_OUTPUT`);
|
||||
Reference in New Issue
Block a user