Skip to content
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

chore(cli): show git commit with --version if tact comes from dev repo #555

Merged
merged 2 commits into from
Jul 11, 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
2 changes: 1 addition & 1 deletion .github/workflows/tact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
- name: CLI Test | Compare Tact version from CLI flag `--version` against package.json
if: runner.os != 'Windows'
run: |
if [ "$(tact --version)" != "$(jq -r '.version' < package.json)" ];
if [ "$(tact --version | head -n1)" != "$(jq -r '.version' < package.json)" ];
then false
fi

Expand Down
16 changes: 15 additions & 1 deletion bin/tact.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const pkg = require("../package.json");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const main = require("../dist/node.js");
const meowModule = import("meow");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { execFileSync } = require("child_process");

void meowModule.then(
/** @param meow {import('meow/build/index')} */
Expand Down Expand Up @@ -36,6 +38,7 @@ void meowModule.then(
url: new URL("file://" + __dirname + __filename).toString(),
},
description: `Command-line utility for the Tact compiler:\n${pkg.description}`,
autoVersion: false,
flags: {
config: {
shortFlag: "c",
Expand Down Expand Up @@ -83,7 +86,18 @@ void meowModule.then(

// Show version regardless of other flags
if (cli.flags.version) {
cli.showVersion();
console.log(pkg.version);
// if working inside a git repository
// also print the current git commit hash
try {
const gitCommit = execFileSync("git", ["rev-parse", "HEAD"], {
encoding: "utf8",
stdio: ["ignore", "pipe", "ignore"],
}).trim();
console.log(`git commit: ${gitCommit}`);
} finally {
process.exit(0);
}
}

// Evaluate expression regardless of other flags
Expand Down
Loading