Skip to content

add variable commit_date#308

Closed
trim21 wants to merge 0 commit intodocker:masterfrom
trim21:master
Closed

add variable commit_date#308
trim21 wants to merge 0 commit intodocker:masterfrom
trim21:master

Conversation

@trim21
Copy link
Copy Markdown
Contributor

@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
@trim21
Copy link
Copy Markdown
Contributor Author

trim21 commented Jul 13, 2023

@crazy-max any code review?

Comment thread src/meta.ts Outdated
}

private getCommitDate(): Date {
const myOutput = execSync('git show -s --format="%ci" HEAD');
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
Contributor 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
Copy Markdown
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.

Comment thread src/meta.ts Outdated
}

private getCommitDate(): Date {
const myOutput = execSync('git show -s --format="%ci" HEAD');
Copy link
Copy Markdown
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",

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