-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scripts for generating migration checkpoints in
template-infra
- Loading branch information
Showing
2 changed files
with
133 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/usr/bin/env bash | ||
# Convert a template-infra worktree into one that minimally supports the | ||
# Platform CLI tooling. | ||
# | ||
# Run from the root of a template-infra worktree. | ||
|
||
set -eu | ||
|
||
rename_file() { | ||
local original_file=$1 | ||
local renamed_file=$2 | ||
|
||
mkdir -p "${renamed_file%/*}" | ||
git mv "$original_file" "${renamed_file}" | ||
} | ||
|
||
rename_app_file() { | ||
local original_file=$1 | ||
local renamed_file="${original_file/app/{{app_name\}\}}" | ||
|
||
rename_file "${original_file}" "${renamed_file}" | ||
} | ||
|
||
if [[ -d .template-infra/ ]]; then | ||
echo "Already templatized" | ||
exit | ||
fi | ||
|
||
# get rid of example app junk | ||
find app -not -name Makefile -delete &> /dev/null || : | ||
git add -u | ||
|
||
# rename "app" files | ||
for f in $(git ls-files '*app*' | grep -v '^docs/' | grep -v 'template-only' | grep '\bapp\b'); do | ||
rename_app_file "${f}" | ||
done | ||
|
||
# rather than copy over the upstream copier file: | ||
# | ||
# curl -O https://raw.githubusercontent.com/navapbc/template-infra/refs/heads/main/copier.yml | ||
# | ||
# we'll use a simplified version, since the only variable we are using is | ||
# `app_name` | ||
cat <<EOF > copier.yml | ||
template: | ||
type: str | ||
choices: | ||
- base | ||
- app | ||
# | ||
# App vars | ||
# | ||
app_name: | ||
type: str | ||
help: The name of the app | ||
validator: >- | ||
{% if not (app_name | regex_search('^[a-z0-9\-_]+$')) %} | ||
The app name can not be empty and should only contain lower case letters, digits, dashes, and underscores. | ||
{% endif %} | ||
when: &app | ||
"{{ template == 'app' }}" | ||
_envops: | ||
trim_blocks: true | ||
lstrip_blocks: true | ||
_skip_if_exists: | ||
- "/{{ app_name }}/" | ||
- "/{{ app_name }}/Makefile" | ||
_exclude: | ||
- /.git | ||
- /copier.yml | ||
- /CODEOWNERS | ||
- /CONTRIBUTING.md | ||
- /LICENSE.md | ||
- /README.md | ||
EOF | ||
|
||
# create answers file | ||
mkdir .template-infra | ||
echo -e "# Changes here will be overwritten by Copier\n{{ _copier_answers|to_nice_yaml -}}" > '.template-infra/{{_copier_conf.answers_file}}.jinja' | ||
|
||
# fixup CI stuff, for file/path triggers | ||
for f in $(rg -l -e 'app/' -e '-app-' .github/ | grep -v 'template-only' | grep -v 'README.md'); do | ||
renamed_file=$f.jinja | ||
git mv "${f}" "${renamed_file}" | ||
sed -ri 's|app/|{{ app_name }}/|g' "${renamed_file}" | ||
# sed -ri 's|-app-|-{{ app_name }}-|g' "${renamed_file}" | ||
sed -ri "s/-app(\b.*yml)/-{{ app_name}}\1/g" "${renamed_file}" | ||
sed -ri "s/app_name: app/app_name: {{ app_name}}/g" "${renamed_file}" | ||
sed -ri 's/app_name: "app"/app_name: {{ app_name}}/g' "${renamed_file}" | ||
# sed -ri 's/\$\{\{(.*)\}\}/\$\{\{"\{\{"\}\}\1\{\{"\}\}"\}\}/g' "${renamed_file}" | ||
perl -pi -e 's|\$\{\{(.*?)\}\}|\$\{\{"\{\{"\}\}\1\{\{"\}\}"\}\}|g' "${renamed_file}" | ||
sed -ri "s/\bApp\b/{{ app_name}}/g" "${renamed_file}" | ||
done | ||
|
||
git add copier.yml .template-infra/ |
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,34 @@ | ||
#!/usr/bin/env bash | ||
# Run from the root of a template-infra repo | ||
|
||
set -eux | ||
|
||
VERSION=$1 | ||
|
||
# add any executables next to this script to the PATH for easy calling, like | ||
# templatize-legacy-infra | ||
SCRIPT_PATH=$(dirname "$(realpath -s "$0")") | ||
PATH=${SCRIPT_PATH}:${PATH} | ||
export PATH | ||
|
||
worktree_path=$(realpath "../template-infra-${VERSION}") | ||
|
||
git worktree add -d "${worktree_path}" "${VERSION}" | ||
|
||
pushd "${worktree_path}" | ||
|
||
templatize-legacy-infra | ||
|
||
msg="${VERSION} Platform CLI Migration Checkpoint" | ||
git commit --all -m "${msg}" | ||
git tag -a "platform-cli-migration/${VERSION}" -m "${msg}" | ||
|
||
# could push up the tag: | ||
# | ||
# git push origin "platform-cli-migration/${VERSION}" | ||
# | ||
# but will do that manually | ||
|
||
popd | ||
|
||
git worktree remove "${worktree_path}" |