Skip to content

Commit

Permalink
internal/ci: do not release "zero" releases in release workflow
Browse files Browse the repository at this point in the history
When we create a release branch for v0.$X.0, it's likely that commits on
the default branch will from that point onwards be intended for the $X+1
version. However, unless we tag the next commit after the release
branch, it might be the case that pseudo versions of those later commits
refer to the $X release.

A "zero" tag fixes this when applied to the first commit after a release
branch. Critically, the -0.dev pre-release suffix is ordered before
-alpha tags.

This is per advice in:

golang/go#38985 (comment)

Also DRY up our use of tag prefixes (and suffixes) so that they can be
reused in GitHub glob patterns as well as CUE regular expressions.

Signed-off-by: Paul Jolly <[email protected]>
Change-Id: I79b9308fd858cb1e08f119787254f5927e503545
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/549359
Unity-Result: CUEcueckoo <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
  • Loading branch information
myitcv committed Feb 3, 2023
1 parent ae0d7ca commit 02e19c8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ name: Release
push:
tags:
- v*
- '!*-0.dev'
branches:
- ci/test
- master
Expand Down
36 changes: 33 additions & 3 deletions internal/ci/core/core.cue
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,39 @@ _#URLPath: {

#goreleaserVersion: "v1.13.1"

#defaultBranch: "master"
#releaseBranchPattern: "release-branch.*"
#releaseTagPattern: "v*"
#defaultBranch: "master"

// #releaseBranchPrefix is the git branch name prefix used to identify
// release branches.
#releaseBranchPrefix: "release-branch."

// #releaseBranchPattern is the GitHub pattern that corresponds to
// #releaseBranchPrefix.
#releaseBranchPattern: #releaseBranchPrefix + "*"

// #releaseTagPrefix is the prefix used to identify all git tag that correspond
// to semver releases
#releaseTagPrefix: "v"

// #releaseTagPattern is the GitHub glob pattern that corresponds to
// #releaseTagPrefix.
#releaseTagPattern: #releaseTagPrefix + "*"

// #zeroReleaseTagSuffix is the suffix used to identify all "zero" releases.
// When we create a release branch for v0.$X.0, it's likely that commits on the
// default branch will from that point onwards be intended for the $X+1
// version. However, unless we tag the next commit after the release branch, it
// might be the case that pseudo versions of those later commits refer to the
// $X release.
//
// A "zero" tag fixes this when applied to the first commit after a release
// branch. Critically, the -0.dev pre-release suffix is ordered before -alpha.
// tags.
#zeroReleaseTagSuffix: "-0.dev"

// #zeroReleaseTagPattern is the GitHub glob pattern that corresponds
// #zeroReleaseTagSuffix.
#zeroReleaseTagPattern: "*" + #zeroReleaseTagSuffix

#codeReview: {
gerrit?: string
Expand Down
2 changes: 1 addition & 1 deletion internal/ci/github/release.cue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ release: _base.#bashWorkflow & {
concurrency: "release"

on: push: {
tags: [core.#releaseTagPattern]
tags: [core.#releaseTagPattern, "!" + core.#zeroReleaseTagPattern]
branches: list.Concat([[_base.#testDefaultBranch], _#protectedBranchPatterns])
}
jobs: goreleaser: {
Expand Down
6 changes: 3 additions & 3 deletions internal/ci/github/workflows.cue
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ _#protectedBranchPatterns: [core.#defaultBranch, core.#releaseBranchPattern]
// See https://docs.github.com/en/actions/learn-github-actions/expressions.
_#matchPattern: {
variable: string
pattern: string
expr: [
if strings.HasSuffix(pattern, "*") {
pattern: string
expr: [
if strings.HasSuffix(pattern, "*") {
let prefix = strings.TrimSuffix(pattern, "*")
"startsWith(\(variable), '\(prefix)')"
},
Expand Down
4 changes: 3 additions & 1 deletion internal/ci/goreleaser/goreleaser_tool.cue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"tool/exec"
"tool/os"
"tool/cli"

"cuelang.org/go/internal/ci/core"
)

command: release: {
Expand Down Expand Up @@ -58,7 +60,7 @@ command: release: {
// Only run the full release when running on GitHub actions for a release tag.
// Keep in sync with core.#releaseTagPattern, which is a globbing pattern
// rather than a regular expression.
if _githubRef !~ "refs/tags/v.*" {
if _githubRef !~ "refs/tags/\(core.#releaseTagPrefix).*" {
"--snapshot"
},
]
Expand Down

0 comments on commit 02e19c8

Please sign in to comment.