mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-01 13:07:49 +02:00
parent
916769893e
commit
fac5e48c77
@ -304,7 +304,7 @@ func (c *giteaClient) ReleaseURLTemplate(ctx *context.Context) (string, error) {
|
||||
}
|
||||
|
||||
return fmt.Sprintf(
|
||||
"%s/%s/%s/releases/download/{{ .Tag }}/{{ .ArtifactName }}",
|
||||
"%s/%s/%s/releases/download/{{ urlPathEscape .Tag }}/{{ .ArtifactName }}",
|
||||
downloadURL,
|
||||
ctx.Config.Release.Gitea.Owner,
|
||||
ctx.Config.Release.Gitea.Name,
|
||||
|
@ -486,12 +486,12 @@ func TestGiteaReleaseURLTemplate(t *testing.T) {
|
||||
{
|
||||
name: "string_url",
|
||||
downloadURL: "https://gitea.com",
|
||||
wantDownloadURL: "https://gitea.com/owner/name/releases/download/{{ .Tag }}/{{ .ArtifactName }}",
|
||||
wantDownloadURL: "https://gitea.com/owner/name/releases/download/{{ urlPathEscape .Tag }}/{{ .ArtifactName }}",
|
||||
},
|
||||
{
|
||||
name: "download_url_template",
|
||||
downloadURL: "{{ .Env.GORELEASER_TEST_GITEA_URLS_DOWNLOAD }}",
|
||||
wantDownloadURL: "https://gitea.mycompany.com/owner/name/releases/download/{{ .Tag }}/{{ .ArtifactName }}",
|
||||
wantDownloadURL: "https://gitea.mycompany.com/owner/name/releases/download/{{ urlPathEscape .Tag }}/{{ .ArtifactName }}",
|
||||
},
|
||||
{
|
||||
name: "download_url_template_invalid_value",
|
||||
|
@ -497,7 +497,7 @@ func (c *githubClient) ReleaseURLTemplate(ctx *context.Context) (string, error)
|
||||
}
|
||||
|
||||
return fmt.Sprintf(
|
||||
"%s/%s/%s/releases/download/{{ .Tag }}/{{ .ArtifactName }}",
|
||||
"%s/%s/%s/releases/download/{{ urlPathEscape .Tag }}/{{ .ArtifactName }}",
|
||||
downloadURL,
|
||||
ctx.Config.Release.GitHub.Owner,
|
||||
ctx.Config.Release.GitHub.Name,
|
||||
|
@ -138,12 +138,12 @@ func TestGitHubReleaseURLTemplate(t *testing.T) {
|
||||
{
|
||||
name: "default_download_url",
|
||||
downloadURL: DefaultGitHubDownloadURL,
|
||||
wantDownloadURL: "https://github.com/owner/name/releases/download/{{ .Tag }}/{{ .ArtifactName }}",
|
||||
wantDownloadURL: "https://github.com/owner/name/releases/download/{{ urlPathEscape .Tag }}/{{ .ArtifactName }}",
|
||||
},
|
||||
{
|
||||
name: "download_url_template",
|
||||
downloadURL: "{{ .Env.GORELEASER_TEST_GITHUB_URLS_DOWNLOAD }}",
|
||||
wantDownloadURL: "https://github.mycompany.com/owner/name/releases/download/{{ .Tag }}/{{ .ArtifactName }}",
|
||||
wantDownloadURL: "https://github.mycompany.com/owner/name/releases/download/{{ urlPathEscape .Tag }}/{{ .ArtifactName }}",
|
||||
},
|
||||
{
|
||||
name: "download_url_template_invalid_value",
|
||||
|
@ -447,14 +447,14 @@ func (c *gitlabClient) ReleaseURLTemplate(ctx *context.Context) (string, error)
|
||||
|
||||
if ctx.Config.Release.GitLab.Owner != "" {
|
||||
urlTemplate = fmt.Sprintf(
|
||||
"%s/%s/%s/-/releases/{{ .Tag }}/downloads/{{ .ArtifactName }}",
|
||||
"%s/%s/%s/-/releases/{{ urlPathEscape .Tag }}/downloads/{{ .ArtifactName }}",
|
||||
downloadURL,
|
||||
ctx.Config.Release.GitLab.Owner,
|
||||
gitlabName,
|
||||
)
|
||||
} else {
|
||||
urlTemplate = fmt.Sprintf(
|
||||
"%s/%s/-/releases/{{ .Tag }}/downloads/{{ .ArtifactName }}",
|
||||
"%s/%s/-/releases/{{ urlPathEscape .Tag }}/downloads/{{ .ArtifactName }}",
|
||||
downloadURL,
|
||||
gitlabName,
|
||||
)
|
||||
|
@ -37,19 +37,19 @@ func TestGitLabReleaseURLTemplate(t *testing.T) {
|
||||
name: "default_download_url",
|
||||
downloadURL: DefaultGitLabDownloadURL,
|
||||
repo: repo,
|
||||
wantDownloadURL: "https://gitlab.com/owner/name/-/releases/{{ .Tag }}/downloads/{{ .ArtifactName }}",
|
||||
wantDownloadURL: "https://gitlab.com/owner/name/-/releases/{{ urlPathEscape .Tag }}/downloads/{{ .ArtifactName }}",
|
||||
},
|
||||
{
|
||||
name: "default_download_url_no_owner",
|
||||
downloadURL: DefaultGitLabDownloadURL,
|
||||
repo: config.Repo{Name: "name"},
|
||||
wantDownloadURL: "https://gitlab.com/name/-/releases/{{ .Tag }}/downloads/{{ .ArtifactName }}",
|
||||
wantDownloadURL: "https://gitlab.com/name/-/releases/{{ urlPathEscape .Tag }}/downloads/{{ .ArtifactName }}",
|
||||
},
|
||||
{
|
||||
name: "download_url_template",
|
||||
repo: repo,
|
||||
downloadURL: "{{ .Env.GORELEASER_TEST_GITLAB_URLS_DOWNLOAD }}",
|
||||
wantDownloadURL: "https://gitlab.mycompany.com/owner/name/-/releases/{{ .Tag }}/downloads/{{ .ArtifactName }}",
|
||||
wantDownloadURL: "https://gitlab.mycompany.com/owner/name/-/releases/{{ urlPathEscape .Tag }}/downloads/{{ .ArtifactName }}",
|
||||
},
|
||||
{
|
||||
name: "download_url_template_invalid_value",
|
||||
|
@ -95,7 +95,7 @@ func (c *Mock) PublishRelease(_ *context.Context, _ string /* releaseID */) (err
|
||||
}
|
||||
|
||||
func (c *Mock) ReleaseURLTemplate(_ *context.Context) (string, error) {
|
||||
return "https://dummyhost/download/{{ .Tag }}/{{ .ArtifactName }}", nil
|
||||
return "https://dummyhost/download/{{ urlPathEscape .Tag }}/{{ .ArtifactName }}", nil
|
||||
}
|
||||
|
||||
func (c *Mock) CreateFile(_ *context.Context, _ config.CommitAuthor, _ Repo, content []byte, path, msg string) error {
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"maps"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
@ -251,6 +252,7 @@ func (t *Template) Apply(s string) (string, error) {
|
||||
"isEnvSet": t.isEnvSet,
|
||||
"map": makemap,
|
||||
"indexOrDefault": indexOrDefault,
|
||||
"urlPathEscape": url.PathEscape,
|
||||
}).
|
||||
Parse(s)
|
||||
if err != nil {
|
||||
|
@ -39,8 +39,9 @@ func TestWithArtifact(t *testing.T) {
|
||||
Dirty: true,
|
||||
}),
|
||||
testctx.WithEnv(map[string]string{
|
||||
"FOO": "bar",
|
||||
"MULTILINE": "something with\nmultiple lines\nremove this\nto test things",
|
||||
"FOO": "bar",
|
||||
"MULTILINE": "something with\nmultiple lines\nremove this\nto test things",
|
||||
"WITH_SLASHES": "foo/bar",
|
||||
}),
|
||||
testctx.WithSemver(1, 2, 3, ""),
|
||||
testctx.Snapshot,
|
||||
@ -103,6 +104,7 @@ func TestWithArtifact(t *testing.T) {
|
||||
"env bar: barrrrr": `env bar: {{ envOrDefault "BAR" "barrrrr" }}`,
|
||||
"env foo: bar": `env foo: {{ envOrDefault "FOO" "barrrrr" }}`,
|
||||
"env foo is set: true": `env foo is set: {{ isEnvSet "FOO" }}`,
|
||||
"/foo%2Fbar": `/{{ urlPathEscape .Env.WITH_SLASHES}}`,
|
||||
|
||||
"remove this": "{{ filter .Env.MULTILINE \".*remove.*\" }}",
|
||||
"something with\nmultiple lines\nto test things": "{{ reverseFilter .Env.MULTILINE \".*remove.*\" }}",
|
||||
|
@ -178,6 +178,7 @@ On all fields, you have these available functions:
|
||||
| `incmajor "v1.2.4"` | increments the major of the given version[^panic-if-not-semver] |
|
||||
| `list "a" "b" "c"` | makes a list of strings[^pro] |
|
||||
| `in (list "a" "b" "c") "b"` | checks if a slice contains a value[^pro] |
|
||||
| `urlPathEscape "foo/bar"` | escapes URL paths. See [PathEscape](https://pkg.go.dev/net/url#PathEscape) (since v2.5) |
|
||||
|
||||
[^panic-if-not-semver]: Will panic if not a semantic version.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user