Skip to content

Commit e7431a2

Browse files
authored
Fixing issue with goreleaser (#29)
1 parent 3fb0fec commit e7431a2

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

continuous_delivery_scripts/plugins/golang.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from continuous_delivery_scripts.utils.language_specifics_base import BaseLanguage, get_language_from_file_name
1212
from continuous_delivery_scripts.spdx_report.spdx_project import SpdxProject
1313
from continuous_delivery_scripts.utils.configuration import configuration, ConfigurationVariable
14+
from continuous_delivery_scripts.utils.git_helpers import LocalProjectRepository
1415

1516
logger = logging.getLogger(__name__)
1617

@@ -68,18 +69,6 @@ def _call_goreleaser_check(version: str) -> None:
6869
check_call(_generate_goreleaser_check_command_list(), cwd=ROOT_DIR)
6970

7071

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-
8372
class Go(BaseLanguage):
8473
"""Specific actions for a Golang project."""
8574

@@ -100,7 +89,7 @@ def package_software(self, version: str) -> None:
10089
def release_package_to_repository(self, version: str) -> None:
10190
"""No operation."""
10291
super().release_package_to_repository(version)
103-
_call_goreleaser_release(version)
92+
self._call_goreleaser_release(version)
10493

10594
def check_credentials(self) -> None:
10695
"""Checks any credentials."""
@@ -128,3 +117,22 @@ def get_current_spdx_project(self) -> Optional[SpdxProject]:
128117
def should_clean_before_packaging(self) -> bool:
129118
"""States whether the repository must be cleaned before packaging happens."""
130119
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)

news/202108242248.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed issue with goreleaser requiring tag to be checked out

0 commit comments

Comments
 (0)