diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 050406aa09ac1..752eefc7b57ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -154,6 +154,7 @@ jobs: - run: npx hereby lkg - run: | + node ./scripts/addPackageJsonGitHead.mjs package.json npm pack mv typescript*.tgz typescript.tgz echo "package=$PWD/typescript.tgz" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/insiders.yaml b/.github/workflows/insiders.yaml index 4177abaeb8ae8..a9fddaca3c6a2 100644 --- a/.github/workflows/insiders.yaml +++ b/.github/workflows/insiders.yaml @@ -59,6 +59,7 @@ jobs: npm ci npx hereby configure-insiders npx hereby LKG + node ./scripts/addPackageJsonGitHead.mjs package.json npm publish --tag insiders env: NODE_AUTH_TOKEN: ${{secrets.npm_token}} diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml index 9efb90fa34a31..eceacd03e0e8c 100644 --- a/.github/workflows/nightly.yaml +++ b/.github/workflows/nightly.yaml @@ -59,6 +59,7 @@ jobs: npm ci npx hereby configure-nightly npx hereby LKG + node ./scripts/addPackageJsonGitHead.mjs package.json npm publish --tag next env: NODE_AUTH_TOKEN: ${{secrets.npm_token}} diff --git a/.github/workflows/release-branch-artifact.yaml b/.github/workflows/release-branch-artifact.yaml index 9b48afa7f0941..7e7a165b2d9a3 100644 --- a/.github/workflows/release-branch-artifact.yaml +++ b/.github/workflows/release-branch-artifact.yaml @@ -40,6 +40,7 @@ jobs: run: | npx hereby LKG npx hereby clean + node ./scripts/addPackageJsonGitHead.mjs package.json npm pack ./ mv typescript-*.tgz typescript.tgz - name: Upload built tarfile diff --git a/azure-pipelines.release.yml b/azure-pipelines.release.yml index 54684eafbbbed..64e2da5f5b8e8 100644 --- a/azure-pipelines.release.yml +++ b/azure-pipelines.release.yml @@ -77,6 +77,7 @@ extends: - script: | npx hereby LKG npx hereby clean + node ./scripts/addPackageJsonGitHead.mjs package.json npm pack displayName: 'LKG, clean, pack' diff --git a/scripts/addPackageJsonGitHead.mjs b/scripts/addPackageJsonGitHead.mjs new file mode 100644 index 0000000000000..7d4931edfadbd --- /dev/null +++ b/scripts/addPackageJsonGitHead.mjs @@ -0,0 +1,24 @@ +import { execFileSync } from "child_process"; +import { + readFileSync, + writeFileSync, +} from "fs"; +import { + dirname, + resolve, +} from "path"; + +const packageJsonFilePath = process.argv[2]; +if (!packageJsonFilePath) { + console.error("Usage: node addPackageJsonGitHead.mjs "); + process.exit(1); +} + +const packageJsonValue = JSON.parse(readFileSync(packageJsonFilePath, "utf8")); + +const cwd = dirname(resolve(packageJsonFilePath)); +const gitHead = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim(); + +packageJsonValue.gitHead = gitHead; + +writeFileSync(packageJsonFilePath, JSON.stringify(packageJsonValue, undefined, 4) + "\n"); diff --git a/scripts/configurePrerelease.mjs b/scripts/configurePrerelease.mjs index 762d1b7312165..80b7ce1a9a417 100644 --- a/scripts/configurePrerelease.mjs +++ b/scripts/configurePrerelease.mjs @@ -1,5 +1,4 @@ import assert from "assert"; -import { execFileSync } from "child_process"; import { readFileSync, writeFileSync, @@ -18,7 +17,6 @@ const __filename = url.fileURLToPath(new URL(import.meta.url)); name: string; version: string; keywords: string[]; - gitHead?: string; }} PackageJson */ @@ -59,7 +57,6 @@ function main() { // Finally write the changes to disk. // Modify the package.json structure packageJsonValue.version = `${majorMinor}.${prereleasePatch}`; - packageJsonValue.gitHead = execFileSync("git", ["rev-parse", "HEAD"], { encoding: "utf8" }).trim(); writeFileSync(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4)); writeFileSync(tsFilePath, modifiedTsFileContents); }