From 35d861eea830c5fee92147558d8552608b099eaf Mon Sep 17 00:00:00 2001 From: Rocket Date: Wed, 12 Jun 2024 17:27:17 -0700 Subject: [PATCH 01/21] Add template-only-cd github actions workflow --- .github/workflows/template-only-cd.yml | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/template-only-cd.yml diff --git a/.github/workflows/template-only-cd.yml b/.github/workflows/template-only-cd.yml new file mode 100644 index 0000000..451dae1 --- /dev/null +++ b/.github/workflows/template-only-cd.yml @@ -0,0 +1,41 @@ +name: Template Deploy + +on: + push: + branches: + - main + workflow_dispatch: + +# Only allow one workflow at a time to prevent race conditions when pushing changes to the project repo +concurrency: template-only-cd + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + steps: + - name: Checkout template repo + uses: actions/checkout@v3 + with: + path: template-application-rails + + - name: Checkout project repo + uses: actions/checkout@v3 + with: + path: project-repo + repository: navapbc/platform-test-rails + token: ${{ secrets.PLATFORM_BOT_GITHUB_TOKEN }} + + - name: Update application template + working-directory: project-repo + run: ../template-application-rails/template-only-bin/update-template.sh + + - name: Push changes to project repo + working-directory: project-repo + run: | + git config user.name nava-platform-bot + git config user.email platform-admins@navapbc.com + git add --all + # Commit changes (if no changes then no-op) + git diff-index --quiet HEAD || git commit -m "Template application deploy #${{ github.run_id }}" + git push \ No newline at end of file From 30d702da4fffa4c2c8353c785709047b4e5895f5 Mon Sep 17 00:00:00 2001 From: Rocket Date: Thu, 13 Jun 2024 17:14:29 -0700 Subject: [PATCH 02/21] Update install, update, and rename scripts --- template-only-bin/install-template.sh | 18 +++-- template-only-bin/rename-template-app.sh | 84 +++++++++++++++++------- template-only-bin/update-template.sh | 60 +++++++++++++++++ 3 files changed, 128 insertions(+), 34 deletions(-) create mode 100644 template-only-bin/update-template.sh diff --git a/template-only-bin/install-template.sh b/template-only-bin/install-template.sh index 3ffe4d1..ae62060 100755 --- a/template-only-bin/install-template.sh +++ b/template-only-bin/install-template.sh @@ -30,20 +30,18 @@ if [ "$template_short_name" != "$app_name" ]; then "./template-only-bin/rename-template-app.sh" "${app_name}" "${template_short_name}" fi +# Note: Keep this list in sync with the files listed in update-template.sh +# Copy only relevant files that should be included in the project repo. echo "Copying files from $template_name..." -# Note: Keep this list of paths in sync with INCLUDE_PATHS in update-template.sh +# Copy top level paths. cp -r \ - .github \ - .gitignore \ .grype.yml \ "${app_name}" \ docker-compose.yml \ docker-compose.mock-production.yml \ - docs \ - $curr_dir -cd - >& /dev/null + ${curr_dir} +# Copy nested paths. +cp ".github/workflows/ci-${app_name}.yml" "${curr_dir}/.github/workflows" +cp -r "docs/${app_name}" "${curr_dir}/docs" -echo "Removing files relevant only to template development..." -# Note: Keep this list of paths in sync with EXCLUDE_OPT in update-template.sh -rm -rf .github/workflows/template-only-* -rm -rf .github/ISSUE_TEMPLATE +cd - >& /dev/null \ No newline at end of file diff --git a/template-only-bin/rename-template-app.sh b/template-only-bin/rename-template-app.sh index a012b93..2d685b7 100755 --- a/template-only-bin/rename-template-app.sh +++ b/template-only-bin/rename-template-app.sh @@ -1,11 +1,16 @@ #!/usr/bin/env bash # ----------------------------------------------------------------------------- -# This script renames the application template in your project. +# This script renames the template application in your project. # Run this script in your 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: -# new_name (required) - the new name for the application, in either snake- or kebab-case -# old_name (required) – the old name for the application, in either snake- or kebab-case +# current_name (required) – the current name for the application +# new_name (required) - the new name for the application # ----------------------------------------------------------------------------- set -euo pipefail @@ -17,30 +22,61 @@ sedi () { # Export the function so it can be used in the `find -exec` calls later on export -f sedi -new_name=$1 -old_name=$2 - -# Don't make assumptions about whether the arguments are snake- or kebab-case. Handle both. -# Get kebab-case names -old_name_kebab=$(echo $old_name | tr "_" "-") -new_name_kebab=$(echo $new_name | tr "_" "-") +current_name=$1 +new_name=$2 +default_name="app-rails" -# Get snake-case names -old_name_snake=$(echo $old_name | tr "-" "_") -new_name_snake=$(echo $new_name | tr "-" "_") +echo "---------------------------------------------------------------------" +echo "current_name: ${current_name}" +echo "new_name: ${new_name}" +echo -# Rename the app directory -if [ -d "$old_name" ]; then - echo "Renaming ${old_name} to ${new_name}..." - mv "${old_name}" "${new_name}" +if [[ "${current_name}" == "${new_name}" ]]; then + echo "No rename required: ${current_name} == ${new_name}" + exit 0 fi -# Rename all kebab-case instances -echo "Performing a find-and-replace for all instances of (kebab-case) '$old_name_kebab' with '$new_name_kebab'..." -LC_ALL=C find . -type f -not -path "./.git/*" -exec bash -c "sedi \"s/$old_name_kebab/$new_name_kebab/g\" \"{}\"" \; +# Note: Keep this list in sync with the files copied in install-template.sh and update-template.sh +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 + echo "Checking: ${include_path}..." + + # 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 + + # 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 -# Rename all snake-case instances -echo "Performing a find-and-replace for all instances of (snake-case) '$old_name_snake' with '$new_name_snake'..." -LC_ALL=C find . -type f -not -path "./.git/*" -exec bash -c "sedi \"s/$old_name_snake/$new_name_snake/g\" \"{}\"" \; + # 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}\" \"{}\"" \; -echo "...Done." + # Rename included paths that contain the current_name. + if [[ "${include_path}" =~ "${current_name}" ]]; then + new_include_path=$(echo "${include_path}" | sed "s/${default_name}/${new_name}/g") + mv "${include_path}" "${new_include_path}" + fi +done diff --git a/template-only-bin/update-template.sh b/template-only-bin/update-template.sh new file mode 100644 index 0000000..f654c9c --- /dev/null +++ b/template-only-bin/update-template.sh @@ -0,0 +1,60 @@ +#!/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 + +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 + +if [ "$template_short_name" != "$app_name" ]; then + echo "Modifying template to use ${app_name} instead of ${template_short_name}..." + "./template-only-bin/rename-template-app.sh" "${app_name}" "${template_short_name}" +fi + +# Note: Keep this list in sync with the files copied in install-template.sh +cd "${template_name}" +include_paths=" \ + .github/workflows/ci-${app_name}.yml + .grype.yml \ + ${app_name} \ + docker-compose.yml \ + docker-compose.mock-production.yml \ + docs/${app_name}" +git diff $current_version $target_version -- $include_paths > update.patch +cd - &> /dev/null + +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." \ No newline at end of file From ec2fbb21c9a938759b1fc46434f5f40835a75a43 Mon Sep 17 00:00:00 2001 From: Rocket Date: Thu, 13 Jun 2024 17:19:57 -0700 Subject: [PATCH 03/21] Use correct directory --- template-only-bin/update-template.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/template-only-bin/update-template.sh b/template-only-bin/update-template.sh index f654c9c..df7627e 100644 --- a/template-only-bin/update-template.sh +++ b/template-only-bin/update-template.sh @@ -30,8 +30,10 @@ git checkout "$target_version" cd - &> /dev/null if [ "$template_short_name" != "$app_name" ]; then + cd "${template_name}" echo "Modifying template to use ${app_name} instead of ${template_short_name}..." "./template-only-bin/rename-template-app.sh" "${app_name}" "${template_short_name}" + cd - &> /dev/null fi # Note: Keep this list in sync with the files copied in install-template.sh From 4b5140fe3f77494f96d0631934b34ad27c387efb Mon Sep 17 00:00:00 2001 From: Rocket Date: Thu, 13 Jun 2024 17:26:44 -0700 Subject: [PATCH 04/21] Change argument order --- template-only-bin/install-template.sh | 2 +- template-only-bin/update-template.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/template-only-bin/install-template.sh b/template-only-bin/install-template.sh index ae62060..13cccae 100755 --- a/template-only-bin/install-template.sh +++ b/template-only-bin/install-template.sh @@ -27,7 +27,7 @@ cd $template_dir if [ "$template_short_name" != "$app_name" ]; then echo "Modifying template to use ${app_name} instead of ${template_short_name}..." - "./template-only-bin/rename-template-app.sh" "${app_name}" "${template_short_name}" + "./template-only-bin/rename-template-app.sh" "${template_short_name}" "${app_name}" fi # Note: Keep this list in sync with the files listed in update-template.sh diff --git a/template-only-bin/update-template.sh b/template-only-bin/update-template.sh index df7627e..d9ee166 100644 --- a/template-only-bin/update-template.sh +++ b/template-only-bin/update-template.sh @@ -32,7 +32,7 @@ cd - &> /dev/null if [ "$template_short_name" != "$app_name" ]; then cd "${template_name}" echo "Modifying template to use ${app_name} instead of ${template_short_name}..." - "./template-only-bin/rename-template-app.sh" "${app_name}" "${template_short_name}" + "./template-only-bin/rename-template-app.sh" "${template_short_name}" "${app_name}" cd - &> /dev/null fi From c0a3918bb8d8d484451a63fd3ff261c78db8f1d7 Mon Sep 17 00:00:00 2001 From: Rocket Date: Thu, 13 Jun 2024 17:26:58 -0700 Subject: [PATCH 05/21] Print correct path --- template-only-bin/rename-template-app.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/template-only-bin/rename-template-app.sh b/template-only-bin/rename-template-app.sh index 2d685b7..9b5c948 100755 --- a/template-only-bin/rename-template-app.sh +++ b/template-only-bin/rename-template-app.sh @@ -47,14 +47,14 @@ include_paths+=(docs/app-rails) # Loop through the paths to be included in this template. for include_path in "${include_paths[@]}"; do - echo "Checking: ${include_path}..." - # 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}..." + # 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" From ad0263f1d26af5a5cef0d7dffd27826cc2deeac5 Mon Sep 17 00:00:00 2001 From: Rocket Date: Thu, 13 Jun 2024 17:34:06 -0700 Subject: [PATCH 06/21] Use correct path names --- template-only-bin/rename-template-app.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/template-only-bin/rename-template-app.sh b/template-only-bin/rename-template-app.sh index 9b5c948..ea9034b 100755 --- a/template-only-bin/rename-template-app.sh +++ b/template-only-bin/rename-template-app.sh @@ -48,9 +48,9 @@ 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") + # change the include path to use the correct old_name. + if [[ "${old_name}" != "${default_name}" ]]; then + include_path=$(echo "${include_path}" | sed "s/${default_name}/${old_name}/g") fi echo "Checking: ${include_path}..." From 0c62addb7c64b4f942847c28b3429147fbf6673d Mon Sep 17 00:00:00 2001 From: Rocket Date: Thu, 13 Jun 2024 17:35:48 -0700 Subject: [PATCH 07/21] Revert "Use correct path names" This reverts commit ad0263f1d26af5a5cef0d7dffd27826cc2deeac5. --- template-only-bin/rename-template-app.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/template-only-bin/rename-template-app.sh b/template-only-bin/rename-template-app.sh index ea9034b..9b5c948 100755 --- a/template-only-bin/rename-template-app.sh +++ b/template-only-bin/rename-template-app.sh @@ -48,9 +48,9 @@ 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 old_name. - if [[ "${old_name}" != "${default_name}" ]]; then - include_path=$(echo "${include_path}" | sed "s/${default_name}/${old_name}/g") + # 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}..." From a23e287d22d54aaaba472b82890b0331e2f8c26e Mon Sep 17 00:00:00 2001 From: Rocket Date: Thu, 13 Jun 2024 17:45:08 -0700 Subject: [PATCH 08/21] Fix typo --- template-only-bin/rename-template-app.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template-only-bin/rename-template-app.sh b/template-only-bin/rename-template-app.sh index 9b5c948..27eb052 100755 --- a/template-only-bin/rename-template-app.sh +++ b/template-only-bin/rename-template-app.sh @@ -76,7 +76,7 @@ for include_path in "${include_paths[@]}"; do # Rename included paths that contain the current_name. if [[ "${include_path}" =~ "${current_name}" ]]; then - new_include_path=$(echo "${include_path}" | sed "s/${default_name}/${new_name}/g") + new_include_path=$(echo "${include_path}" | sed "s/${current_name}/${new_name}/g") mv "${include_path}" "${new_include_path}" fi done From 4ad779d9ec137a1b247b9b62390ee351b90f0950 Mon Sep 17 00:00:00 2001 From: Rocket Date: Fri, 14 Jun 2024 11:23:00 -0700 Subject: [PATCH 09/21] Fix install paths --- template-only-bin/download-and-install-template.sh | 4 ---- template-only-bin/install-template.sh | 11 +++++------ template-only-bin/rename-template-app.sh | 9 ++++++--- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/template-only-bin/download-and-install-template.sh b/template-only-bin/download-and-install-template.sh index 0e368cd..252077c 100755 --- a/template-only-bin/download-and-install-template.sh +++ b/template-only-bin/download-and-install-template.sh @@ -21,10 +21,6 @@ template_short_name="app-${template_name##*-}" target_version=${1:-"main"} app_name=${2:-"${template_short_name}"} -echo "template_short_name: ${template_short_name}" -echo "app_name: ${app_name}" -echo "target_version: ${target_version}" - git clone "https://github.com/navapbc/${template_name}.git" cd "${template_name}" diff --git a/template-only-bin/install-template.sh b/template-only-bin/install-template.sh index 13cccae..451361c 100755 --- a/template-only-bin/install-template.sh +++ b/template-only-bin/install-template.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash # ----------------------------------------------------------------------------- # This script installs an application template to your project. -# Run this script using ./download-and-install-template.sh +# Run this script using ./download-and-install-template.sh. Expected to be run +# from the project's root directory. # # Positional parameters: # template_name (required) – the name of the template to install @@ -20,19 +21,17 @@ echo "template_short_name: ${template_short_name}" echo "app_name: ${app_name}" curr_dir=$(pwd) -script_dir=$(dirname $0) -template_dir="${script_dir}/.." -cd $template_dir +cd "${template_name}" -if [ "$template_short_name" != "$app_name" ]; then +if [ "${template_short_name}" != "${app_name}" ]; then echo "Modifying template to use ${app_name} instead of ${template_short_name}..." "./template-only-bin/rename-template-app.sh" "${template_short_name}" "${app_name}" fi # Note: Keep this list in sync with the files listed in update-template.sh # Copy only relevant files that should be included in the project repo. -echo "Copying files from $template_name..." +echo "Copying files from ${template_name}..." # Copy top level paths. cp -r \ .grype.yml \ diff --git a/template-only-bin/rename-template-app.sh b/template-only-bin/rename-template-app.sh index 27eb052..cb4edde 100755 --- a/template-only-bin/rename-template-app.sh +++ b/template-only-bin/rename-template-app.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # ----------------------------------------------------------------------------- -# This script renames the template application in your project. -# Run this script in your project's root directory. +# 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 @@ -26,12 +26,14 @@ 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 @@ -53,7 +55,7 @@ for include_path in "${include_paths[@]}"; do include_path=$(echo "${include_path}" | sed "s/${default_name}/${current_name}/g") fi - echo "Checking: ${include_path}..." + 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 @@ -77,6 +79,7 @@ for include_path in "${include_paths[@]}"; do # 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 From 370734cc2d44e3720396f8e46c35af75c6a0e1d0 Mon Sep 17 00:00:00 2001 From: Rocket Date: Fri, 14 Jun 2024 11:28:44 -0700 Subject: [PATCH 10/21] Make missing directories --- template-only-bin/install-template.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/template-only-bin/install-template.sh b/template-only-bin/install-template.sh index 451361c..ca8cc9a 100755 --- a/template-only-bin/install-template.sh +++ b/template-only-bin/install-template.sh @@ -39,8 +39,8 @@ cp -r \ docker-compose.yml \ docker-compose.mock-production.yml \ ${curr_dir} -# Copy nested paths. -cp ".github/workflows/ci-${app_name}.yml" "${curr_dir}/.github/workflows" -cp -r "docs/${app_name}" "${curr_dir}/docs" +# Copy nested paths. Make any missing directories. +mkdir -p "${curr_dir}/.github/workflows" && cp ".github/workflows/ci-${app_name}.yml" "${curr_dir}/.github/workflows" +mkdir -p "${curr_dir}/docs" && cp -r "docs/${app_name}" "${curr_dir}/docs" cd - >& /dev/null \ No newline at end of file From a630c27f895f1b8c6348c99642ad9f001929f550 Mon Sep 17 00:00:00 2001 From: Rocket Date: Fri, 14 Jun 2024 11:45:57 -0700 Subject: [PATCH 11/21] Update update instructions --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0c244f0..2bd1f37 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ To get started using the template application on your project: 1. Clone the template repository 2. Copy the template files into your project directory - 3. Remove any files specific to the template repository, like this README. + 3. Ignore any files specific to the template repository, like this README. You can optionally pass in a branch, commit hash, or release that you want to install. For example: @@ -58,7 +58,7 @@ To get started using the template application on your project: If you have previously installed this template and would like to update your project to use a newer version of this application: -1. Run the [download and install script](./template-only-bin/download-and-install-template.sh) in your project's root directory and pass in the branch, commit hash, or release that you want to update to, followed by the name of your application directory (e.g. `app-rails`). +1. Run the [update script](./template-only-bin/update-template.sh) in your project's root directory and pass in the branch, commit hash, or release that you want to update to, followed by the name of your application directory (e.g. `app-rails`). ```bash curl https://raw.githubusercontent.com/navapbc/template-application-rails/main/template-only-bin/download-and-install-template.sh | bash -s -- @@ -68,6 +68,6 @@ If you have previously installed this template and would like to update your pro 1. Clone the template repository 2. Copy the template files into your project directory - 3. Remove any files specific to the template repository, like this README. + 3. Ignore any files specific to the template repository, like this README. ⚠️ Warning! This will modify existing files. Review all changes carefully after executing the script by running `git diff`. From a290bb309de6d9ac5b52311edbec23d315f129d7 Mon Sep 17 00:00:00 2001 From: Rocket Date: Fri, 14 Jun 2024 12:23:55 -0700 Subject: [PATCH 12/21] Add control for which version of install scripts to use --- template-only-bin/download-and-install-template.sh | 6 +++++- template-only-bin/install-template.sh | 9 +++++---- template-only-bin/update-template.sh | 6 +++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/template-only-bin/download-and-install-template.sh b/template-only-bin/download-and-install-template.sh index 252077c..3513742 100755 --- a/template-only-bin/download-and-install-template.sh +++ b/template-only-bin/download-and-install-template.sh @@ -9,6 +9,9 @@ # version tag, or commit hash. # app_name (optional) – the new name for the application, in either snake- or kebab-case # Defaults to app-rails. +# target_script_branch (optional) - the branch of the template repo to use when +# retrieving template-only-bin scripts. Used primarily for template development. +# Defaults to `main`. # ----------------------------------------------------------------------------- set -euo pipefail @@ -20,6 +23,7 @@ template_short_name="app-${template_name##*-}" target_version=${1:-"main"} app_name=${2:-"${template_short_name}"} +target_script_branch=${3:-"main"} git clone "https://github.com/navapbc/${template_name}.git" cd "${template_name}" @@ -29,7 +33,7 @@ git checkout "$target_version" cd - &> /dev/null echo "Installing ${template_name}..." -"./${template_name}/template-only-bin/install-template.sh" "${template_name}" "${app_name}" +curl "https://raw.githubusercontent.com/navapbc/${template_name}/${target_script_branch}/template-only-bin/install-template.sh" | bash -s -- "${template_name}" "${app_name}" "${target_script_branch}" echo "Storing template version in a file..." cd "${template_name}" diff --git a/template-only-bin/install-template.sh b/template-only-bin/install-template.sh index ca8cc9a..f2b0544 100755 --- a/template-only-bin/install-template.sh +++ b/template-only-bin/install-template.sh @@ -7,6 +7,9 @@ # Positional parameters: # template_name (required) – the name of the template to install # app_name (required) – the name of the application +# target_script_branch (optional) - the branch of the template repo to use when +# retrieving template-only-bin scripts. Used primarily for template development. +# Defaults to `main`. # ----------------------------------------------------------------------------- set -euo pipefail @@ -16,9 +19,7 @@ template_name=$1 # See https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion template_short_name="app-${template_name##*-}" app_name=$2 - -echo "template_short_name: ${template_short_name}" -echo "app_name: ${app_name}" +target_script_branch=${3:-"main"} curr_dir=$(pwd) @@ -26,7 +27,7 @@ cd "${template_name}" if [ "${template_short_name}" != "${app_name}" ]; then echo "Modifying template to use ${app_name} instead of ${template_short_name}..." - "./template-only-bin/rename-template-app.sh" "${template_short_name}" "${app_name}" + curl "https://raw.githubusercontent.com/navapbc/${template_name}/${target_script_branch}/template-only-bin/rename-template-app.sh" | bash -s -- "${template_short_name}" "${app_name}" fi # Note: Keep this list in sync with the files listed in update-template.sh diff --git a/template-only-bin/update-template.sh b/template-only-bin/update-template.sh index d9ee166..d5c7023 100644 --- a/template-only-bin/update-template.sh +++ b/template-only-bin/update-template.sh @@ -9,6 +9,9 @@ # version tag, or commit hash. # app_name (optional) – the name of the application, in either snake- or kebab-case # Defaults to app-rails. +# target_script_branch (optional) - the branch of the template repo to use when +# retrieving template-only-bin scripts. Used primarily for template development. +# Defaults to `main`. # ----------------------------------------------------------------------------- set -euo pipefail @@ -20,6 +23,7 @@ template_short_name="app-${template_name##*-}" target_version=${1:-"main"} app_name=${2:-"${template_short_name}"} +target_script_branch=${3:-"main"} current_version=$(cat ".${template_name}-version") git clone "https://github.com/navapbc/${template_name}.git" @@ -32,7 +36,7 @@ cd - &> /dev/null if [ "$template_short_name" != "$app_name" ]; then cd "${template_name}" echo "Modifying template to use ${app_name} instead of ${template_short_name}..." - "./template-only-bin/rename-template-app.sh" "${template_short_name}" "${app_name}" + curl "https://raw.githubusercontent.com/navapbc/${template_name}/${target_script_branch}/template-only-bin/rename-template-app.sh" | bash -s -- "${template_short_name}" "${app_name}" cd - &> /dev/null fi From 301e0f98c805b5d1fc0e2e3721aa89eaaf779ce6 Mon Sep 17 00:00:00 2001 From: Rocket Date: Fri, 14 Jun 2024 12:26:34 -0700 Subject: [PATCH 13/21] Remove .sh script extensions --- .github/workflows/template-only-cd.yml | 2 +- README.md | 10 +++++----- template-only-bin/download-and-install-template.sh | 2 +- template-only-bin/install-template.sh | 6 +++--- template-only-bin/rename-template-app.sh | 2 +- template-only-bin/update-template.sh | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/template-only-cd.yml b/.github/workflows/template-only-cd.yml index 451dae1..f9e1f13 100644 --- a/.github/workflows/template-only-cd.yml +++ b/.github/workflows/template-only-cd.yml @@ -28,7 +28,7 @@ jobs: - name: Update application template working-directory: project-repo - run: ../template-application-rails/template-only-bin/update-template.sh + run: ../template-application-rails/template-only-bin/update-template - name: Push changes to project repo working-directory: project-repo diff --git a/README.md b/README.md index 2bd1f37..22dc352 100644 --- a/README.md +++ b/README.md @@ -34,10 +34,10 @@ See [`navapbc/platform`](https://github.com/navapbc/platform) for other template To get started using the template application on your project: -1. Run the [download and install script](./template-only-bin/download-and-install-template.sh) in your project's root directory. +1. Run the [download and install script](./template-only-bin/download-and-install-template) in your project's root directory. ```bash - curl https://raw.githubusercontent.com/navapbc/template-application-rails/main/template-only-bin/download-and-install-template.sh | bash -s + curl https://raw.githubusercontent.com/navapbc/template-application-rails/main/template-only-bin/download-and-install-template | bash -s ``` This script will: @@ -49,7 +49,7 @@ To get started using the template application on your project: You can optionally pass in a branch, commit hash, or release that you want to install. For example: ```bash - curl https://raw.githubusercontent.com/navapbc/template-application-rails/main/template-only-bin/download-and-install-template.sh | bash -s -- + curl https://raw.githubusercontent.com/navapbc/template-application-rails/main/template-only-bin/download-and-install-template | bash -s -- ``` 2. [Follow the steps in `app-rails/README.md`](./app-rails/README.md) to set up the application locally. 3. Optional, if using the Platform infrastructure template: [Follow the steps in the `template-infra` README](https://github.com/navapbc/template-infra#installation) to set up the various pieces of your infrastructure. @@ -58,10 +58,10 @@ To get started using the template application on your project: If you have previously installed this template and would like to update your project to use a newer version of this application: -1. Run the [update script](./template-only-bin/update-template.sh) in your project's root directory and pass in the branch, commit hash, or release that you want to update to, followed by the name of your application directory (e.g. `app-rails`). +1. Run the [update script](./template-only-bin/update-template) in your project's root directory and pass in the branch, commit hash, or release that you want to update to, followed by the name of your application directory (e.g. `app-rails`). ```bash - curl https://raw.githubusercontent.com/navapbc/template-application-rails/main/template-only-bin/download-and-install-template.sh | bash -s -- + curl https://raw.githubusercontent.com/navapbc/template-application-rails/main/template-only-bin/download-and-install-template | bash -s -- ``` This script will: diff --git a/template-only-bin/download-and-install-template.sh b/template-only-bin/download-and-install-template.sh index 3513742..a2eda3c 100755 --- a/template-only-bin/download-and-install-template.sh +++ b/template-only-bin/download-and-install-template.sh @@ -33,7 +33,7 @@ git checkout "$target_version" cd - &> /dev/null echo "Installing ${template_name}..." -curl "https://raw.githubusercontent.com/navapbc/${template_name}/${target_script_branch}/template-only-bin/install-template.sh" | bash -s -- "${template_name}" "${app_name}" "${target_script_branch}" +curl "https://raw.githubusercontent.com/navapbc/${template_name}/${target_script_branch}/template-only-bin/install-template" | bash -s -- "${template_name}" "${app_name}" "${target_script_branch}" echo "Storing template version in a file..." cd "${template_name}" diff --git a/template-only-bin/install-template.sh b/template-only-bin/install-template.sh index f2b0544..5839b42 100755 --- a/template-only-bin/install-template.sh +++ b/template-only-bin/install-template.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # ----------------------------------------------------------------------------- # This script installs an application template to your project. -# Run this script using ./download-and-install-template.sh. Expected to be run +# Run this script using ./download-and-install-template. Expected to be run # from the project's root directory. # # Positional parameters: @@ -27,10 +27,10 @@ cd "${template_name}" if [ "${template_short_name}" != "${app_name}" ]; then echo "Modifying template to use ${app_name} instead of ${template_short_name}..." - curl "https://raw.githubusercontent.com/navapbc/${template_name}/${target_script_branch}/template-only-bin/rename-template-app.sh" | bash -s -- "${template_short_name}" "${app_name}" + curl "https://raw.githubusercontent.com/navapbc/${template_name}/${target_script_branch}/template-only-bin/rename-template-app" | bash -s -- "${template_short_name}" "${app_name}" fi -# Note: Keep this list in sync with the files listed in update-template.sh +# Note: Keep this list in sync with the files listed in update-template # Copy only relevant files that should be included in the project repo. echo "Copying files from ${template_name}..." # Copy top level paths. diff --git a/template-only-bin/rename-template-app.sh b/template-only-bin/rename-template-app.sh index cb4edde..7bb2bba 100755 --- a/template-only-bin/rename-template-app.sh +++ b/template-only-bin/rename-template-app.sh @@ -38,7 +38,7 @@ if [[ "${current_name}" == "${new_name}" ]]; then exit 0 fi -# Note: Keep this list in sync with the files copied in install-template.sh and update-template.sh +# 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) diff --git a/template-only-bin/update-template.sh b/template-only-bin/update-template.sh index d5c7023..fc47b4b 100644 --- a/template-only-bin/update-template.sh +++ b/template-only-bin/update-template.sh @@ -36,11 +36,11 @@ cd - &> /dev/null if [ "$template_short_name" != "$app_name" ]; then cd "${template_name}" echo "Modifying template to use ${app_name} instead of ${template_short_name}..." - curl "https://raw.githubusercontent.com/navapbc/${template_name}/${target_script_branch}/template-only-bin/rename-template-app.sh" | bash -s -- "${template_short_name}" "${app_name}" + curl "https://raw.githubusercontent.com/navapbc/${template_name}/${target_script_branch}/template-only-bin/rename-template-app" | bash -s -- "${template_short_name}" "${app_name}" cd - &> /dev/null fi -# Note: Keep this list in sync with the files copied in install-template.sh +# Note: Keep this list in sync with the files copied in install-template cd "${template_name}" include_paths=" \ .github/workflows/ci-${app_name}.yml From b5c052d0e4f4af87d995de6a3867341389b511d2 Mon Sep 17 00:00:00 2001 From: Rocket Date: Fri, 14 Jun 2024 12:26:59 -0700 Subject: [PATCH 14/21] Add execution bit to all scripts --- template-only-bin/update-template.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 template-only-bin/update-template.sh diff --git a/template-only-bin/update-template.sh b/template-only-bin/update-template.sh old mode 100644 new mode 100755 From 10ca65ad3ca7a32704606a4c35e0c8a539ff6287 Mon Sep 17 00:00:00 2001 From: Rocket Date: Fri, 14 Jun 2024 12:43:54 -0700 Subject: [PATCH 15/21] Actually rename scripts --- ...nd-install-template.sh => download-and-install-template} | 6 +----- template-only-bin/{install-template.sh => install-template} | 6 +----- .../{rename-template-app.sh => rename-template-app} | 0 template-only-bin/{update-template.sh => update-template} | 6 +----- 4 files changed, 3 insertions(+), 15 deletions(-) rename template-only-bin/{download-and-install-template.sh => download-and-install-template} (80%) rename template-only-bin/{install-template.sh => install-template} (82%) rename template-only-bin/{rename-template-app.sh => rename-template-app} (100%) rename template-only-bin/{update-template.sh => update-template} (86%) diff --git a/template-only-bin/download-and-install-template.sh b/template-only-bin/download-and-install-template similarity index 80% rename from template-only-bin/download-and-install-template.sh rename to template-only-bin/download-and-install-template index a2eda3c..b68e223 100755 --- a/template-only-bin/download-and-install-template.sh +++ b/template-only-bin/download-and-install-template @@ -9,9 +9,6 @@ # version tag, or commit hash. # app_name (optional) – the new name for the application, in either snake- or kebab-case # Defaults to app-rails. -# target_script_branch (optional) - the branch of the template repo to use when -# retrieving template-only-bin scripts. Used primarily for template development. -# Defaults to `main`. # ----------------------------------------------------------------------------- set -euo pipefail @@ -23,7 +20,6 @@ template_short_name="app-${template_name##*-}" target_version=${1:-"main"} app_name=${2:-"${template_short_name}"} -target_script_branch=${3:-"main"} git clone "https://github.com/navapbc/${template_name}.git" cd "${template_name}" @@ -33,7 +29,7 @@ git checkout "$target_version" cd - &> /dev/null echo "Installing ${template_name}..." -curl "https://raw.githubusercontent.com/navapbc/${template_name}/${target_script_branch}/template-only-bin/install-template" | bash -s -- "${template_name}" "${app_name}" "${target_script_branch}" +curl "https://raw.githubusercontent.com/navapbc/${template_name}/rocket/update-template-only-bin-scripts/template-only-bin/install-template" | bash -s -- "${template_name}" "${app_name}" "${target_script_branch}" echo "Storing template version in a file..." cd "${template_name}" diff --git a/template-only-bin/install-template.sh b/template-only-bin/install-template similarity index 82% rename from template-only-bin/install-template.sh rename to template-only-bin/install-template index 5839b42..ecf201e 100755 --- a/template-only-bin/install-template.sh +++ b/template-only-bin/install-template @@ -7,9 +7,6 @@ # Positional parameters: # template_name (required) – the name of the template to install # app_name (required) – the name of the application -# target_script_branch (optional) - the branch of the template repo to use when -# retrieving template-only-bin scripts. Used primarily for template development. -# Defaults to `main`. # ----------------------------------------------------------------------------- set -euo pipefail @@ -19,7 +16,6 @@ template_name=$1 # See https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Shell-Parameter-Expansion template_short_name="app-${template_name##*-}" app_name=$2 -target_script_branch=${3:-"main"} curr_dir=$(pwd) @@ -27,7 +23,7 @@ cd "${template_name}" if [ "${template_short_name}" != "${app_name}" ]; then echo "Modifying template to use ${app_name} instead of ${template_short_name}..." - curl "https://raw.githubusercontent.com/navapbc/${template_name}/${target_script_branch}/template-only-bin/rename-template-app" | bash -s -- "${template_short_name}" "${app_name}" + curl "https://raw.githubusercontent.com/navapbc/${template_name}/rocket/update-template-only-bin-scripts/template-only-bin/rename-template-app" | bash -s -- "${template_short_name}" "${app_name}" fi # Note: Keep this list in sync with the files listed in update-template diff --git a/template-only-bin/rename-template-app.sh b/template-only-bin/rename-template-app similarity index 100% rename from template-only-bin/rename-template-app.sh rename to template-only-bin/rename-template-app diff --git a/template-only-bin/update-template.sh b/template-only-bin/update-template similarity index 86% rename from template-only-bin/update-template.sh rename to template-only-bin/update-template index fc47b4b..100884a 100755 --- a/template-only-bin/update-template.sh +++ b/template-only-bin/update-template @@ -9,9 +9,6 @@ # version tag, or commit hash. # app_name (optional) – the name of the application, in either snake- or kebab-case # Defaults to app-rails. -# target_script_branch (optional) - the branch of the template repo to use when -# retrieving template-only-bin scripts. Used primarily for template development. -# Defaults to `main`. # ----------------------------------------------------------------------------- set -euo pipefail @@ -23,7 +20,6 @@ template_short_name="app-${template_name##*-}" target_version=${1:-"main"} app_name=${2:-"${template_short_name}"} -target_script_branch=${3:-"main"} current_version=$(cat ".${template_name}-version") git clone "https://github.com/navapbc/${template_name}.git" @@ -36,7 +32,7 @@ cd - &> /dev/null if [ "$template_short_name" != "$app_name" ]; then cd "${template_name}" echo "Modifying template to use ${app_name} instead of ${template_short_name}..." - curl "https://raw.githubusercontent.com/navapbc/${template_name}/${target_script_branch}/template-only-bin/rename-template-app" | bash -s -- "${template_short_name}" "${app_name}" + curl "https://raw.githubusercontent.com/navapbc/${template_name}/rocket/update-template-only-bin-scripts/template-only-bin/rename-template-app" | bash -s -- "${template_short_name}" "${app_name}" cd - &> /dev/null fi From acda9751c2c5b7d30e7a6100e07cf211228f14f5 Mon Sep 17 00:00:00 2001 From: Rocket Date: Fri, 14 Jun 2024 12:49:27 -0700 Subject: [PATCH 16/21] Remove extra arg --- template-only-bin/download-and-install-template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template-only-bin/download-and-install-template b/template-only-bin/download-and-install-template index b68e223..19be463 100755 --- a/template-only-bin/download-and-install-template +++ b/template-only-bin/download-and-install-template @@ -29,7 +29,7 @@ git checkout "$target_version" cd - &> /dev/null echo "Installing ${template_name}..." -curl "https://raw.githubusercontent.com/navapbc/${template_name}/rocket/update-template-only-bin-scripts/template-only-bin/install-template" | bash -s -- "${template_name}" "${app_name}" "${target_script_branch}" +curl "https://raw.githubusercontent.com/navapbc/${template_name}/rocket/update-template-only-bin-scripts/template-only-bin/install-template" | bash -s -- "${template_name}" "${app_name}" echo "Storing template version in a file..." cd "${template_name}" From e3c25d7092f41ebfe4a39ac8b21495ec23295a89 Mon Sep 17 00:00:00 2001 From: Rocket Date: Fri, 14 Jun 2024 13:07:00 -0700 Subject: [PATCH 17/21] Debug rename order --- template-only-bin/update-template | 34 ++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/template-only-bin/update-template b/template-only-bin/update-template index 100884a..01174ad 100755 --- a/template-only-bin/update-template +++ b/template-only-bin/update-template @@ -12,6 +12,14 @@ # ----------------------------------------------------------------------------- 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 `-`. @@ -29,26 +37,32 @@ cd "${template_name}" git checkout "$target_version" cd - &> /dev/null -if [ "$template_short_name" != "$app_name" ]; then - cd "${template_name}" - echo "Modifying template to use ${app_name} instead of ${template_short_name}..." - curl "https://raw.githubusercontent.com/navapbc/${template_name}/rocket/update-template-only-bin-scripts/template-only-bin/rename-template-app" | bash -s -- "${template_short_name}" "${app_name}" - cd - &> /dev/null -fi - # Note: Keep this list in sync with the files copied in install-template cd "${template_name}" include_paths=" \ - .github/workflows/ci-${app_name}.yml + .github/workflows/ci-${template_short_name}.yml .grype.yml \ - ${app_name} \ + ${template_short_name} \ docker-compose.yml \ docker-compose.mock-production.yml \ - docs/${app_name}" + 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 + cat "${template_name}/update.patch" | sedi \"${word_boundary_replacement}\" +fi + echo "Applying patch..." +cd "${template_name}/update.patch" "~/Desktop" git apply --allow-empty "${template_name}/update.patch" echo "Storing template version in a file..." From 86d8d87684d45d9bbc8f41076a30d899f46c82b7 Mon Sep 17 00:00:00 2001 From: Rocket Date: Fri, 14 Jun 2024 13:08:01 -0700 Subject: [PATCH 18/21] Remove quote escaping --- template-only-bin/update-template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template-only-bin/update-template b/template-only-bin/update-template index 01174ad..7dad4ee 100755 --- a/template-only-bin/update-template +++ b/template-only-bin/update-template @@ -58,7 +58,7 @@ if [ "$template_short_name" != "$app_name" ]; then else word_boundary_replacement="s/[[:<:]]${template_short_name}[[:>:]]/${app_name}/g" fi - cat "${template_name}/update.patch" | sedi \"${word_boundary_replacement}\" + cat "${template_name}/update.patch" | sedi "${word_boundary_replacement}" fi echo "Applying patch..." From 4176b63e64dbf5687857945e590f631151141e91 Mon Sep 17 00:00:00 2001 From: Rocket Date: Fri, 14 Jun 2024 13:11:59 -0700 Subject: [PATCH 19/21] Fix sed usage --- template-only-bin/update-template | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/template-only-bin/update-template b/template-only-bin/update-template index 7dad4ee..d3a0efc 100755 --- a/template-only-bin/update-template +++ b/template-only-bin/update-template @@ -58,11 +58,10 @@ if [ "$template_short_name" != "$app_name" ]; then else word_boundary_replacement="s/[[:<:]]${template_short_name}[[:>:]]/${app_name}/g" fi - cat "${template_name}/update.patch" | sedi "${word_boundary_replacement}" + sedi "${word_boundary_replacement}" "${template_name}/update.patch" fi echo "Applying patch..." -cd "${template_name}/update.patch" "~/Desktop" git apply --allow-empty "${template_name}/update.patch" echo "Storing template version in a file..." From 4df01b8c25c9c063c3b5fa4a311d11949f5723af Mon Sep 17 00:00:00 2001 From: Rocket Date: Fri, 14 Jun 2024 13:14:43 -0700 Subject: [PATCH 20/21] Remove template-only-cd.yml from this branch --- .github/workflows/template-only-cd.yml | 41 -------------------------- 1 file changed, 41 deletions(-) delete mode 100644 .github/workflows/template-only-cd.yml diff --git a/.github/workflows/template-only-cd.yml b/.github/workflows/template-only-cd.yml deleted file mode 100644 index f9e1f13..0000000 --- a/.github/workflows/template-only-cd.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Template Deploy - -on: - push: - branches: - - main - workflow_dispatch: - -# Only allow one workflow at a time to prevent race conditions when pushing changes to the project repo -concurrency: template-only-cd - -jobs: - deploy: - name: Deploy - runs-on: ubuntu-latest - steps: - - name: Checkout template repo - uses: actions/checkout@v3 - with: - path: template-application-rails - - - name: Checkout project repo - uses: actions/checkout@v3 - with: - path: project-repo - repository: navapbc/platform-test-rails - token: ${{ secrets.PLATFORM_BOT_GITHUB_TOKEN }} - - - name: Update application template - working-directory: project-repo - run: ../template-application-rails/template-only-bin/update-template - - - name: Push changes to project repo - working-directory: project-repo - run: | - git config user.name nava-platform-bot - git config user.email platform-admins@navapbc.com - git add --all - # Commit changes (if no changes then no-op) - git diff-index --quiet HEAD || git commit -m "Template application deploy #${{ github.run_id }}" - git push \ No newline at end of file From be04300227494743126964267e65c9760b98ecb3 Mon Sep 17 00:00:00 2001 From: Rocket Date: Fri, 14 Jun 2024 17:18:03 -0700 Subject: [PATCH 21/21] Add template-only-cd github actions workflow --- .github/workflows/template-only-cd.yml | 41 ++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/template-only-cd.yml diff --git a/.github/workflows/template-only-cd.yml b/.github/workflows/template-only-cd.yml new file mode 100644 index 0000000..f9e1f13 --- /dev/null +++ b/.github/workflows/template-only-cd.yml @@ -0,0 +1,41 @@ +name: Template Deploy + +on: + push: + branches: + - main + workflow_dispatch: + +# Only allow one workflow at a time to prevent race conditions when pushing changes to the project repo +concurrency: template-only-cd + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + steps: + - name: Checkout template repo + uses: actions/checkout@v3 + with: + path: template-application-rails + + - name: Checkout project repo + uses: actions/checkout@v3 + with: + path: project-repo + repository: navapbc/platform-test-rails + token: ${{ secrets.PLATFORM_BOT_GITHUB_TOKEN }} + + - name: Update application template + working-directory: project-repo + run: ../template-application-rails/template-only-bin/update-template + + - name: Push changes to project repo + working-directory: project-repo + run: | + git config user.name nava-platform-bot + git config user.email platform-admins@navapbc.com + git add --all + # Commit changes (if no changes then no-op) + git diff-index --quiet HEAD || git commit -m "Template application deploy #${{ github.run_id }}" + git push \ No newline at end of file