Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a check to see if Jenkins is clobbering tags #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

agocs
Copy link

@agocs agocs commented Oct 4, 2016

If the git tag begins with "jenkins", there's a pretty strong chance
that Jenkins is clobbering our git tag. I've added logic that checks for
a new env var, semverIfJenkins. If that is set to 1 when ldflags.sh is
called, ldflags.sh will check to see if the git tag begins with
"jenkins", and, if so, it grabs the latest git tag beginning with the
character "v" assuming that is a semver tag.

If semverIfJenkins is set but there is no semver tag, gittag will be
empty string.

Usage:

semverIfJenkins=1 source ldflags.sh

If the git tag begins with "jenkins", there's a pretty strong chance
that Jenkins is clobbering our git tag. I've added logic that checks for
a new env var, `semverIfJenkins`. If that is set to 1 when ldflags.sh is
called, ldflags.sh will check to see if the git tag begins with
"jenkins", and, if so, it grabs the latest git tag beginning with the
character "v" assuming that is a semver tag.

If semverIfJenkins is set but there is no semver tag, gittag will be
empty string.
Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, thoughts on this:

If we're going to use environment variables, let's use uppercase with underscores, just to be consistent.

I'd much rather modify the external-facing $TAG variable than the internal $gittag variable, just for sanity's sake.

I'm tempted, so this doesn't become a shell monstrosity as we add exceptions and special logic, to say we should pull this into its own file. The idea kicking around in my head at the moment is to put this in a new jenkins-semver.sh file that sets $TAG if git name-rev --tags --name-only $(git rev-parse --short HEAD) has jenkins prefix. Then programs could do something like

source vendor/darlinggo.co/version/jenkins-semver.sh
source vendor/darlinggo.co/version/ldflags.sh
go build -ldflags "${LDFLAGS}" .

But that's a bit more composable and sustainable if we start needing to add more exceptions in. It also patterns how people could modify the logic that gets built into the LDFLAGS environment variable without getting code merged to master or forking.

What do you think? Any thoughts on any of this?

@paddycarver
Copy link
Contributor

(Also, thanks for the PR! Sorry for the delay in reviewing it.)

@agocs
Copy link
Author

agocs commented Oct 19, 2016

Sorry if I've let this sit too long. I think that's wise. I'll see if I can find time to hack on it some more.

@paddycarver
Copy link
Contributor

Not at all! If you want help, let me know, and I can probably implement some of this, too. I don't have a jenkins server handy, but I can do some of the bash stuff if necessary.

Also, as a note, just make sure your PR adds you (or DramaFever, if that's who owns the work you're contributing) to the AUTHORS file, and you (regardless of who owns the work) to the CONTRIBUTORS file.

... neither of which exists. I'll remedy that right now. I'm the worst.

(Basically, this just makes sure that the copyright owner retains their copyright claim on the code, and the people that actually wrote the code get the credit they deserve for writing it.)

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.

2 participants