@@ -44,14 +44,16 @@ <h1 class="title">Module <code>continuous_delivery_scripts.plugins.golang</code>
44
44
from continuous_delivery_scripts.utils.language_specifics_base import BaseLanguage, get_language_from_file_name
45
45
from continuous_delivery_scripts.spdx_report.spdx_project import SpdxProject
46
46
from continuous_delivery_scripts.utils.configuration import configuration, ConfigurationVariable
47
- from continuous_delivery_scripts.utils.git_helpers import LocalProjectRepository
47
+ from continuous_delivery_scripts.utils.git_helpers import LocalProjectRepository, GitWrapper
48
48
49
49
logger = logging.getLogger(__name__)
50
50
51
- SRC_DIR = configuration.get_value(ConfigurationVariable.SOURCE_DIR)
52
- ROOT_DIR = configuration.get_value(ConfigurationVariable.PROJECT_ROOT)
51
+ SRC_DIR = Path(str( configuration.get_value(ConfigurationVariable.SOURCE_DIR)) )
52
+ ROOT_DIR = Path(str( configuration.get_value(ConfigurationVariable.PROJECT_ROOT)) )
53
53
ENVVAR_GORELEASER_GIT_TOKEN = "GITHUB_TOKEN"
54
54
ENVVAR_GORELEASER_CUSTOMISED_TAG = "GORELEASER_CURRENT_TAG"
55
+ ENVVAR_GO_MOD = "GO111MODULE"
56
+ GO_MOD_ON_VALUE = "on"
55
57
56
58
57
59
def _generate_golds_command_list(output_directory: Path, module: str) -> List[str]:
@@ -86,20 +88,43 @@ <h1 class="title">Module <code>continuous_delivery_scripts.plugins.golang</code>
86
88
def _call_golds(output_directory: Path, module: str) -> None:
87
89
"""Calls Golds for generating the docs."""
88
90
logger.info("Installing Golds if missing.")
89
- check_call(_install_golds_command_list())
91
+ env = os.environ
92
+ env[ENVVAR_GO_MOD] = GO_MOD_ON_VALUE
93
+ check_call(_install_golds_command_list(), env=env)
90
94
logger.info("Creating Golds documentation.")
91
- check_call(_generate_golds_command_list(output_directory, module), cwd=SRC_DIR)
95
+ check_call(_generate_golds_command_list(output_directory, module), cwd=SRC_DIR, env=env )
92
96
93
97
94
98
def _call_goreleaser_check(version: str) -> None:
95
99
"""Calls go releaser check to verify configuration."""
96
100
logger.info("Installing GoReleaser if missing.")
97
- check_call(_install_goreleaser_command_list())
98
- logger.info("Checking GoReleaser configuration.")
99
101
env = os.environ
102
+ env[ENVVAR_GO_MOD] = GO_MOD_ON_VALUE
103
+ check_call(_install_goreleaser_command_list(), env=env)
104
+ logger.info("Checking GoReleaser configuration.")
100
105
env[ENVVAR_GORELEASER_CUSTOMISED_TAG] = version
101
106
env[ENVVAR_GORELEASER_GIT_TOKEN] = configuration.get_value(ConfigurationVariable.GIT_TOKEN)
102
- check_call(_generate_goreleaser_check_command_list(), cwd=ROOT_DIR)
107
+ check_call(_generate_goreleaser_check_command_list(), cwd=ROOT_DIR, env=env)
108
+
109
+
110
+ def _determine_go_module_tag(version) -> Optional[str]:
111
+ """Determines go module for tagging.
112
+
113
+ See https://golang.org/ref/mod#vcs-version.
114
+ and https://github.com/golang/go/wiki/Modules#should-i-have-multiple-modules-in-a-single-repository.
115
+ """
116
+ module = ""
117
+ try:
118
+ module = str(SRC_DIR.relative_to(ROOT_DIR))
119
+ except ValueError:
120
+ try:
121
+ module = str(ROOT_DIR.relative_to(SRC_DIR))
122
+ except ValueError as exception:
123
+ logger.warning(exception)
124
+ if module == "." or len(module) == 0:
125
+ return None
126
+ module = module.rstrip("/")
127
+ return f"{module}/{version}"
103
128
104
129
105
130
class Go(BaseLanguage):
@@ -151,10 +176,19 @@ <h1 class="title">Module <code>continuous_delivery_scripts.plugins.golang</code>
151
176
"""States whether the repository must be cleaned before packaging happens."""
152
177
return True
153
178
179
+ def tag_release(self, git: GitWrapper, version: str) -> None:
180
+ """Tags release commit."""
181
+ super().tag_release(git, version)
182
+ go_tag = _determine_go_module_tag(self.get_version_tag(version))
183
+ if go_tag:
184
+ git.create_tag(go_tag, message=f"Golang module release: {go_tag}")
185
+
154
186
def _call_goreleaser_release(self, version: str) -> None:
155
187
"""Calls go releaser release to upload packages."""
156
188
logger.info("Installing GoReleaser if missing.")
157
- check_call(_install_goreleaser_command_list())
189
+ env = os.environ
190
+ env[ENVVAR_GO_MOD] = GO_MOD_ON_VALUE
191
+ check_call(_install_goreleaser_command_list(), env=env)
158
192
tag = self.get_version_tag(version)
159
193
# The tag of the release must be retrieved
160
194
# See https://github.com/goreleaser/goreleaser/discussions/1426
@@ -165,7 +199,6 @@ <h1 class="title">Module <code>continuous_delivery_scripts.plugins.golang</code>
165
199
git.checkout(f"tags/{tag}")
166
200
logger.info("Release package.")
167
201
changelogPath = configuration.get_value(ConfigurationVariable.CHANGELOG_FILE_PATH)
168
- env = os.environ
169
202
env[ENVVAR_GORELEASER_CUSTOMISED_TAG] = tag
170
203
env[ENVVAR_GORELEASER_GIT_TOKEN] = configuration.get_value(ConfigurationVariable.GIT_TOKEN)
171
204
check_call(_generate_goreleaser_release_command_list(changelogPath), cwd=ROOT_DIR, env=env)</ code > </ pre >
@@ -238,10 +271,19 @@ <h2 class="section-title" id="header-classes">Classes</h2>
238
271
"""States whether the repository must be cleaned before packaging happens."""
239
272
return True
240
273
274
+ def tag_release(self, git: GitWrapper, version: str) -> None:
275
+ """Tags release commit."""
276
+ super().tag_release(git, version)
277
+ go_tag = _determine_go_module_tag(self.get_version_tag(version))
278
+ if go_tag:
279
+ git.create_tag(go_tag, message=f"Golang module release: {go_tag}")
280
+
241
281
def _call_goreleaser_release(self, version: str) -> None:
242
282
"""Calls go releaser release to upload packages."""
243
283
logger.info("Installing GoReleaser if missing.")
244
- check_call(_install_goreleaser_command_list())
284
+ env = os.environ
285
+ env[ENVVAR_GO_MOD] = GO_MOD_ON_VALUE
286
+ check_call(_install_goreleaser_command_list(), env=env)
245
287
tag = self.get_version_tag(version)
246
288
# The tag of the release must be retrieved
247
289
# See https://github.com/goreleaser/goreleaser/discussions/1426
@@ -252,7 +294,6 @@ <h2 class="section-title" id="header-classes">Classes</h2>
252
294
git.checkout(f"tags/{tag}")
253
295
logger.info("Release package.")
254
296
changelogPath = configuration.get_value(ConfigurationVariable.CHANGELOG_FILE_PATH)
255
- env = os.environ
256
297
env[ENVVAR_GORELEASER_CUSTOMISED_TAG] = tag
257
298
env[ENVVAR_GORELEASER_GIT_TOKEN] = configuration.get_value(ConfigurationVariable.GIT_TOKEN)
258
299
check_call(_generate_goreleaser_release_command_list(changelogPath), cwd=ROOT_DIR, env=env)</ code > </ pre >
@@ -377,6 +418,7 @@ <h3>Inherited members</h3>
377
418
< li > < code > < a title ="continuous_delivery_scripts.utils.language_specifics_base.BaseLanguage.generate_source_licence_header_template " href ="../utils/language_specifics_base.html#continuous_delivery_scripts.utils.language_specifics_base.BaseLanguage.generate_source_licence_header_template "> generate_source_licence_header_template</ a > </ code > </ li >
378
419
< li > < code > < a title ="continuous_delivery_scripts.utils.language_specifics_base.BaseLanguage.should_clean_before_packaging " href ="../utils/language_specifics_base.html#continuous_delivery_scripts.utils.language_specifics_base.BaseLanguage.should_clean_before_packaging "> should_clean_before_packaging</ a > </ code > </ li >
379
420
< li > < code > < a title ="continuous_delivery_scripts.utils.language_specifics_base.BaseLanguage.should_include_spdx_in_package " href ="../utils/language_specifics_base.html#continuous_delivery_scripts.utils.language_specifics_base.BaseLanguage.should_include_spdx_in_package "> should_include_spdx_in_package</ a > </ code > </ li >
421
+ < li > < code > < a title ="continuous_delivery_scripts.utils.language_specifics_base.BaseLanguage.tag_release " href ="../utils/language_specifics_base.html#continuous_delivery_scripts.utils.language_specifics_base.BaseLanguage.tag_release "> tag_release</ a > </ code > </ li >
380
422
</ ul >
381
423
</ li >
382
424
</ ul >
0 commit comments