11
11
from continuous_delivery_scripts .utils .language_specifics_base import BaseLanguage , get_language_from_file_name
12
12
from continuous_delivery_scripts .spdx_report .spdx_project import SpdxProject
13
13
from continuous_delivery_scripts .utils .configuration import configuration , ConfigurationVariable
14
+ from continuous_delivery_scripts .utils .git_helpers import LocalProjectRepository
14
15
15
16
logger = logging .getLogger (__name__ )
16
17
@@ -68,18 +69,6 @@ def _call_goreleaser_check(version: str) -> None:
68
69
check_call (_generate_goreleaser_check_command_list (), cwd = ROOT_DIR )
69
70
70
71
71
- def _call_goreleaser_release (version : str ) -> None :
72
- """Calls go releaser release to upload packages."""
73
- logger .info ("Installing GoReleaser if missing." )
74
- check_call (_install_goreleaser_command_list ())
75
- logger .info ("Release package." )
76
- changelogPath = configuration .get_value (ConfigurationVariable .CHANGELOG_FILE_PATH )
77
- env = os .environ
78
- env [ENVVAR_GORELEASER_CUSTOMISED_TAG ] = version
79
- env [ENVVAR_GORELEASER_GIT_TOKEN ] = configuration .get_value (ConfigurationVariable .GIT_TOKEN )
80
- check_call (_generate_goreleaser_release_command_list (changelogPath ), cwd = ROOT_DIR , env = env )
81
-
82
-
83
72
class Go (BaseLanguage ):
84
73
"""Specific actions for a Golang project."""
85
74
@@ -100,7 +89,7 @@ def package_software(self, version: str) -> None:
100
89
def release_package_to_repository (self , version : str ) -> None :
101
90
"""No operation."""
102
91
super ().release_package_to_repository (version )
103
- _call_goreleaser_release (version )
92
+ self . _call_goreleaser_release (version )
104
93
105
94
def check_credentials (self ) -> None :
106
95
"""Checks any credentials."""
@@ -128,3 +117,22 @@ def get_current_spdx_project(self) -> Optional[SpdxProject]:
128
117
def should_clean_before_packaging (self ) -> bool :
129
118
"""States whether the repository must be cleaned before packaging happens."""
130
119
return True
120
+
121
+ def _call_goreleaser_release (self , version : str ) -> None :
122
+ """Calls go releaser release to upload packages."""
123
+ logger .info ("Installing GoReleaser if missing." )
124
+ check_call (_install_goreleaser_command_list ())
125
+ tag = self .get_version_tag (version )
126
+ # The tag of the release must be retrieved
127
+ # See https://github.com/goreleaser/goreleaser/discussions/1426
128
+ logger .info (f"Checking out tag: { tag } ." )
129
+ with LocalProjectRepository () as git :
130
+ git .configure_for_github ()
131
+ git .fetch ()
132
+ git .checkout (f"tags/{ tag } " )
133
+ logger .info ("Release package." )
134
+ changelogPath = configuration .get_value (ConfigurationVariable .CHANGELOG_FILE_PATH )
135
+ env = os .environ
136
+ env [ENVVAR_GORELEASER_CUSTOMISED_TAG ] = version
137
+ env [ENVVAR_GORELEASER_GIT_TOKEN ] = configuration .get_value (ConfigurationVariable .GIT_TOKEN )
138
+ check_call (_generate_goreleaser_release_command_list (changelogPath ), cwd = ROOT_DIR , env = env )
0 commit comments