Skip to content

Add Tag manager script#185

Open
yaswant wants to merge 9 commits intoMetOffice:mainfrom
yaswant:tagman
Open

Add Tag manager script#185
yaswant wants to merge 9 commits intoMetOffice:mainfrom
yaswant:tagman

Conversation

@yaswant
Copy link
Collaborator

@yaswant yaswant commented Feb 9, 2026

PR Summary

Sci/Tech Reviewer: @r-sharp
Code Reviewer: @t00sa

Script to manage (add, delete, list) tags in a repository.

Code Quality Checklist

  • I have performed a self-review of my own code
  • My code follows the project's style guidelines
  • Comments have been included that aid understanding and enhance the readability of the code
  • My changes generate no new warnings
  • All automated checks in the CI pipeline have completed successfully

Testing

  • This change has been tested appropriately (please describe)

Security Considerations

  • I have reviewed my changes for potential security issues
  • Sensitive data is properly handled (if applicable)
  • Authentication and authorisation are properly implemented (if applicable)

AI Assistance and Attribution

  • Some of the content of this change has been produced with the assistance of Generative AI tool name (e.g., Met Office Github Copilot Enterprise, Github Copilot Personal, ChatGPT GPT-4, etc) and I have followed the Simulation Systems AI policy (including attribution labels)

Sci/Tech Review

  • I understand this area of code and the changes being added
  • The proposed changes correspond to the pull request description
  • Documentation is sufficient (do documentation papers need updating)
  • Sufficient testing has been completed

(Please alert the code reviewer via a tag when you have approved the SR)

Code Review

  • All dependencies have been resolved
  • Related Issues have been properly linked and addressed
  • Code quality standards have been met
  • Tests are adequate and have passed
  • Security considerations have been addressed
  • Performance impact is acceptable

@yaswant yaswant added this to the Spring 2026 milestone Feb 9, 2026
@yaswant yaswant added the enhancement New feature or request label Feb 9, 2026
@github-actions github-actions bot requested a review from r-sharp February 10, 2026 09:37
@yaswant yaswant removed the request for review from james-bruten-mo February 10, 2026 09:38
Copy link
Contributor

@r-sharp r-sharp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the following comment :

Requires:

GitHub CLI (gh): https://cli.github.com/

Git command-line tool: https://git-scm.com/

A similar reference should be made to 'jq' as a JSON specific 'sed' like tool is hardly commonplace.

Also, given the number of subroutines and relieance on required non standard 'libraries', I do have to question if bash was the tool the job. I can't help but feel something more adept at variable handling and argument passing would have been a better tool and would have been easier for subsequent maintainers to read and follow.

Taking the first argument as a comment and then essentially executing the remaining arguments to test for a non-zero return code doesn't strike me as the healthiest way to go about things. This has the feel of something hacked together to use at a specific time, and then throw away, rather than something to be retained for future use which would mean it's perhaps best not added to the repository.

sbin/tagman Outdated

set -euo pipefail
# Colour codes for output
GRN='\033[0;32m'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GRN='\033[0;32m'
GREEN='\033[0;32m'

Please use full words in variable names for future clarity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback. However, NC (No Color) is an extremely well-established convention in bash scripting for ANSI colour codes, alongside RED, GRN (Green), YLW (Yellow), etc. These abbreviations are widely recognised in the shell scripting community. Using full words like NO_COLOR or RESET_COLOR_CODE would make the code unnecessarily verbose without improving clarity for anyone familiar with bash scripting conventions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid I disagree.
The fact that I didn't know what NC was indicates it's not a sufficiently7 well known convention.

Variable names should be full, not abbreviated, words wherever possible for clarity.

sbin/tagman Outdated
# Colour codes for output
GRN='\033[0;32m'
RED='\033[0;31m'
YLW='\033[0;33m'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
YLW='\033[0;33m'
YELLOW='\033[0;33m'

Please use full words in variable names for future clarity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

sbin/tagman Outdated
GRN='\033[0;32m'
RED='\033[0;31m'
YLW='\033[0;33m'
NC='\033[0m'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is 'NC' ?
not remotely clear, Plaese use full words in variable names.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

sbin/tagman Outdated
Comment on lines 34 to 64
Usage:
$(basename "$0") add <tag_name> <commit_ref> [options]
$(basename "$0") delete|del <tag_name> [options]
$(basename "$0") list|ls [options]

Actions:
add Create and push a new tag
delete Delete a tag from the repository (alias: del)
list List all tags in the repository (alias: ls)

Arguments:
<tag_name> Name of the tag to create or delete
<commit_ref> Commit SHA, tag name, release name, or branch name

Options:
--repo, -R REPO Repository in format owner/repo (default: $DEFAULT_REPO)
--message MSG Tag annotation message (for add action)
--dry-run, -n Show what would be done without making changes

Examples:
# Create tag from commit SHA
$(basename "$0") add v1.0.0 abc123def --repo MetOffice/git_playground

# Create tag from existing tag
$(basename "$0") add Test vn1.5 --repo MetOffice/git_playground

# Create tag from release
$(basename "$0") add Autumn2025 vn14.0 --repo MetOffice/um

# Create tag from branch
$(basename "$0") add Spring2026 main --repo MetOffice/SimSys_Scripts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too Long.
I can't even get the whole 'Usage' block on a single screen in order to highlight it for a comment.
43 lines is going to be more than most terminal heights.
Consider significantly less examples, which seem to be overkill

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the concern about screen real estate, but I respectfully disagree that this is excessive. Still I have a feeling that you can convince me to shorten this ;)

The usage function serves as both immediate help and documentation for users who may not have access to or won't read separate documentation. It provides:

  • Clear syntax for all three actions (add/delete/list)
  • Available options and their formats
  • Five practical examples covering different use cases
  • Important notes about behaviour

⚠️ This script performs potentially destructive Git operations (creating/deleting tags in production repositories). Comprehensive examples aren't "overkill" - they help prevent user errors that could have significant consequences. Each example demonstrates a distinct use case:

  1. Tag from commit SHA (most common)
  2. Tag from existing tag
  3. Tag from release (cross-repo workflow)
  4. Tag from branch
  5. Delete operation

Users can scroll or pipe to less if needed: tagman | less
Terminal heights vary, but scrolling is expected for help text
If there's a specific concern about this blocking adoption or causing issues, I'm open to discussing it, but cutting back examples would make the tool harder to use correctly, especially for destructive operations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel all the examples are neccessary as there is insufficient difference between what needs to be written (as a command)

The first 3 examples are all the same. Purely the syntax of the commit being supplied ha=s changed. There is no fundemental difference between the three examples.

In FCM we didn't feel the need to provide examples using revisions & keywords & tags as all three were interchangable.

"Terminal heights vary, but scrolling is expected for help text" it most certainly isn't.

Even this response is TL;DR

sbin/tagman Outdated
}

cleanup() {
[[ -n "${WORK_TMP:-}" ]] && rm -rf "$WORK_TMP"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[[ -n "${WORK_TMP:-}" ]] && rm -rf "$WORK_TMP"
if test -n "${WORK_TMP:-}"; then
rm -rf "$WORK_TMP"
fi

Please use full, clear code, not clever contractions. This isn't Java.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate your attention to code clarity. The [[ ]] construct is actually the recommended modern bash syntax over test or [ ]. It's more robust, handles edge cases better (like empty strings), supports pattern matching, and is explicitly recommended in the Google Shell Style Guide and other authoritative sources. This isn't a "clever contraction" but rather best practice for bash scripting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The [[]] isn't the contraction I'm refferring to "&&" is
Please use a proper if then statement.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

sbin/tagman Outdated

case "$ACTION" in
add)
[[ $# -lt 2 ]] && usage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[[ $# -lt 2 ]] && usage
if test $# -lt 2 ; then
usage
fi

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aas above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above - I don't see why not.

sbin/tagman Outdated
shift 2
;;
del|delete)
[[ $# -lt 1 ]] && usage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[[ $# -lt 1 ]] && usage
if test $# -lt 1 ; then
usage
fi

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as abopve

# No arguments required
;;
*)
echo -e "${RED}Unknown action: $ACTION${NC}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo -e "${RED}Unknown action: $ACTION${NC}"
echo -e "${RED}Unknown action: $ACTION${NORMAL_COUNTENANCE}"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change cannot be applied.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but a change is still required.

--message) MESSAGE="$2"; shift 2 ;;
-n|--dry-run) DRY_RUN=true; shift ;;
*)
echo -e "${RED}Unknown option: $1${NC}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo -e "${RED}Unknown option: $1${NC}"
echo -e "${RED}Unknown option: $1${NASTY_CARROT}"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change cannot be applied.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

add) add_tag ;;
del|delete) delete_tag ;;
ls|list) list_tags ;;
*) echo -e "${RED}Invalid action: $ACTION${NC}" ;;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*) echo -e "${RED}Invalid action: $ACTION${NC}" ;;
*) echo -e "${RED}Invalid action: $ACTION${NOTABLE_CAULIFLOWER}" ;;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change cannot be applied.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

@yaswant
Copy link
Collaborator Author

yaswant commented Feb 13, 2026

@r-sharp I appreciate you taking the time to review this thoroughly. Thanks for the suggestion re jq - I'll update the comment section to include it. However, I respectfully disagree with this assessment. I've replied to your individual comments/suggested changes as well.

Regarding tool choice:
Bash is the appropriate tool for this task. The script's purpose is Git tag management - fundamentally a command-line operation that requires executing git/gh commands, which bash excels at. The "non-standard libraries" you mention are:

  • GitHub CLI (gh) - the official GitHub tool
  • jq - industry-standard JSON processor
  • Git itself

These are standard tools in our development environment and are explicitly documented in the requirements. Rewriting this in Python or another language would add unnecessary complexity, dependencies, and overhead for what is essentially orchestrating CLI commands.

Regarding maintainability:
The code is well-structured with descriptive function names, clear separation of concerns, and extensive comments. Anyone familiar with bash (a core skill for system administrators and DevOps engineers) can maintain this.

I welcome discussion about genuine improvements, but the suggestion that this is throwaway code or shouldn't be in the repository doesn't reflect the actual code quality or appropriateness of the implementation.

@yaswant yaswant requested review from r-sharp and t00sa February 13, 2026 02:23
Copy link
Contributor

@r-sharp r-sharp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bash may well be the appropriate tool for executing shell commands, it is not a particualrly good tool for more involved programming such as concoluted logic, subroutines and operations with multiple paths throughthe operation.

""" The "non-standard libraries" you mention are:

GitHub CLI (gh) - the official GitHub tool
jq - industry-standard JSON processor
Git itself

"""
I only mentioned them, because you felt the need to. The fact that you felt the need to list them as prerequestits indicates that there is an acceptance on your part that they may not be present.
My feeling was that if you had to ensure the presence of those libraries for use with bash, was no different from having to ensure similar librararies to perform the same functions where equally available in a python script.

I don't agree that this would be more complex in python, it would be broadly similar but wouldn't be quite so convoluted.

"""Regarding maintainability:
The code is well-structured with descriptive function names, clear separation of concerns, and extensive comments."""
I disagree, or I wouldn't have added the comments I added.
All the comments I made are where the code was not clear and where I had pause reading the logic to think and backtrack to establish what was goping on.

If contractions and abbreviations are so easy to follow, then why are natural langue models/ML and AI becoming so popular ? Verbosity is not a bad thing if it improves the speed at which the information can be ingested and adsorbed without the need for additional processing.
Not having to translate what is being read into something with meaning internally saves time and effort.

"""Anyone familiar with bash (a core skill for system administrators and DevOps engineers) can maintain this."""
Then I guess you'd better sack me and emploty someone with those skills instead.

The purpose of a review is to provide feedback and appropriate requested changes.
If you're just going to overule the reviewer then we might as well jusst rubber stamp everything and move on.
I have made comments where I had to think about what you were trying to do rather than just reading a logical progression through a series of commands.

I will not accept YLW, GRN, NC, && and ||, They are not immediuately clear to the reader and would be improved by YELLOW, GREEN, , "if ; then" and " if !; then"

@yaswant yaswant requested a review from r-sharp February 13, 2026 10:02
@yaswant yaswant requested a review from r-sharp February 13, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants