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

use a variable for php version (phpMM) and utilize pipelines in php files. #32344

Merged
merged 5 commits into from
Oct 30, 2024

Conversation

smoser
Copy link
Member

@smoser smoser commented Oct 30, 2024

Update the php-8.-.yaml files to have use a var transform based on package name for the php version, and then use replace any use of php version with that variable.

Also here:

@smoser
Copy link
Member Author

smoser commented Oct 30, 2024

python program that made the bulk of these changes (inserting phpMM), executed as python3 ./tmpl-phps php-8.*-*.yaml:

#!/usr/bin/python3
import re
import sys
import subprocess

re.compile(r"abc")
namepre = "php-8."
varname = "phpMM"
vartok = "${{vars." + varname + "}}"
repl = re.compile(r"([^a-zA-Z]php[-]{0,1})(\d[.]\d+)")

blob = r"""
var-transforms:
  - from: ${{package.name}}
    match: ^php-(\d+\.\d+)-.*$
    replace: "$1"
    to: phpMM
"""

changed = []
for fname in sys.argv[1:]:
    if not fname.startswith(namepre):
        print(f"SKIP: {fname} not {namepre}")
        continue
    if not fname.endswith(".yaml"):
        print(f"SKIP: {fname} not yaml")
        continue
    with open(fname, "r") as fp:
        ocontent = fp.read()
    if varname in ocontent:
        print(f"SKIP: {fname} already had {varname}")
        continue
    pname = fname[0:-len(".yaml")]

    ncontent = repl.sub(r"\1" + vartok, ocontent)

    # now substitute *back* the 'name: php-' as we don't
    # want it updated.
    pver = fname[len("php-"):len("php-")+len("8.3")]
    ncontent = ncontent.replace(f"name: php-{vartok}-",
                                f"name: php-{pver}-", 1)

    # and insert the var-transform blob
    pos = ncontent.index("\nenvironment:")
    ncontent = ncontent[0:pos] + blob + ncontent[pos+1:]
    print(f"UPDATE: {fname}")
    with open(fname, "w") as fp:
        fp.write(ncontent)
    changed.append(fname)
    continue


subprocess.check_output(["yam"] + changed)
subprocess.check_output(["wolfictl", "bump"] + changed)

sys.exit(0)

@smoser smoser marked this pull request as draft October 30, 2024 15:34
@smoser smoser marked this pull request as ready for review October 30, 2024 15:45
@smoser smoser enabled auto-merge (squash) October 30, 2024 15:46
@smoser smoser merged commit e0dda80 into wolfi-dev:main Oct 30, 2024
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants