You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-11-06 09:09:19 +02:00
feat(githubPublishRelease): custom tag prefix support (#3166)
* feat(githubPublishRelease): tag prefix support * cleanup * go fmt * tagPrefix shall not be mandatory
This commit is contained in:
@@ -76,8 +76,10 @@ func runGithubPublishRelease(ctx context.Context, config *githubPublishReleaseOp
|
||||
releaseBody += getReleaseDeltaText(config, lastRelease)
|
||||
}
|
||||
|
||||
prefixedTagName := config.TagPrefix + config.Version
|
||||
|
||||
release := github.RepositoryRelease{
|
||||
TagName: &config.Version,
|
||||
TagName: &prefixedTagName,
|
||||
TargetCommitish: &config.Commitish,
|
||||
Name: &config.Version,
|
||||
Body: &releaseBody,
|
||||
|
||||
@@ -28,6 +28,7 @@ type githubPublishReleaseOptions struct {
|
||||
ReleaseBodyHeader string `json:"releaseBodyHeader,omitempty"`
|
||||
Repository string `json:"repository,omitempty"`
|
||||
ServerURL string `json:"serverUrl,omitempty"`
|
||||
TagPrefix string `json:"tagPrefix,omitempty"`
|
||||
Token string `json:"token,omitempty"`
|
||||
UploadURL string `json:"uploadUrl,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
@@ -139,6 +140,7 @@ func addGithubPublishReleaseFlags(cmd *cobra.Command, stepConfig *githubPublishR
|
||||
cmd.Flags().StringVar(&stepConfig.ReleaseBodyHeader, "releaseBodyHeader", os.Getenv("PIPER_releaseBodyHeader"), "Content which will appear for the release.")
|
||||
cmd.Flags().StringVar(&stepConfig.Repository, "repository", os.Getenv("PIPER_repository"), "Name of the GitHub repository.")
|
||||
cmd.Flags().StringVar(&stepConfig.ServerURL, "serverUrl", `https://github.com`, "GitHub server url for end-user access.")
|
||||
cmd.Flags().StringVar(&stepConfig.TagPrefix, "tagPrefix", ``, "Defines a prefix to be added to the tag.")
|
||||
cmd.Flags().StringVar(&stepConfig.Token, "token", os.Getenv("PIPER_token"), "GitHub personal access token as per https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line")
|
||||
cmd.Flags().StringVar(&stepConfig.UploadURL, "uploadUrl", `https://uploads.github.com`, "Set the GitHub API url.")
|
||||
cmd.Flags().StringVar(&stepConfig.Version, "version", os.Getenv("PIPER_version"), "Define the version number which will be written as tag as well as release name.")
|
||||
@@ -284,6 +286,15 @@ func githubPublishReleaseMetadata() config.StepData {
|
||||
Aliases: []config.Alias{{Name: "githubServerUrl"}},
|
||||
Default: `https://github.com`,
|
||||
},
|
||||
{
|
||||
Name: "tagPrefix",
|
||||
ResourceRef: []config.ResourceReference{},
|
||||
Scope: []string{"PARAMETERS", "STAGES", "STEPS"},
|
||||
Type: "string",
|
||||
Mandatory: false,
|
||||
Aliases: []config.Alias{},
|
||||
Default: ``,
|
||||
},
|
||||
{
|
||||
Name: "token",
|
||||
ResourceRef: []config.ResourceReference{
|
||||
|
||||
@@ -119,6 +119,33 @@ func TestRunGithubPublishRelease(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "Header\n", ghRepoClient.release.GetBody())
|
||||
assert.Equal(t, true, ghRepoClient.release.GetPrerelease())
|
||||
assert.Equal(t, "1.0", ghRepoClient.release.GetTagName())
|
||||
})
|
||||
|
||||
t.Run("Success - first release with tag prefix set & no body", func(t *testing.T) {
|
||||
ghIssueClient := ghICMock{}
|
||||
ghRepoClient := ghRCMock{
|
||||
latestStatusCode: 404,
|
||||
latestErr: fmt.Errorf("not found"),
|
||||
}
|
||||
|
||||
myGithubPublishReleaseOptions := githubPublishReleaseOptions{
|
||||
AddDeltaToLastRelease: true,
|
||||
Commitish: "master",
|
||||
Owner: "TEST",
|
||||
PreRelease: true,
|
||||
Repository: "test",
|
||||
ServerURL: "https://github.com",
|
||||
ReleaseBodyHeader: "Header",
|
||||
Version: "1.0",
|
||||
TagPrefix: "v",
|
||||
}
|
||||
err := runGithubPublishRelease(ctx, &myGithubPublishReleaseOptions, &ghRepoClient, &ghIssueClient)
|
||||
assert.NoError(t, err, "Error occurred but none expected.")
|
||||
|
||||
assert.Equal(t, "Header\n", ghRepoClient.release.GetBody())
|
||||
assert.Equal(t, true, ghRepoClient.release.GetPrerelease())
|
||||
assert.Equal(t, "v1.0", ghRepoClient.release.GetTagName())
|
||||
})
|
||||
|
||||
t.Run("Success - subsequent releases & with body", func(t *testing.T) {
|
||||
|
||||
@@ -129,6 +129,14 @@ spec:
|
||||
type: string
|
||||
default: https://github.com
|
||||
mandatory: true
|
||||
- name: tagPrefix
|
||||
type: string
|
||||
description: "Defines a prefix to be added to the tag."
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
default: ""
|
||||
- name: token
|
||||
aliases:
|
||||
- name: githubToken
|
||||
|
||||
Reference in New Issue
Block a user