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

add variable commit_date #308

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

add variable commit_date #308

wants to merge 2 commits into from

Conversation

trim21
Copy link

@trim21 trim21 commented Jul 3, 2023

close #292

@trim21 trim21 marked this pull request as ready for review July 3, 2023 07:32
@trim21 trim21 requested a review from crazy-max as a code owner July 3, 2023 07:32
Signed-off-by: Trim21 <trim21.me@gmail.com>
@trim21
Copy link
Author

trim21 commented Jul 13, 2023

@crazy-max any code review?

Signed-off-by: Trim21 <trim21.me@gmail.com>
this.version = this.getVersion();
}

private getCommitDate(): Date {
const myOutput = execSync('git show -s --format="%ci" HEAD');
Copy link
Member

Choose a reason for hiding this comment

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

We should use our toolkit for this. Can you open a PR to add this in https://github.com/docker/actions-toolkit/blob/main/src/git.ts?

Copy link
Member

Choose a reason for hiding this comment

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

Also we should only invoke git command if context is git like we do in

switch (source) {
case ContextSource.workflow:
return getContextFromWorkflow();
case ContextSource.git:
return await getContextFromGit();

If context is workflow then we should take it from GH API if feasible. commits.timestamp looks to be a good candidate:

"timestamp": "2022-04-19T11:04:39+02:00",

Copy link
Author

Choose a reason for hiding this comment

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

We should use our toolkit for this. Can you open a PR to add this in https://github.com/docker/actions-toolkit/blob/main/src/git.ts?

add a new property to GitContext looks complex...

Copy link
Member

Choose a reason for hiding this comment

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

add a new property to GitContext looks complex...

Just smth similar to https://github.com/docker/actions-toolkit/blob/f1593e3aa24d872bd4fa0a8f76a3bdaf26d20872/src/git.ts#L101-L103 is enough.

Copy link
Author

@trim21 trim21 Jul 13, 2023

Choose a reason for hiding this comment

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

add a new property to GitContext looks complex...

GitContext is just an alias of GitHubContext and it's created from Context.constructor, make it very hard to add a new property, should I create some new interface types to resolve this?

Copy link
Author

Choose a reason for hiding this comment

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

add a new property to GitContext looks complex...

Just smth similar to https://github.com/docker/actions-toolkit/blob/f1593e3aa24d872bd4fa0a8f76a3bdaf26d20872/src/git.ts#L101-L103 is enough.

.sha is a existing property on Context(GitContext and GithubContext)

Copy link
Member

Choose a reason for hiding this comment

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

I mean a new method for Git class in the actions toolkit like:

public static async commitDate(): Promise<Date> {

Then you would just need to consume it here when context is git.

this.version = this.getVersion();
}

private getCommitDate(): Date {
const myOutput = execSync('git show -s --format="%ci" HEAD');
Copy link
Member

@crazy-max crazy-max Jul 25, 2023

Choose a reason for hiding this comment

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

Also we don't want to exec git when the context is workflow. You should just grab the commits.timestamp from the GitHub event for this case:

"timestamp": "2022-04-19T11:27:24+02:00",

@trim21 trim21 marked this pull request as draft September 1, 2023 19:51
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.

Proposol: add commit date variable
2 participants