-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/bundler/app-rails/bundler-f2ed05c871
- Loading branch information
Showing
10 changed files
with
209 additions
and
88 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
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
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
9 changes: 9 additions & 0 deletions
9
app-rails/db/migrate/20240613000011_enable_extension_for_uuid.rb
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,9 @@ | ||
class EnableExtensionForUuid < ActiveRecord::Migration[7.1] | ||
def up | ||
enable_extension 'pgcrypto' unless extension_enabled?('pgcrypto') | ||
end | ||
|
||
def down | ||
disable_extension 'pgcrypto' if extension_enabled?('pgcrypto') | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,85 @@ | ||
#!/usr/bin/env bash | ||
# ----------------------------------------------------------------------------- | ||
# This script renames the template application in a project. | ||
# Run this script in a project's root directory. | ||
# | ||
# The project name is the name of the folder in your project's root directory. Use | ||
# lowercase letters and hyphens. Do not use spaces. Underscores may have unexpected side | ||
# effects. Choose a unique string that will avoid collisions with commonly used words. | ||
# By default, the application name is `app-rails`. | ||
# | ||
# Positional parameters: | ||
# current_name (required) – the current name for the application | ||
# new_name (required) - the new name for the application | ||
# ----------------------------------------------------------------------------- | ||
set -euo pipefail | ||
|
||
# Helper to get the correct sed -i behavior for both GNU sed and BSD sed (installed by default on macOS) | ||
# Hat tip: https://stackoverflow.com/a/38595160 | ||
sedi () { | ||
sed --version >/dev/null 2>&1 && sed -i -- "$@" || sed -i "" "$@" | ||
} | ||
# Export the function so it can be used in the `find -exec` calls later on | ||
export -f sedi | ||
|
||
current_name=$1 | ||
new_name=$2 | ||
default_name="app-rails" | ||
|
||
# Debug: | ||
echo "---------------------------------------------------------------------" | ||
echo "current_name: ${current_name}" | ||
echo "new_name: ${new_name}" | ||
echo | ||
|
||
if [[ "${current_name}" == "${new_name}" ]]; then | ||
# Debug: | ||
echo "No rename required: ${current_name} == ${new_name}" | ||
exit 0 | ||
fi | ||
|
||
# Note: Keep this list in sync with the files copied in install-template and update-template | ||
declare -a include_paths | ||
include_paths=(.github/workflows/ci-app-rails.yml) | ||
include_paths+=(.grype.yml) | ||
include_paths+=(app-rails) | ||
include_paths+=(docker-compose.yml) | ||
include_paths+=(docker-compose.mock-production.yml) | ||
include_paths+=(docs/app-rails) | ||
|
||
# Loop through the paths to be included in this template. | ||
for include_path in "${include_paths[@]}"; do | ||
# If the application does not use the default name (i.e. it has already been renamed), | ||
# change the include path to use the correct current_name. | ||
if [[ "${current_name}" != "${default_name}" ]]; then | ||
include_path=$(echo "${include_path}" | sed "s/${default_name}/${current_name}/g") | ||
fi | ||
|
||
echo "Checking '${include_path}' to rename '${current_name}' to '${new_name}'..." | ||
|
||
# Skip if the path does not exist. | ||
if [[ ! -d "${include_path}" ]] && [[ ! -f "${include_path}" ]]; then | ||
echo "Skipping ahead. ${include_path} does not exist in this repo" | ||
continue | ||
fi | ||
|
||
# Construct the correct string substitution that respects word boundaries. | ||
# Hat tip: https://unix.stackexchange.com/a/393968 | ||
if sed --version >/dev/null 2>&1; then | ||
word_boundary_replacement="s/\<${current_name}\>/${new_name}/g" | ||
else | ||
word_boundary_replacement="s/[[:<:]]${current_name}[[:>:]]/${new_name}/g" | ||
fi | ||
|
||
# Replace occurrances of the current_name with the new_name in the path. | ||
# If the path is a file, replace in the file. | ||
# If the path is a directory, recursively replace in all files in the directory. | ||
LC_ALL=C find "${include_path}" -type f -exec bash -c "sedi \"${word_boundary_replacement}\" \"{}\"" \; | ||
|
||
# Rename included paths that contain the current_name. | ||
if [[ "${include_path}" =~ "${current_name}" ]]; then | ||
new_include_path=$(echo "${include_path}" | sed "s/${current_name}/${new_name}/g") | ||
echo "Renaming path from '${include_path}' to '${new_include_path}'..." | ||
mv "${include_path}" "${new_include_path}" | ||
fi | ||
done |
This file was deleted.
Oops, something went wrong.
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,75 @@ | ||
#!/usr/bin/env bash | ||
# ----------------------------------------------------------------------------- | ||
# This script updates an application template in your project. | ||
# This script from your project's root directory. | ||
# | ||
# Positional parameters: | ||
# target_version (optional) – the version of the template application to install. | ||
# Defaults to main. Can be any target that can be checked out, including a branch, | ||
# version tag, or commit hash. | ||
# app_name (optional) – the name of the application, in either snake- or kebab-case | ||
# Defaults to app-rails. | ||
# ----------------------------------------------------------------------------- | ||
set -euo pipefail | ||
|
||
# Helper to get the correct sed -i behavior for both GNU sed and BSD sed (installed by default on macOS) | ||
# Hat tip: https://stackoverflow.com/a/38595160 | ||
sedi () { | ||
sed --version >/dev/null 2>&1 && sed -i -- "$@" || sed -i "" "$@" | ||
} | ||
# Export the function so it can be used in the `find -exec` calls later on | ||
export -f sedi | ||
|
||
template_name="template-application-rails" | ||
# Use shell parameter expansion to get the last word, where the delimiter between | ||
# words is `-`. | ||
# See https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion | ||
template_short_name="app-${template_name##*-}" | ||
|
||
target_version=${1:-"main"} | ||
app_name=${2:-"${template_short_name}"} | ||
current_version=$(cat ".${template_name}-version") | ||
|
||
git clone "https://github.com/navapbc/${template_name}.git" | ||
|
||
echo "Checking out $target_version..." | ||
cd "${template_name}" | ||
git checkout "$target_version" | ||
cd - &> /dev/null | ||
|
||
# Note: Keep this list in sync with the files copied in install-template | ||
cd "${template_name}" | ||
include_paths=" \ | ||
.github/workflows/ci-${template_short_name}.yml | ||
.grype.yml \ | ||
${template_short_name} \ | ||
docker-compose.yml \ | ||
docker-compose.mock-production.yml \ | ||
docs/${template_short_name}" | ||
git diff $current_version $target_version -- $include_paths > update.patch | ||
cd - &> /dev/null | ||
|
||
if [ "$template_short_name" != "$app_name" ]; then | ||
echo "Modifying patch to use ${app_name} instead of ${template_short_name}..." | ||
# Construct the correct string substitution that respects word boundaries. | ||
# Hat tip: https://unix.stackexchange.com/a/393968 | ||
if sed --version >/dev/null 2>&1; then | ||
word_boundary_replacement="s/\<${template_short_name}\>/${app_name}/g" | ||
else | ||
word_boundary_replacement="s/[[:<:]]${template_short_name}[[:>:]]/${app_name}/g" | ||
fi | ||
sedi "${word_boundary_replacement}" "${template_name}/update.patch" | ||
fi | ||
|
||
echo "Applying patch..." | ||
git apply --allow-empty "${template_name}/update.patch" | ||
|
||
echo "Storing template version in a file..." | ||
cd "${template_name}" | ||
git rev-parse HEAD >../".${template_name}-version" | ||
cd - &> /dev/null | ||
|
||
echo "Cleaning up ${template_name} folder..." | ||
rm -fr "${template_name}" | ||
|
||
echo "...Done." |