Skip to content

Commit ff0b158

Browse files
author
Rui Yang
authored
Merge pull request #131 from concourse/bump-build-label
Allow bumping of build labels
2 parents 1d321fc + 94423ac commit ff0b158

File tree

13 files changed

+413
-49
lines changed

13 files changed

+413
-49
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,17 @@ be one of:
228228
type, (e.g. `alpha` vs. `beta`), the type is switched and the prerelease
229229
version is reset to `1`. If the version is *not* already a pre-release, then
230230
`pre` is added, starting at `1`.
231-
232-
The value of `pre` can be anything you like; the value will be `pre`-pended (_hah_) to a numeric value. For example, `pre: build` will result in a semver of `x.y.z-build.<number>`, `pre: alpha` becomes `x.y.z-alpha.<number>`, and `pre: my-preferred-naming-convention` becomes `x.y.z-my-preferred-naming-convention.<number>`
233231

234-
If `pre_without_version` is set as `true`, the value will be `pre` and no version number. So `SNAPSHOT` will still be as `SNAPSHOT`,
232+
The value of `pre` can be anything you like; the value will be `pre`-pended (_hah_) to a numeric value. For example, `pre: foo` will result in a semver of `x.y.z-foo.<number>`, `pre: alpha` becomes `x.y.z-alpha.<number>`, and `pre: my-preferred-naming-convention` becomes `x.y.z-my-preferred-naming-convention.<number>`
233+
234+
* `build`: *Optional.* Same as `pre` but for build labels (e.g. `build: foo`
235+
will result in a semver of `x.y.z+foo.<number>`, `build: alpha` becomes
236+
`x.y.z+alpha.<number>`.
237+
238+
It is valid for a semver to be both a prerelease and a build, for example,
239+
`pre: alpha, build: test` results in `x.y.z-alpha.<number>+test.<number>`
240+
* `pre_without_version`: *Optional.* When bumping to a prerelease, drop the
241+
version if set to `true`.
235242
Examples:
236243
* Major version bump: version file = 1.2.4-SNAPSHOT, release version = 2.0.0
237244
* Minor version bump: version file = 1.2.4-SNAPSHOT, release version = 1.3.0

in/in_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/aws/aws-sdk-go/aws/session"
1515
"github.com/aws/aws-sdk-go/service/s3"
1616
"github.com/concourse/semver-resource/models"
17-
"github.com/nu7hatch/gouuid"
17+
uuid "github.com/nu7hatch/gouuid"
1818
. "github.com/onsi/ginkgo"
1919
. "github.com/onsi/gomega"
2020
"github.com/onsi/gomega/gexec"

in/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ func main() {
3737
}
3838

3939
bumped := version.BumpFromParams(
40-
request.Params.Bump,
40+
request.Params.Bump,
4141
request.Params.Pre,
42-
request.Params.PreWithoutVersion).Apply(inputVersion)
42+
request.Params.PreWithoutVersion,
43+
request.Params.Build,
44+
request.Params.BuildWithoutVersion,
45+
).Apply(inputVersion)
4346

4447
if !bumped.Equals(inputVersion) {
4548
fmt.Fprintf(os.Stderr, "bumped locally from %s to %s\n", inputVersion, bumped)

models/models.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ type InResponse struct {
1616
}
1717

1818
type InParams struct {
19-
Bump string `json:"bump"`
20-
Pre string `json:"pre"`
21-
PreWithoutVersion bool `json:"pre_without_version"`
19+
Bump string `json:"bump"`
20+
Pre string `json:"pre"`
21+
Build string `json:"build"`
22+
PreWithoutVersion bool `json:"pre_without_version"`
23+
BuildWithoutVersion bool `json:"build_without_version"`
2224
}
2325

2426
type OutRequest struct {
@@ -35,9 +37,11 @@ type OutResponse struct {
3537
type OutParams struct {
3638
File string `json:"file"`
3739

38-
Bump string `json:"bump"`
39-
Pre string `json:"pre"`
40-
PreWithoutVersion bool `json:"pre_without_version"`
40+
Bump string `json:"bump"`
41+
Pre string `json:"pre"`
42+
Build string `json:"build"`
43+
PreWithoutVersion bool `json:"pre_without_version"`
44+
BuildWithoutVersion bool `json:"build_without_version"`
4145
}
4246

4347
type CheckRequest struct {

out/main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ func main() {
5858
}
5959
} else if request.Params.Bump != "" || request.Params.Pre != "" {
6060
bump := version.BumpFromParams(
61-
request.Params.Bump,
62-
request.Params.Pre,
63-
request.Params.PreWithoutVersion)
61+
request.Params.Bump,
62+
request.Params.Pre,
63+
request.Params.PreWithoutVersion,
64+
request.Params.Build,
65+
request.Params.BuildWithoutVersion,
66+
)
6467

6568
newVersion, err = driver.Bump(bump)
6669
if err != nil {

out/out_test.go

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/aws/aws-sdk-go/aws/session"
1616
"github.com/aws/aws-sdk-go/service/s3"
1717
"github.com/concourse/semver-resource/models"
18-
"github.com/nu7hatch/gouuid"
18+
uuid "github.com/nu7hatch/gouuid"
1919
. "github.com/onsi/ginkgo"
2020
. "github.com/onsi/gomega"
2121
"github.com/onsi/gomega/gexec"
@@ -269,5 +269,142 @@ var _ = Describe("Out", func() {
269269
})
270270
})
271271
})
272+
273+
Context("when bumping the version to a build", func() {
274+
BeforeEach(func() {
275+
request.Params.Build = "build"
276+
})
277+
278+
Context("when the version is not a build", func() {
279+
BeforeEach(func() {
280+
putVersion("1.2.3")
281+
})
282+
283+
It("reports the bumped version as the version", func() {
284+
Expect(response.Version.Number).To(Equal("1.2.3+build.1"))
285+
})
286+
287+
It("saves the contents of the file in the configured bucket", func() {
288+
Expect(getVersion()).To(Equal("1.2.3+build.1"))
289+
})
290+
291+
Context("when doing a semantic bump at the same time", func() {
292+
BeforeEach(func() {
293+
request.Params.Bump = "minor"
294+
})
295+
296+
It("reports the bumped version as the version", func() {
297+
Expect(response.Version.Number).To(Equal("1.3.0+build.1"))
298+
})
299+
300+
It("saves the contents of the file in the configured bucket", func() {
301+
Expect(getVersion()).To(Equal("1.3.0+build.1"))
302+
})
303+
})
304+
})
305+
306+
Context("when the version is the same build", func() {
307+
BeforeEach(func() {
308+
putVersion("1.2.3+build.2")
309+
})
310+
311+
It("reports the bumped version as the version", func() {
312+
Expect(response.Version.Number).To(Equal("1.2.3+build.3"))
313+
})
314+
315+
It("saves the contents of the file in the configured bucket", func() {
316+
Expect(getVersion()).To(Equal("1.2.3+build.3"))
317+
})
318+
319+
Context("when doing a semantic bump at the same time", func() {
320+
BeforeEach(func() {
321+
request.Params.Bump = "minor"
322+
})
323+
324+
It("reports the bumped version as the version", func() {
325+
Expect(response.Version.Number).To(Equal("1.3.0+build.1"))
326+
})
327+
328+
It("saves the contents of the file in the configured bucket", func() {
329+
Expect(getVersion()).To(Equal("1.3.0+build.1"))
330+
})
331+
})
332+
})
333+
334+
Context("when the version is a different build", func() {
335+
BeforeEach(func() {
336+
putVersion("1.2.3-beta.2")
337+
})
338+
339+
It("reports the bumped version as the version", func() {
340+
Expect(response.Version.Number).To(Equal("1.2.3+build.1"))
341+
})
342+
343+
It("saves the contents of the file in the configured bucket", func() {
344+
Expect(getVersion()).To(Equal("1.2.3+build.1"))
345+
})
346+
347+
Context("when doing a semantic bump at the same time", func() {
348+
BeforeEach(func() {
349+
request.Params.Bump = "minor"
350+
})
351+
352+
It("reports the bumped version as the version", func() {
353+
Expect(response.Version.Number).To(Equal("1.3.0+build.1"))
354+
})
355+
356+
It("saves the contents of the file in the configured bucket", func() {
357+
Expect(getVersion()).To(Equal("1.3.0+build.1"))
358+
})
359+
})
360+
})
361+
})
362+
363+
Context("when bumping the version to a prerelease and build", func() {
364+
BeforeEach(func() {
365+
request.Params.Pre = "alpha"
366+
request.Params.Build = "build"
367+
})
368+
369+
Context("when the version is just a base version", func() {
370+
BeforeEach(func() {
371+
putVersion("1.2.3")
372+
})
373+
374+
It("reports the bumped version as the version", func() {
375+
Expect(response.Version.Number).To(Equal("1.2.3-alpha.1+build.1"))
376+
})
377+
})
378+
379+
Context("when the version has a prerelease", func() {
380+
BeforeEach(func() {
381+
putVersion("1.2.3-alpha.1")
382+
})
383+
384+
It("reports the bumped version as the version", func() {
385+
Expect(response.Version.Number).To(Equal("1.2.3-alpha.2+build.1"))
386+
})
387+
})
388+
389+
Context("when the version has a build", func() {
390+
BeforeEach(func() {
391+
putVersion("1.2.3+build.1")
392+
})
393+
394+
It("reports the bumped version as the version", func() {
395+
Expect(response.Version.Number).To(Equal("1.2.3-alpha.1+build.2"))
396+
})
397+
})
398+
399+
Context("when the version has a build and prerelease", func() {
400+
BeforeEach(func() {
401+
putVersion("1.2.3-alpha.1+build.1")
402+
})
403+
404+
It("reports the bumped version as the version", func() {
405+
Expect(response.Version.Number).To(Equal("1.2.3-alpha.2+build.2"))
406+
})
407+
})
408+
})
272409
})
273410
})

test/helpers.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ put_uri_with_bump() {
152152
},
153153
params: {
154154
bump: $(echo $3 | jq -R .),
155-
pre: $(echo $4 | jq -R .)
155+
pre: $(echo $4 | jq -R .),
156+
build: $(echo $5 | jq -R .)
156157
}
157158
}" | ${resource_dir}/out "$2" | tee /dev/stderr
158159
}
@@ -168,7 +169,8 @@ put_uri_with_bump_and_initial() {
168169
},
169170
params: {
170171
bump: $(echo $4 | jq -R .),
171-
pre: $(echo $5 | jq -R .)
172+
pre: $(echo $5 | jq -R .),
173+
build: $(echo $6 | jq -R .)
172174
}
173175
}" | ${resource_dir}/out "$2" | tee /dev/stderr
174176
}
@@ -180,11 +182,12 @@ put_uri_with_bump_and_message() {
180182
uri: $(echo $1 | jq -R .),
181183
branch: \"master\",
182184
file: \"some-file\",
183-
commit_message: \"$(echo $5)\"
185+
commit_message: \"$(echo $6)\"
184186
},
185187
params: {
186188
bump: $(echo $3 | jq -R .),
187-
pre: $(echo $4 | jq -R .)
189+
pre: $(echo $4 | jq -R .),
190+
build: $(echo $5 | jq -R .)
188191
}
189192
}" | ${resource_dir}/out "$2" | tee /dev/stderr
190193
}

test/put.sh

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ it_can_put_and_bump_first_version() {
7676
# cannot push to repo while it's checked out to a branch
7777
git -C $repo checkout refs/heads/master
7878

79-
put_uri_with_bump $repo $src minor alpha | jq -e "
80-
.version == {number: \"0.1.0-alpha.1\"}
79+
put_uri_with_bump $repo $src minor alpha build | jq -e "
80+
.version == {number: \"0.1.0-alpha.1+build.1\"}
8181
"
8282

8383
# switch back to master
8484
git -C $repo checkout master
8585

8686
test -e $repo/some-file
87-
test "$(cat $repo/some-file)" = 0.1.0-alpha.1
87+
test "$(cat $repo/some-file)" = 0.1.0-alpha.1+build.1
8888
}
8989

9090
it_can_put_and_bump_first_version_with_initial() {
@@ -95,15 +95,15 @@ it_can_put_and_bump_first_version_with_initial() {
9595
# cannot push to repo while it's checked out to a branch
9696
git -C $repo checkout refs/heads/master
9797

98-
put_uri_with_bump_and_initial $repo $src 1.2.3 minor alpha | jq -e "
99-
.version == {number: \"1.3.0-alpha.1\"}
98+
put_uri_with_bump_and_initial $repo $src 1.2.3 minor alpha build | jq -e "
99+
.version == {number: \"1.3.0-alpha.1+build.1\"}
100100
"
101101

102102
# switch back to master
103103
git -C $repo checkout master
104104

105105
test -e $repo/some-file
106-
test "$(cat $repo/some-file)" = 1.3.0-alpha.1
106+
test "$(cat $repo/some-file)" = 1.3.0-alpha.1+build.1
107107
}
108108

109109
it_can_put_and_bump_over_existing_version() {
@@ -116,15 +116,15 @@ it_can_put_and_bump_over_existing_version() {
116116
# cannot push to repo while it's checked out to a branch
117117
git -C $repo checkout refs/heads/master
118118

119-
put_uri_with_bump $repo $src minor alpha | jq -e "
120-
.version == {number: \"1.3.0-alpha.1\"}
119+
put_uri_with_bump $repo $src minor alpha build | jq -e "
120+
.version == {number: \"1.3.0-alpha.1+build.1\"}
121121
"
122122

123123
# switch back to master
124124
git -C $repo checkout master
125125

126126
test -e $repo/some-file
127-
test "$(cat $repo/some-file)" = 1.3.0-alpha.1
127+
test "$(cat $repo/some-file)" = 1.3.0-alpha.1+build.1
128128
}
129129

130130
it_can_put_and_bump_with_message_over_existing_version() {
@@ -139,15 +139,15 @@ it_can_put_and_bump_with_message_over_existing_version() {
139139
# cannot push to repo while it's checked out to a branch
140140
git -C $repo checkout refs/heads/master
141141

142-
put_uri_with_bump_and_message $repo $src minor alpha "$message" | jq -e "
143-
.version == {number: \"1.3.0-alpha.1\"}
142+
put_uri_with_bump_and_message $repo $src minor alpha build "$message" | jq -e "
143+
.version == {number: \"1.3.0-alpha.1+build.1\"}
144144
"
145145

146146
# switch back to master
147147
git -C $repo checkout master
148148

149149
test -e $repo/some-file
150-
test "$(cat $repo/some-file)" = 1.3.0-alpha.1
150+
test "$(cat $repo/some-file)" = 1.3.0-alpha.1+build.1
151151
test "$(git -C $repo log -n1 --pretty=%B)" = "$message"
152152
}
153153

@@ -163,17 +163,17 @@ it_can_put_and_bump_with_message_and_replace_over_existing_version() {
163163
# cannot push to repo while it's checked out to a branch
164164
git -C $repo checkout refs/heads/master
165165

166-
put_uri_with_bump_and_message $repo $src minor alpha "$message" | jq -e "
167-
.version == {number: \"1.3.0-alpha.1\"}
166+
put_uri_with_bump_and_message $repo $src minor alpha build "$message" | jq -e "
167+
.version == {number: \"1.3.0-alpha.1+build.1\"}
168168
"
169169

170170
# switch back to master
171171
git -C $repo checkout master
172172

173-
local expected_message="This is a commit message on some-file with 1.3.0-alpha.1"
173+
local expected_message="This is a commit message on some-file with 1.3.0-alpha.1+build.1"
174174

175175
test -e $repo/some-file
176-
test "$(cat $repo/some-file)" = 1.3.0-alpha.1
176+
test "$(cat $repo/some-file)" = 1.3.0-alpha.1+build.1
177177
test "$(git -C $repo log -n1 --pretty=%B)" = "$expected_message"
178178
}
179179

0 commit comments

Comments
 (0)