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

Expose version info in CLI tool with build-time obtained git hash #787

Merged
merged 4 commits into from
Jan 17, 2023

Conversation

jsdw
Copy link
Collaborator

@jsdw jsdw commented Jan 17, 2023

Builds off @DaviRain-Su's work in #776 and provides version info in the subxt CLI command, making the git hash be a compile-time included string.

Closes #739

@jsdw jsdw mentioned this pull request Jan 17, 2023
@jsdw jsdw changed the title version info with built-time obtained git hash Expose version info with build-time obtained git hash Jan 17, 2023
@jsdw jsdw changed the title Expose version info with build-time obtained git hash Expose version info in CLI tool with build-time obtained git hash Jan 17, 2023
output_git_short_hash();
}

fn output_git_short_hash() {
Copy link
Member

@niklasad1 niklasad1 Jan 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could do something similar as substrate to get a better error message if git fails:

		match Command::new("git").args(&["rev-parse", "--short=11", "HEAD"]).output() {
			Ok(o) if o.status.success() => {
				let sha = String::from_utf8_lossy(&o.stdout).trim().to_owned();
				Cow::from(sha)
			},
			Ok(o) => {
				println!("cargo:warning=Git command failed with status: {}", o.status);
				Cow::from("unknown")
			},
			Err(err) => {
				println!("cargo:warning=Failed to execute git command: {}", err);
				Cow::from("unknown")
			},
		}

I guess you want to fail the entire thing once it errors, I have no issues with that :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the expect output is clear enough not sure

Copy link
Collaborator Author

@jsdw jsdw Jan 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea! I'd never expect the git tool not to exist really in a build env I guess, but maybe worth doing this just incase! :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this; nice suggestion!

@niklasad1
Copy link
Member

You could have cherry-picked @DaviRain-Su commit to give him some kudos for the work but yeah kudos in the PR description works as well I guess :P

@jsdw
Copy link
Collaborator Author

jsdw commented Jan 17, 2023

You could have cherry-picked @DaviRain-Su commit to give him some kudos for the work but yeah kudos in the PR description works as well I guess :P

I'll remember that for next time; I wanted to give kudos for sure, but it's a pain working with remote branches so I was lazy :)

@jsdw
Copy link
Collaborator Author

jsdw commented Jan 17, 2023

I haven't merged this yet because I'm playing with rerun-if-changed and for some reason if I push a commit to the repo and then rebuild, this script doesn't update the version properly. Am looking into it!

@jsdw
Copy link
Collaborator Author

jsdw commented Jan 17, 2023

It took me far too long to see that the rerun-if-changed commands I was using were wrong, but it all should work now :)

@jsdw jsdw merged commit 08d6640 into master Jan 17, 2023
@jsdw jsdw deleted the jsdw-version branch January 17, 2023 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add subxt --version
3 participants