I would like to know if there is any way to get the date of a commit through an environment variable or something to be able to use it within github actions.
            Asked
            
        
        
            Active
            
        
            Viewed 1,872 times
        
    6
            
            
        - 
                    You can find all default env vars here: https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables – Dominik Jul 11 '22 at 03:15
 - 
                    @Dominik there are no references to date or timestamp there or at https://docs.github.com/en/actions/learn-github-actions/contexts Does this mean it doesn't exist? – rob Nov 30 '22 at 10:24
 - 
                    If it's not in the docs it's a good guess for it not to be a public API yeah – Dominik Nov 30 '22 at 11:01
 
2 Answers
1
            
            
        similar to @trayan-azarov
_GIT_COMMIT_DATE=$(git log -1 --format=%cd --date=format:%Y%m%dh%H%M%S)
this just gives you greater flexibility with the date format.
        WiR3D
        
- 1,465
 - 20
 - 23
 
0
            
            
        You can try using git for this e.g.:
export COMMIT_TIME=$(git show -s --format=%ci dd28288f)
Where dd28288f is your commit sha (see https://stackoverflow.com/a/58886352 for more info). Or you can use the GitHub built-in env vars - ${GITHUB_SHA::8}
The above will result in COMMIT_TIME=2023-02-25 19:59:02 +0200
Hope this helps.
        Trayan Azarov
        
- 21
 - 3