-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update implementation of git-based tags
- Loading branch information
Showing
4 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
github, | ||
kube, | ||
setup, | ||
tag, | ||
yq, | ||
) | ||
|
||
|
@@ -17,5 +18,6 @@ | |
"github", | ||
"kube", | ||
"setup", | ||
"tag", | ||
"yq", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Generate an artifact tag based on the git environment""" | ||
|
||
import argparse | ||
|
||
from mads.environ.git import Git | ||
|
||
|
||
def register_subcommand(parser: argparse.ArgumentParser): | ||
"""Register the environ command""" | ||
|
||
def run(args): | ||
"""Run the query""" | ||
|
||
git = Git() | ||
|
||
print( | ||
git.artifact_tag( | ||
*args.prefix, | ||
use_branch=args.use_branch, | ||
default=args.default, | ||
) | ||
) | ||
|
||
parser.set_defaults(func=run) | ||
parser.add_argument("prefix", nargs="*", help="Prefix for the tag") | ||
parser.add_argument( | ||
"--use-branch", | ||
action="store_true", | ||
help="Use the branch name rather than a semantic equivalent", | ||
default=False, | ||
) | ||
|
||
parser.add_argument( | ||
"--default", | ||
default="dev", | ||
help="Default tag to use if no branch is found", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from mads.environ.git import Git | ||
|
||
|
||
def test_artifact_tag_main_branch(): | ||
g = Git(branch="main") | ||
|
||
assert g.branch == "main" | ||
|
||
# On the main branch, the default behavior is to return "latest" | ||
assert g.artifact_tag() == "latest" | ||
|
||
# If using a prefix, the main branch behavior includes no suffix | ||
assert g.artifact_tag("feature") == "feature" | ||
|
||
# If use_branch, prefer the branch name over "latest" | ||
assert g.artifact_tag(use_branch=True) == "main" | ||
|
||
# If use_branch and a prefix, include the branch name instead of omitting | ||
assert g.artifact_tag("feature", use_branch=True) == "feature" | ||
|
||
|
||
def test_artifact_tag_feature_branch(): | ||
g = Git(branch="feature/123") | ||
|
||
assert g.branch == "feature/123" | ||
|
||
# On a feature branch, the default behavior is to return "dev" | ||
assert g.artifact_tag() == "dev" | ||
|
||
# If using a prefix, the feature branch behavior includes the prefix | ||
assert g.artifact_tag("feature") == "feature-dev" | ||
|
||
# If use_branch, prefer the branch name over "dev" | ||
assert g.artifact_tag(use_branch=True) == "feature/123" | ||
|
||
# If use_branch and a prefix, include the branch name instead of omitting | ||
assert g.artifact_tag("feature", use_branch=True) == "feature-feature/123" |