generated from nhs-england-tools/repository-template
-
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.
Specify repository template branch to be used
- Loading branch information
Showing
6 changed files
with
23 additions
and
13 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 |
---|---|---|
|
@@ -56,6 +56,7 @@ Locally | |
make docker-build | ||
make docker-test \ | ||
REPOSITORY_TEMPLATE=github.com/nhs-england-tools/repository-template \ | ||
BRANCH_NAME=main \ | ||
REPOSITORY_TO_UPDATE=github.com/nhs-england-tools/update-from-template-app \ | ||
GIT_USER_NAME="Update from Template App" \ | ||
GIT_USER_EMAIL="[email protected]" \ | ||
|
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 |
---|---|---|
|
@@ -9,10 +9,13 @@ build_datetime_local=$(date --date="$datetime" +"%Y-%m-%dT%H:%M:%S%z") | |
build_datetime=$datetime | ||
build_timestamp=$(date --date="$datetime" -u +"%Y%m%d%H%M%S") | ||
|
||
branch_name=${BRANCH_NAME:-"main"} | ||
org=$(echo "$REPOSITORY_TO_UPDATE" | cut -d'/' -f2) | ||
|
||
work_dir=/github/workspace | ||
src_dir=$work_dir/repository-template | ||
dest_dir=$work_dir/repository-to-update | ||
list_of_files_to_update_json=${work_dir}/update-from-template.json | ||
list_of_files_to_update_json=$work_dir/update-from-template.json | ||
|
||
git_user_name=${GIT_USER_NAME:-"unknown"} | ||
git_user_email=${GIT_USER_EMAIL:-"[email protected]"} | ||
|
@@ -25,7 +28,6 @@ GITHUB_APP_SK_CONTENT_FILE=$work_dir/gh_app_sk.pem | |
if ! [ -f $GITHUB_APP_SK_CONTENT_FILE ]; then | ||
echo "$GITHUB_APP_SK_CONTENT" > $GITHUB_APP_SK_CONTENT_FILE | ||
fi | ||
org=$(echo "${REPOSITORY_TO_UPDATE}" | cut -d'/' -f2) | ||
|
||
# ============================================================================== | ||
|
||
|
@@ -112,13 +114,15 @@ function fetch-repositories-content() { | |
) | ||
fi | ||
fi | ||
cd $src_dir | ||
git checkout $branch_name | ||
} | ||
|
||
function prune-legacy-updates() { | ||
|
||
[ -z "$github_token" ] && return | ||
|
||
cd ${dest_dir} | ||
cd $dest_dir | ||
# Close legacy PRs | ||
pr_numbers=$(gh pr list --search "Update from template" --json number,title | jq '.[] | select(.title | startswith("Update from template")).number') | ||
for pr_number in $pr_numbers; do | ||
|
@@ -132,18 +136,18 @@ function prune-legacy-updates() { | |
|
||
function checkout-new-branch() { | ||
|
||
cd ${dest_dir} | ||
cd $dest_dir | ||
git checkout -b update-from-template-${build_timestamp} | ||
} | ||
|
||
function produce-list-of-files-to-update() { | ||
|
||
cd ${dest_dir} | ||
cd $dest_dir | ||
/update-from-template \ | ||
--source-dir ${src_dir} \ | ||
--destination-dir ${dest_dir} \ | ||
--source-dir $src_dir \ | ||
--destination-dir $dest_dir \ | ||
--app-config-file /update-from-template.yaml \ | ||
--template-config-file ${dest_dir}/scripts/config/repository-template.yaml \ | ||
--template-config-file $dest_dir/scripts/config/repository-template.yaml \ | ||
> $list_of_files_to_update_json | ||
} | ||
|
||
|
@@ -156,22 +160,22 @@ function update-files() { | |
) | ||
echo "$to_update" | while IFS= read -r file; do | ||
dir=$(dirname "$file") | ||
mkdir -p ${dest_dir}/$dir | ||
cp ${src_dir}/$file ${dest_dir}/$file | ||
mkdir -p $dest_dir/$dir | ||
cp $src_dir/$file $dest_dir/$file | ||
done | ||
# Delete files | ||
to_delete=$( | ||
cat $list_of_files_to_update_json \ | ||
| jq -r '.comparison | to_entries[] | select(.value.action == "delete") | .key' | ||
) | ||
echo "$to_delete" | while IFS= read -r file; do | ||
rm -rf ${dest_dir}/$file | ||
rm -rf $dest_dir/$file | ||
done | ||
} | ||
|
||
function push-and-create-pull-request() { | ||
|
||
cd ${dest_dir} | ||
cd $dest_dir | ||
# Add and commit changes | ||
git add -A | ||
git commit -m "Update from template ${build_datetime_local}" | ||
|
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 |
---|---|---|
|
@@ -28,6 +28,7 @@ runs: | |
with: | ||
build_datetime: "${{ inputs.build_datetime }}" | ||
repository_template: github.com/nhs-england-tools/repository-template | ||
branch_name: "main" | ||
repository_to_update: github.com/nhs-england-tools/update-from-template-app | ||
git_user_name: "Update from Template App" | ||
git_user_email: "[email protected]" | ||
|