Getting the last commit message into the run command

In my Java project, there is a properties file that is used by a plugin to populate a box on an output HTML file (making the result of my Selenium test look nice).

I just wanted to take the text of the last commit to the subject repo and use sed to hack the relevant property in the file. I have been able to make a similar hack using a static string, but using dynamically generated data (e.g. `git log -1 --pretty=format::"%s"’) leaves me cold.

I nearly got there with set-env, but that is deprecated.

Can anyone please tell me how this can be done?

It has been replaced by the GITHUB_ENV environment file. The other thing you need to know is that in Bash you can use $(command) to substitute the output of command. So to set a COMMIT_MSG environment variable for use in later steps:

- name: get commit message
  run: |
    echo "COMMIT_MSG=$(git log -1 --pretty=format:%s)" >>$GITHUB_ENV

Or if you need the output only for the sed command you could skip the variable and just do something like:

- name: substitute log message
  run: |
   sed -e "s/@COMMIT_MSG@/$(git log -1 --pretty=format:%s)/" project.properties.in >project.properties
2 Likes

Excellent! Thanks for this, I now can achieve what I was trying to do.

I have now realised that what was doing was, actually, not going to achieve what I actually wanted doing, but that is The Human Condition.

1 Like