Skip to content

Add gitHead to package.json in all release workflows #58135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/insiders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
1 change: 1 addition & 0 deletions .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
1 change: 1 addition & 0 deletions .github/workflows/release-branch-artifact.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions azure-pipelines.release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ extends:
- script: |
npx hereby LKG
npx hereby clean
node ./scripts/addPackageJsonGitHead.mjs package.json
npm pack
displayName: 'LKG, clean, pack'

Expand Down
24 changes: 24 additions & 0 deletions scripts/addPackageJsonGitHead.mjs
Original file line number Diff line number Diff line change
@@ -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 <package.json location>");
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");
3 changes: 0 additions & 3 deletions scripts/configurePrerelease.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import assert from "assert";
import { execFileSync } from "child_process";
import {
readFileSync,
writeFileSync,
Expand All @@ -18,7 +17,6 @@ const __filename = url.fileURLToPath(new URL(import.meta.url));
name: string;
version: string;
keywords: string[];
gitHead?: string;
}} PackageJson
*/

Expand Down Expand Up @@ -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);
}
Expand Down