chore: publish packages with the correct branch name in buildInfo (#27682)

This commit is contained in:
Adam Stone-Lord
2023-08-28 12:08:11 -04:00
committed by GitHub
parent f383ae329f
commit e533618ab7

View File

@@ -1,6 +1,7 @@
const _ = require('lodash')
const path = require('path')
const shell = require('shelljs')
const minimist = require('minimist')
const fs = require('../lib/fs')
@@ -24,7 +25,7 @@ function getStdout (cmd) {
return shell.exec(cmd).trim()
}
function preparePackageForNpmRelease (json) {
function preparePackageForNpmRelease (json, branchName) {
// modify the existing package.json
// to prepare it for releasing to npm
delete json.devDependencies
@@ -36,7 +37,7 @@ function preparePackageForNpmRelease (json) {
_.extend(json, {
version,
buildInfo: {
commitBranch: process.env.CIRCLE_BRANCH || getStdout('git branch --show-current'),
commitBranch: branchName || process.env.CIRCLE_BRANCH || getStdout('git branch --show-current'),
commitSha: getStdout('git rev-parse HEAD'),
commitDate: new Date(getStdout('git show -s --format=%ci')).toISOString(),
stable: false,
@@ -57,9 +58,9 @@ function preparePackageForNpmRelease (json) {
return json
}
function makeUserPackageFile () {
function makeUserPackageFile (branchName) {
return fs.readJsonAsync(packageJsonSrc)
.then(preparePackageForNpmRelease)
.then((json) => preparePackageForNpmRelease(json, branchName))
.then((json) => {
return fs.outputJsonAsync(packageJsonDest, json, {
spaces: 2,
@@ -71,7 +72,9 @@ function makeUserPackageFile () {
module.exports = makeUserPackageFile
if (!module.parent) {
makeUserPackageFile()
const args = minimist(process.argv)
makeUserPackageFile(args.branch)
.catch((err) => {
/* eslint-disable no-console */
console.error('Could not write user package file')