Open chadwcarlson opened 2 years ago
Better example,
migrate.py
# migrate.py in template-builder root
import os
import json
import dodo
from datetime import datetime
template = 'drupal9'
mypath = "{0}/templates/{1}/files".format(os.getcwd(), template)
template_link = 'https://raw.githubusercontent.com/platformsh/template-builder/master/'
def get_files(path, depth):
"""Retrieve files added to upstream templates."""
depth -= 1
with os.scandir(path) as p:
for entry in p:
file_link = entry.path.replace("{0}/".format(mypath),template_link)
yield file_link
if entry.is_dir() and depth > 0:
yield from get_files(entry.path, depth)
def get_commands(data):
# data = dodo.project_factory(template).update
commands = []
for item in data:
if isinstance(item, str):
if 'echo' not in item and 'git' not in item and 'rsync' not in item:
if "&&" in item:
if len(item.split(" && ")) == 2:
new_item = item.split(" && ")[1]
# print(new_item)
if 'composer require' in new_item:
commands.append(new_item.split(" --")[0])
else:
commands.append(item.split(" && ")[1])
else:
commands.append(item)
return commands
def get_update_commands():
return get_commands(dodo.project_factory(template).update)
def get_platformify_commands():
return get_commands(dodo.project_factory(template).platformify)
migrate_files = list(get_files(mypath, 10))
update_commands = get_update_commands()
platformify_commands = get_platformify_commands()
data = {
"template": template,
"last_updated_on": datetime.today().strftime('%Y-%m-%d-%H:%M:%S'),
"migration": {
"files": migrate_files,
"commands": [*update_commands, *platformify_commands]
}
}
json_data=json.dumps(data, indent = 4)
with open("{0}/templates/{1}/.platform.migrate.json".format(os.getcwd(), template), "w") as outfile:
outfile.write(json_data)
templates/drupal9/.platform.migrate.json
{
"template": "drupal9",
"last_updated_on": "2022-02-24-11:51:24",
"migration": {
"files": [
"https://raw.githubusercontent.com/platformsh/template-builder/master/config",
"https://raw.githubusercontent.com/platformsh/template-builder/master/config/sync",
"https://raw.githubusercontent.com/platformsh/template-builder/master/config/sync/.gitkeep",
"https://raw.githubusercontent.com/platformsh/template-builder/master/web",
"https://raw.githubusercontent.com/platformsh/template-builder/master/web/sites",
"https://raw.githubusercontent.com/platformsh/template-builder/master/web/sites/default",
"https://raw.githubusercontent.com/platformsh/template-builder/master/web/sites/default/settings.php",
"https://raw.githubusercontent.com/platformsh/template-builder/master/web/sites/default/settings.platformsh.php",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.editorconfig",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.environment",
"https://raw.githubusercontent.com/platformsh/template-builder/master/README.md",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.gitignore",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.lando.upstream.yml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform.app.yaml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/drush",
"https://raw.githubusercontent.com/platformsh/template-builder/master/drush/platformsh_generate_drush_yml.php",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform/services.yaml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform/routes.yaml"
],
"commands": [
"composer require platformsh/config-reader drush/drush drupal/redis"
]
}
}
templates/laravel/.platform.migrate.json
{
"template": "laravel",
"last_updated_on": "2022-02-24-11:51:09",
"migration": {
"files": [
"https://raw.githubusercontent.com/platformsh/template-builder/master/README.md",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.lando.upstream.yml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform.app.yaml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform/services.yaml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform/routes.yaml"
],
"commands": [
"composer require platformsh/laravel-bridge"
]
}
}
Things to consider:
{
"template": "wordpress-composer",
"last_updated_on": "2022-02-24-14:18:10",
"migration": {
"files": [
"https://raw.githubusercontent.com/platformsh/template-builder/master/wp-config.php",
"https://raw.githubusercontent.com/platformsh/template-builder/master/wp-cli.yml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/plugins",
"https://raw.githubusercontent.com/platformsh/template-builder/master/plugins/README.txt",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.editorconfig",
"https://raw.githubusercontent.com/platformsh/template-builder/master/README.md",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.gitignore",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.lando.upstream.yml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform.app.yaml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/example.wp-config-local.php",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform/services.yaml",
"https://raw.githubusercontent.com/platformsh/template-builder/master/.platform/routes.yaml"
],
"commands": [
"composer config platform.php 7.4",
"composer update",
"composer require platformsh/config-reader wp-cli/wp-cli-bundle psy/psysh",
"composer require None",
"composer config --unset platform"
]
}
}
Need a list of changed files and steps that can be exposed to config builder.
Tests: