Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Support for github tags #219

Merged
3 changes: 3 additions & 0 deletions changelogs/fragments/support_git_tag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- add support for git tags.
48 changes: 48 additions & 0 deletions docs/ansible.scm.git_publish_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,54 @@ Parameters
<div>Remove the local copy of the repository if the push is successful</div>
</td>
</tr>
<tr>
<td colspan="2">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>tag</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">dictionary</span>
</div>
</td>
<td>
</td>
<td>
<div>Specify the tag details associated with the commit.</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>annotation</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>
</td>
<td>
<div>Specify annotate</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>message</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>
</td>
<td>
<div>Specify tag message</div>
</td>
</tr>

<tr>
<td colspan="2">
<div class="ansibleOptionAnchor" id="parameter-"></div>
Expand Down
16 changes: 16 additions & 0 deletions docs/ansible.scm.git_retrieve_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@ Parameters
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>tag</b>
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
<div style="font-size: small">
<span style="color: purple">string</span>
</div>
</td>
<td>
</td>
<td>
<div>Specify the tag</div>
</td>
</tr>
<tr>
<td class="elbow-placeholder"></td>
<td colspan="1">
<div class="ansibleOptionAnchor" id="parameter-"></div>
<b>token</b>
Expand Down
28 changes: 24 additions & 4 deletions plugins/action/git_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ def _commit(self: T) -> None:
)
self._run_command(command=command)

def _tag(self: T) -> None:
"""Create a tag object."""
command_parts = list(self._base_command)
message = self._task.args["tag"].get("message")
annotate = self._task.args["tag"]["annotation"]
command_parts.extend(["tag", "-a", annotate])
if message:
message = message.replace("'", '"')
command_parts.extend(["-m", message])
command = Command(
command_parts=command_parts,
fail_msg=f"Failed to perform tagging: {message}",
)
self._run_command(command=command)

def _push(self: T) -> None:
"""Push the commit to the origin."""
command_parts = list(self._base_command)
Expand Down Expand Up @@ -204,7 +219,10 @@ def _push(self: T) -> None:
command_parts.extend(command_parameters)
no_log[token_base64] = "<TOKEN>"

tag = self._task.args.get("tag")
command_parts.extend(["push", "origin", "HEAD"])
if tag:
rohitthakur2590 marked this conversation as resolved.
Show resolved Hide resolved
command_parts.extend(["--tags"])
command = Command(
command_parts=command_parts,
fail_msg="Failed to perform the push",
Expand Down Expand Up @@ -251,14 +269,16 @@ def run(
self._base_command = ("git", "-C", self._path_to_repo)
self._timeout = self._task.args["timeout"]

steps = (
steps = [
self._configure_git_user_name,
self._configure_git_user_email,
self._add,
self._commit,
self._push,
self._remove_repo,
)
]
if self._task.args.get("tag"):
steps.append(self._tag)

steps.extend([self._push, self._remove_repo])

for step in steps:
step()
Expand Down
18 changes: 15 additions & 3 deletions plugins/action/git_retrieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,18 @@ def _clone(self: T) -> None:
command_parts.extend(cli_parameters)
no_log[token_base64] = "<TOKEN>"

tag = self._task.args["origin"].get("tag")
command_parts.extend(
["clone", "--depth=1", "--progress", "--no-single-branch", origin],
["clone", "--depth=1", "--progress"],
)

if tag:
command_parts.extend(
["--branch", tag],
)
else:
command_parts.extend(
["--no-single-branch", origin],
)
command = Command(
command_parts=command_parts,
env=env,
Expand Down Expand Up @@ -262,7 +270,11 @@ def _switch_checkout(self: T) -> None:
if self._branch_exists:
command_parts.extend(["switch", branch])
else:
command_parts.extend(["checkout", "-t", "-b", branch])
tag = self._task.args["origin"].get("tag")
if tag:
command_parts.extend(["checkout", "-b", tag])
else:
command_parts.extend(["checkout", "-t", "-b", branch])

command = Command(
command_parts=command_parts,
Expand Down
11 changes: 11 additions & 0 deletions plugins/modules/git_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@
interacting with the origin repository
- Will only be used for https based connections
type: str
tag:
description:
- Specify the tag details associated with the commit.
type: dict
suboptions:
annotation:
description: Specify annotate
type: str
message:
description: Specify tag message
type: str
user:
description:
- Details for the user to be used for the commit
Expand Down
4 changes: 3 additions & 1 deletion plugins/modules/git_retrieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
description:
- The URL for the origin repository
type: str

tag:
description: Specify the tag
type: str
parent_directory:
description:
- The local directory where the repository will be placed
Expand Down