@@ -44,6 +44,7 @@ <h1 class="title">Module <code>continuous_delivery_scripts.plugins.golang</code>
4444from continuous_delivery_scripts.utils.language_specifics_base import BaseLanguage, get_language_from_file_name
4545from continuous_delivery_scripts.spdx_report.spdx_project import SpdxProject
4646from continuous_delivery_scripts.utils.configuration import configuration, ConfigurationVariable
47+ from continuous_delivery_scripts.utils.git_helpers import LocalProjectRepository
4748
4849logger = logging.getLogger(__name__)
4950
@@ -101,18 +102,6 @@ <h1 class="title">Module <code>continuous_delivery_scripts.plugins.golang</code>
101102 check_call(_generate_goreleaser_check_command_list(), cwd=ROOT_DIR)
102103
103104
104- def _call_goreleaser_release(version: str) -> None:
105- """Calls go releaser release to upload packages."""
106- logger.info("Installing GoReleaser if missing.")
107- check_call(_install_goreleaser_command_list())
108- logger.info("Release package.")
109- changelogPath = configuration.get_value(ConfigurationVariable.CHANGELOG_FILE_PATH)
110- env = os.environ
111- env[ENVVAR_GORELEASER_CUSTOMISED_TAG] = version
112- env[ENVVAR_GORELEASER_GIT_TOKEN] = configuration.get_value(ConfigurationVariable.GIT_TOKEN)
113- check_call(_generate_goreleaser_release_command_list(changelogPath), cwd=ROOT_DIR, env=env)
114-
115-
116105class Go(BaseLanguage):
117106 """Specific actions for a Golang project."""
118107
@@ -133,7 +122,7 @@ <h1 class="title">Module <code>continuous_delivery_scripts.plugins.golang</code>
133122 def release_package_to_repository(self, version: str) -> None:
134123 """No operation."""
135124 super().release_package_to_repository(version)
136- _call_goreleaser_release(version)
125+ self. _call_goreleaser_release(version)
137126
138127 def check_credentials(self) -> None:
139128 """Checks any credentials."""
@@ -160,7 +149,26 @@ <h1 class="title">Module <code>continuous_delivery_scripts.plugins.golang</code>
160149
161150 def should_clean_before_packaging(self) -> bool:
162151 """States whether the repository must be cleaned before packaging happens."""
163- return True</ code > </ pre >
152+ return True
153+
154+ def _call_goreleaser_release(self, version: str) -> None:
155+ """Calls go releaser release to upload packages."""
156+ logger.info("Installing GoReleaser if missing.")
157+ check_call(_install_goreleaser_command_list())
158+ tag = self.get_version_tag(version)
159+ # The tag of the release must be retrieved
160+ # See https://github.com/goreleaser/goreleaser/discussions/1426
161+ logger.info(f"Checking out tag: {tag}.")
162+ with LocalProjectRepository() as git:
163+ git.configure_for_github()
164+ git.fetch()
165+ git.checkout(f"tags/{tag}")
166+ logger.info("Release package.")
167+ changelogPath = configuration.get_value(ConfigurationVariable.CHANGELOG_FILE_PATH)
168+ env = os.environ
169+ env[ENVVAR_GORELEASER_CUSTOMISED_TAG] = version
170+ env[ENVVAR_GORELEASER_GIT_TOKEN] = configuration.get_value(ConfigurationVariable.GIT_TOKEN)
171+ check_call(_generate_goreleaser_release_command_list(changelogPath), cwd=ROOT_DIR, env=env)</ code > </ pre >
164172</ details >
165173</ section >
166174< section >
@@ -201,7 +209,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
201209 def release_package_to_repository(self, version: str) -> None:
202210 """No operation."""
203211 super().release_package_to_repository(version)
204- _call_goreleaser_release(version)
212+ self. _call_goreleaser_release(version)
205213
206214 def check_credentials(self) -> None:
207215 """Checks any credentials."""
@@ -228,7 +236,26 @@ <h2 class="section-title" id="header-classes">Classes</h2>
228236
229237 def should_clean_before_packaging(self) -> bool:
230238 """States whether the repository must be cleaned before packaging happens."""
231- return True</ code > </ pre >
239+ return True
240+
241+ def _call_goreleaser_release(self, version: str) -> None:
242+ """Calls go releaser release to upload packages."""
243+ logger.info("Installing GoReleaser if missing.")
244+ check_call(_install_goreleaser_command_list())
245+ tag = self.get_version_tag(version)
246+ # The tag of the release must be retrieved
247+ # See https://github.com/goreleaser/goreleaser/discussions/1426
248+ logger.info(f"Checking out tag: {tag}.")
249+ with LocalProjectRepository() as git:
250+ git.configure_for_github()
251+ git.fetch()
252+ git.checkout(f"tags/{tag}")
253+ logger.info("Release package.")
254+ changelogPath = configuration.get_value(ConfigurationVariable.CHANGELOG_FILE_PATH)
255+ env = os.environ
256+ env[ENVVAR_GORELEASER_CUSTOMISED_TAG] = version
257+ env[ENVVAR_GORELEASER_GIT_TOKEN] = configuration.get_value(ConfigurationVariable.GIT_TOKEN)
258+ check_call(_generate_goreleaser_release_command_list(changelogPath), cwd=ROOT_DIR, env=env)</ code > </ pre >
232259</ details >
233260< h3 > Ancestors</ h3 >
234261< ul class ="hlist ">
@@ -337,7 +364,7 @@ <h3>Methods</h3>
337364< pre > < code class ="python "> def release_package_to_repository(self, version: str) -> None:
338365 """No operation."""
339366 super().release_package_to_repository(version)
340- _call_goreleaser_release(version)</ code > </ pre >
367+ self. _call_goreleaser_release(version)</ code > </ pre >
341368</ details >
342369</ dd >
343370</ dl >
0 commit comments