Fix update winrepo script on 3006.x

This commit is contained in:
Shane Lee 2024-02-21 12:18:00 -07:00
parent ce9d09bc9c
commit c6991e22ce
No known key found for this signature in database
GPG key ID: 9B77EE3C5C0D9F63
2 changed files with 17 additions and 3 deletions

View file

@ -41,9 +41,12 @@ jobs:
- name: Add Version to Minion Definition File
working-directory: salt
run: |
pwd
ls -al ../winrepo/salt-minion.sls
python .github/workflows/scripts/update_winrepo.py \
--file ../winrepo/salt-minion.sls \
--version ${{ inputs.salt-version || github.ref_name }}
grep ${{ inputs.salt-version || github.ref_name }} ../winrepo/salt-minion.sls
- name: Commit Changes
working-directory: winrepo

View file

@ -1,8 +1,10 @@
import argparse
import os
print("Update winrepo script")
# Where are we
print(os.getcwd())
print(f"Current working directory: {os.getcwd()}")
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument("-f", "--file", help="the winrepo file to edit")
@ -12,10 +14,15 @@ args = arg_parser.parse_args()
file = args.file
version = args.version
print("Args:")
print(f"- file: {file}")
print(f"- version: {version}")
if version.startswith("v"):
version = version[1:]
with open(file) as f:
print(f"Opening file: {file}")
current_contents = f.readlines()
new_contents = []
@ -23,9 +30,13 @@ new_contents = []
added = False
for line in current_contents:
new_contents.append(line)
if "for version in [" in line and not added:
new_contents.append(f" '{version}',\n")
if "load_yaml as versions_relenv" in line and not added:
print(f"Adding version: {version}")
new_contents.append(f"- {version}\n")
added = True
with open(file, "w") as f:
print(f"Writing file: {file}")
f.writelines(new_contents)
print("Update winrepo script complete")