Skip to content

Commit c50ec79

Browse files
authoredApr 19, 2024
Add gitHead to package.json in all release workflows (microsoft#58135)
1 parent e62418e commit c50ec79

7 files changed

+29
-3
lines changed
 

‎.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ jobs:
154154

155155
- run: npx hereby lkg
156156
- run: |
157+
node ./scripts/addPackageJsonGitHead.mjs package.json
157158
npm pack
158159
mv typescript*.tgz typescript.tgz
159160
echo "package=$PWD/typescript.tgz" >> "$GITHUB_OUTPUT"

‎.github/workflows/insiders.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ jobs:
5959
npm ci
6060
npx hereby configure-insiders
6161
npx hereby LKG
62+
node ./scripts/addPackageJsonGitHead.mjs package.json
6263
npm publish --tag insiders
6364
env:
6465
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

‎.github/workflows/nightly.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ jobs:
5959
npm ci
6060
npx hereby configure-nightly
6161
npx hereby LKG
62+
node ./scripts/addPackageJsonGitHead.mjs package.json
6263
npm publish --tag next
6364
env:
6465
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

‎.github/workflows/release-branch-artifact.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
run: |
4141
npx hereby LKG
4242
npx hereby clean
43+
node ./scripts/addPackageJsonGitHead.mjs package.json
4344
npm pack ./
4445
mv typescript-*.tgz typescript.tgz
4546
- name: Upload built tarfile

‎azure-pipelines.release.yml

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ extends:
7777
- script: |
7878
npx hereby LKG
7979
npx hereby clean
80+
node ./scripts/addPackageJsonGitHead.mjs package.json
8081
npm pack
8182
displayName: 'LKG, clean, pack'
8283

‎scripts/addPackageJsonGitHead.mjs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { execFileSync } from "child_process";
2+
import {
3+
readFileSync,
4+
writeFileSync,
5+
} from "fs";
6+
import {
7+
dirname,
8+
resolve,
9+
} from "path";
10+
11+
const packageJsonFilePath = process.argv[2];
12+
if (!packageJsonFilePath) {
13+
console.error("Usage: node addPackageJsonGitHead.mjs <package.json location>");
14+
process.exit(1);
15+
}
16+
17+
const packageJsonValue = JSON.parse(readFileSync(packageJsonFilePath, "utf8"));
18+
19+
const cwd = dirname(resolve(packageJsonFilePath));
20+
const gitHead = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim();
21+
22+
packageJsonValue.gitHead = gitHead;
23+
24+
writeFileSync(packageJsonFilePath, JSON.stringify(packageJsonValue, undefined, 4) + "\n");

‎scripts/configurePrerelease.mjs

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import assert from "assert";
2-
import { execFileSync } from "child_process";
32
import {
43
readFileSync,
54
writeFileSync,
@@ -18,7 +17,6 @@ const __filename = url.fileURLToPath(new URL(import.meta.url));
1817
name: string;
1918
version: string;
2019
keywords: string[];
21-
gitHead?: string;
2220
}} PackageJson
2321
*/
2422

@@ -59,7 +57,6 @@ function main() {
5957
// Finally write the changes to disk.
6058
// Modify the package.json structure
6159
packageJsonValue.version = `${majorMinor}.${prereleasePatch}`;
62-
packageJsonValue.gitHead = execFileSync("git", ["rev-parse", "HEAD"], { encoding: "utf8" }).trim();
6360
writeFileSync(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4));
6461
writeFileSync(tsFilePath, modifiedTsFileContents);
6562
}

0 commit comments

Comments
 (0)
Please sign in to comment.