Skip to content

Instantly share code, notes, and snippets.

@Willshaw
Last active July 21, 2020 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Willshaw/ee1d691d0a124cc5a46fcc295374f16a to your computer and use it in GitHub Desktop.
Save Willshaw/ee1d691d0a124cc5a46fcc295374f16a to your computer and use it in GitHub Desktop.
Use coldfusion to execute a bash script and get the current git commit
#!/bin/bash
# change directory to the path passed from cf
# then do a git log, oneline to avoid commit messages (I had to specify the full path to git)
# pipe that to "head" and limit it to 1 line
# this will give us "HASH MESSAGE"
# use awk to print the first "column" -> HASH
cd $1 && /usr/local/git/bin/git log --oneline | head -n 1 | awk '{print $1}'
<cfscript>
# NOTE! THIS IS JUST AN EXPERIMENT, DON'T DROP EXECUTEABLE BASH SCRIPTS IN YOUR WEB ROOT
// get the path to the folder we're in (or use a specific hardcoded path to your bash file if it's elsewhere, which it should be
path = getDirectoryFromPath(getCurrentTemplatePath());
// execute a bash script (make sure it can be executed by the user running as CF
// give it the above #path# as a parameter
cfexecute(
name="bash",
arguments="/full/path/to/git-hash-read/hash.sh #path#",
variable="githash",
errorVariable="hashbang",
timeout=1
);
</cfscript>
<cfoutput>
Let's see if we can get that commit hash!
<h1>hash</h1>
#githash#
<h2>Was there an error?</h2>
#hashbang#
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment