Skip to content

Instantly share code, notes, and snippets.

@koenbok
Last active September 29, 2017 05:12
Show Gist options
  • Save koenbok/031bfe7831a8b270a1f7 to your computer and use it in GitHub Desktop.
Save koenbok/031bfe7831a8b270a1f7 to your computer and use it in GitHub Desktop.
Wercker Git Versions

Wercker Git Versioning Tips

If you need to add automatic build numbers on the Wercker platform, here are a few gotchas.

  • The hash: git describe --always --dirty. This works just fine, but it always reports as dirty. You might want to filter that out.
  • The branch: process.env.WERCKER_GIT_BRANCH. You cannot get this from Git because Wercker checks out a specific commit, independent of the current branch.
  • The build number: git rev-list --count HEAD. This only works if you run git fetch --unshallow beforehand. This is because Wercker uses a shallow checkout to save bandwidth, thus Git doesn't know about all revisions and reports the wrong build number if you leave this out. A caveat here is that you cannot use the SSH key that Wercker used for fetching the code, so the easiest way is to convert the remote origin to http with git remote set-url origin.
gulp.task "version", (callback) ->
async.series [
(cb) -> command("git rev-parse --abbrev-ref HEAD", cb) # branch
(cb) -> command("git describe --always --dirty", cb) # hash
(cb) -> command("git rev-list --count HEAD", cb) # build
], (err, results) ->
info =
branch: results[0]
hash: results[1]
build: results[2]
date: Math.floor(Date.now() / 1000)
# If we are on the wercker platform, we need to get the branch
# name from the env variables and remove the dirty vrom version.
if process.env.WERCKER_GIT_BRANCH
info.branch = process.env.WERCKER_GIT_BRANCH
info.hash = info.hash.replace("-dirty", "")
gutil.log "Building ", gutil.colors.green("#{info.branch}/#{info.hash} @#{info.build}")
box: nolimitid/node-phantom-npm3
build:
steps:
- script:
name: load git revisions
code: |
git remote set-url origin https://github.com/$WERCKER_GIT_OWNER/$WERCKER_GIT_REPOSITORY.git
cd $WERCKER_SOURCE_DIR
git fetch --unshallow
- npm-test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment