Skip to content

Commit

Permalink
feat: add support for the custom release name #238
Browse files Browse the repository at this point in the history
  • Loading branch information
flelli committed Aug 19, 2023
1 parent d2eb17b commit 80a1294
Show file tree
Hide file tree
Showing 36 changed files with 571 additions and 53 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This release:
* adds support for arbitrary [substitutions](https://mooltiverse.github.io/nyx/guide/user/configuration-reference/substitutions/) in text files within the project using dynamic values from the [State](https://mooltiverse.github.io/nyx/guide/user/state-reference/) ([#182](https://github.com/mooltiverse/nyx/issues/182)) ([#223](https://github.com/mooltiverse/nyx/issues/223))
* adds support for multiple Git tag [names](https://mooltiverse.github.io/nyx/guide/user/configuration-reference/release-types/#git-tag-names) that can be used to change the default git tag or add some tag aliases ([#243](https://github.com/mooltiverse/nyx/issues/243))
* adds support for the new `versionMajorNumber`, `versionMinorNumber`, `versionPatchNumber`, `versionPreReleaseIdentifier`, `versionBuildMetadata` [state attributes](https://mooltiverse.github.io/nyx/guide/user/state-reference/global-attributes/)
* adds support for the new [`releaseName`](https://mooltiverse.github.io/nyx/guide/user/configuration-reference/release-types/#release-name) configuration option to control the name of releases published to remote services
* adds support for Gradle `8.2.1` and `8.3`.

### Fixed issues
Expand Down
1 change: 1 addition & 0 deletions docs/_includes/.nyx-extended.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ nyx {
}
matchWorkspaceStatus = 'CLEAN'
publish = 'true'
releaseName = 'Release {{version}}'
versionRangeFromBranchName = false
}
maturity {
Expand Down
1 change: 1 addition & 0 deletions docs/_includes/.nyx-extended.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
},
"matchWorkspaceStatus":"CLEAN",
"publish":"true",
"releaseName":"Release {{version}}",
"versionRangeFromBranchName":false
},
"maturity":{
Expand Down
1 change: 1 addition & 0 deletions docs/_includes/.nyx-extended.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ releaseTypes:
CI: "^true$"
matchWorkspaceStatus: "CLEAN"
publish: "true"
releaseName: "Release {{version}}"
versionRangeFromBranchName: false
maturity:
collapseVersions: true
Expand Down
1 change: 1 addition & 0 deletions docs/_includes/.nyx-medium.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ nyx {
}
matchWorkspaceStatus = 'CLEAN'
publish = 'true'
releaseName = 'Release {{version}}'
versionRangeFromBranchName = false
}
internal {
Expand Down
1 change: 1 addition & 0 deletions docs/_includes/.nyx-medium.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
},
"matchWorkspaceStatus":"CLEAN",
"publish":"true",
"releaseName":"Release {{version}}",
"versionRangeFromBranchName":false
},
"internal":{
Expand Down
1 change: 1 addition & 0 deletions docs/_includes/.nyx-medium.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ releaseTypes:
CI: "^true$"
matchWorkspaceStatus: "CLEAN"
publish: "true"
releaseName: "Release {{version}}"
versionRangeFromBranchName: false
internal:
collapseVersions: false
Expand Down
22 changes: 20 additions & 2 deletions docs/_pages/guide/user/03.configuration-reference/release-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Each release type has the following attributes:
| [`releaseTypes/<NAME>/matchWorkspaceStatus`](#match-workspace-status) | string | `--release-types-<NAME>-match-workspace-status` | `NYX_RELEASE_TYPES_<NAME>_MATCH_WORKSPACE_STATUS=<STATUS>` | Empty |
| [`releaseTypes/<NAME>/name`](#name) | string | `--release-types-<NAME>-name=<NAME>` | `NYX_RELEASE_TYPES_<NAME>_NAME=<NAME>` | N/A |
| [`releaseTypes/<NAME>/publish`](#publish) | string | `--release-types-<NAME>-publish=<TEMPLATE>` | `NYX_RELEASE_TYPES_<NAME>_PUBLISH=<TEMPLATE>` | `false` |
| [`releaseTypes/<NAME>/releaseName`](#release-name) | string | `--release-types-<NAME>-release-name=<TEMPLATE>` | `NYX_RELEASE_TYPES_<NAME>_RELEASE_NAME=<TEMPLATE>` | Empty |
| [`releaseTypes/<NAME>/versionRange`](#version-range) | string | `--release-types-<NAME>-version-range=<TEMPLATE>` | `NYX_RELEASE_TYPES_<NAME>_VERSION_RANGE=<TEMPLATE>` | Empty (no constrained range) |
| [`releaseTypes/<NAME>/versionRangeFromBranchName`](#version-range-from-branch-name) | boolean | `--release-types-<NAME>-version-range-from-branch-name=true|false` | `NYX_RELEASE_TYPES_<NAME>_VERSION_RANGE_FROM_BRANCH_NAME=true|false` | `false` |

Expand Down Expand Up @@ -497,8 +498,8 @@ When using this option, the release type is only evaluated when the current bran
| Name | `releaseTypes/<NAME>/matchEnvironmentVariables` |
| Type | [map]({{ site.baseurl }}{% link _pages/guide/user/02.introduction/configuration-methods.md %}#collections-of-objects) |
| Default | Empty (matches anything) |
| Command Line Option | `--release-types-<NAME>-match-environment-variables-<VARNAME>=<VALUE>` |
| Environment Variable | `NYX_RELEASE_TYPES_<NAME>_MATCH_ENVIRONMENT_VARIABLES_<VARNAME>=<VALUE>` |
| Command Line Option | `--release-types-<NAME>-match-environment-variables-<VARNAME>=<VALUE>` |
| Environment Variable | `NYX_RELEASE_TYPES_<NAME>_MATCH_ENVIRONMENT_VARIABLES_<VARNAME>=<VALUE>` |
| Configuration File Option | `releaseTypes/items/<NAME>/matchEnvironmentVariables` |
| Related state attributes | |

Expand Down Expand Up @@ -564,6 +565,23 @@ When this value evaluates to *true* releases are published to the [services]({{

Also see [`assets`](#assets) for more on the assets attached to releases upon publication.

#### Release name

| ------------------------- | ---------------------------------------------------------------------------------------- |
| Name | `releaseTypes/<NAME>/releaseName` |
| Type | string |
| Default | EMpty |
| Command Line Option | `--release-types-<NAME>-release-name=<TEMPLATE>` |
| Environment Variable | `NYX_RELEASE_TYPES_<NAME>_RELEASE_NAME=<TEMPLATE>` |
| Configuration File Option | `releaseTypes/items/<NAME>/releaseName` |
| Related state attributes | [version]({{ site.baseurl }}{% link _pages/guide/user/05.state-reference/global-attributes.md %}#version){: .btn .btn--info .btn--small} |

A [template]({{ site.baseurl }}{% link _pages/guide/user/03.configuration-reference/templates.md %}) that is evaluated at runtime to define the name of the releases to be published.

This option only takes effect when [`publish`](#publish) evaluates `true`.

When this option is not defined or is empty the [version]({{ site.baseurl }}{% link _pages/guide/user/05.state-reference/global-attributes.md %}#version) is used for the release name.

#### Version range

| ------------------------- | ---------------------------------------------------------------------------------------- |
Expand Down
10 changes: 9 additions & 1 deletion modules/go/nyx/command/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,17 @@ func (c *Publish) publish() error {
if service == nil {
return &errs.IllegalPropertyError{Message: fmt.Sprintf("the release type uses the '%s' publication service but no such service has been configured in the 'services' section", *serviceName)}
}
releaseName, err := c.renderTemplate(releaseType.GetReleaseName())
if err != nil {
return err
}
if releaseName == nil || len(*releaseName) == 0 {
// if no release name template was specified then fall-back to the version for the release title
releaseName = version
}
// The first two parameters here are nil because the repository owner and name are expected to be passed
// along with service options. This is just a place where we could override them.
release, err := (*service).PublishRelease(nil, nil, version, *version, description)
release, err := (*service).PublishRelease(nil, nil, releaseName, *version, description)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,13 @@ const (
// in order to get the actual name of the argument that brings the value for the release type with the given 'name'.
RELEASE_TYPES_ARGUMENT_ITEM_PUBLISH_FORMAT_STRING = RELEASE_TYPES_ARGUMENT_NAME + "-%s-publish"

// The parametrized name of the argument to read for the 'releaseName' attribute of a
// release type.
// This string is a prototype that contains a '%s' parameter for the release type name
// and must be rendered using fmt.Sprintf(RELEASE_TYPES_ARGUMENT_ITEM_RELEASE_NAME_FORMAT_STRING, name)
// in order to get the actual name of the argument that brings the value for the release type with the given 'name'.
RELEASE_TYPES_ARGUMENT_ITEM_RELEASE_NAME_FORMAT_STRING = RELEASE_TYPES_ARGUMENT_NAME + "-%s-release-name"

// The parametrized name of the argument to read for the 'versionRange' attribute of a
// release type.
// This string is a prototype that contains a '%s' parameter for the release type name
Expand Down Expand Up @@ -1218,6 +1225,7 @@ func (clcl *CommandLineConfigurationLayer) GetReleaseTypes() (*ent.ReleaseTypes,
matchWorkspaceStatus = &mws
}
publish := clcl.getArgument(fmt.Sprintf(RELEASE_TYPES_ARGUMENT_ITEM_PUBLISH_FORMAT_STRING, itemName))
releaseName := clcl.getArgument(fmt.Sprintf(RELEASE_TYPES_ARGUMENT_ITEM_RELEASE_NAME_FORMAT_STRING, itemName))
versionRange := clcl.getArgument(fmt.Sprintf(RELEASE_TYPES_ARGUMENT_ITEM_VERSION_RANGE_FORMAT_STRING, itemName))
var versionRangeFromBranchName *bool = nil
versionRangeFromBranchNameString := clcl.getArgument(fmt.Sprintf(RELEASE_TYPES_ARGUMENT_ITEM_VERSION_RANGE_FROM_BRANCH_NAME_FORMAT_STRING, itemName))
Expand All @@ -1229,7 +1237,7 @@ func (clcl *CommandLineConfigurationLayer) GetReleaseTypes() (*ent.ReleaseTypes,
versionRangeFromBranchName = &vrfbn
}

items[itemName] = ent.NewReleaseTypeWith(assets, collapseVersions, collapseVersionQualifier, description, filterTags, gitCommit, gitCommitMessage, gitPush, gitTag, gitTagMessage, gitTagNames, &identifiers, matchBranches, &matchEnvironmentVariables, matchWorkspaceStatus, publish, versionRange, versionRangeFromBranchName)
items[itemName] = ent.NewReleaseTypeWith(assets, collapseVersions, collapseVersionQualifier, description, filterTags, gitCommit, gitCommitMessage, gitPush, gitTag, gitTagMessage, gitTagNames, &identifiers, matchBranches, &matchEnvironmentVariables, matchWorkspaceStatus, publish, releaseName, versionRange, versionRangeFromBranchName)
}

enabledPointers := clcl.toSliceOfStringPointers(enabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ func TestCommandLineConfigurationLayerGetReleaseTypes(t *testing.T) {
"--release-types-two-match-environment-variables-USER=any user",
"--release-types-two-match-workspace-status=" + ent.CLEAN.String(),
"--release-types-two-publish=true",
"--release-types-two-release-name=myrelease",
"--release-types-two-version-range-from-branch-name=true",
})

Expand Down Expand Up @@ -639,6 +640,7 @@ func TestCommandLineConfigurationLayerGetReleaseTypes(t *testing.T) {
assert.Equal(t, 0, len(*(*(*releaseTypes.GetItems())["one"]).GetMatchEnvironmentVariables()))
assert.Equal(t, ent.DIRTY, *(*(*releaseTypes.GetItems())["one"]).GetMatchWorkspaceStatus())
assert.Equal(t, "false", *(*(*releaseTypes.GetItems())["one"]).GetPublish())
assert.Nil(t, (*(*releaseTypes.GetItems())["one"]).GetReleaseName())
assert.Equal(t, "true", *(*(*releaseTypes.GetItems())["one"]).GetVersionRange())
assert.Nil(t, (*(*releaseTypes.GetItems())["one"]).GetVersionRangeFromBranchName())
assert.Nil(t, (*(*releaseTypes).GetItems())["two"].GetAssets())
Expand Down Expand Up @@ -671,6 +673,7 @@ func TestCommandLineConfigurationLayerGetReleaseTypes(t *testing.T) {
assert.Equal(t, "any user", (*(*(*releaseTypes.GetItems())["two"]).GetMatchEnvironmentVariables())["USER"])
assert.Equal(t, ent.CLEAN, *(*(*releaseTypes.GetItems())["two"]).GetMatchWorkspaceStatus())
assert.Equal(t, "true", *(*(*releaseTypes.GetItems())["two"]).GetPublish())
assert.Equal(t, "myrelease", *(*(*releaseTypes.GetItems())["two"]).GetReleaseName())
assert.Nil(t, (*(*releaseTypes.GetItems())["two"]).GetVersionRange())
assert.True(t, *(*(*releaseTypes.GetItems())["two"]).GetVersionRangeFromBranchName())
}
Expand Down
Loading

0 comments on commit 80a1294

Please sign in to comment.