Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: config files inside .GitHub folder #252

Merged
merged 13 commits into from
Dec 25, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ jobs:

Create a `.templatesyncignore` file. Just like writing a `.gitignore` file, follow the [glob pattern](https://en.wikipedia.org/wiki/Glob_(programming)) in defining the files and folders that should be excluded from syncing with the template repository.

It can also be stored inside `.github` folder.

## Debug

You must create a secret named `ACTIONS_STEP_DEBUG` with the value `true` to see the debug messages set by this command in the log. For more information, see "[Enabling debug logging.][enabling-debug-logging]"
Expand Down
38 changes: 26 additions & 12 deletions src/sync_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,29 @@ if [[ -n "${SRC_SSH_PRIVATEKEY_ABS_PATH}" ]]; then
export GIT_SSH_COMMAND="ssh -i ${SRC_SSH_PRIVATEKEY_ABS_PATH}"
fi

TEMPLATE_VERSION_FILE_NAME=".templateversionrc"
TEMPLATE_SYNC_IGNORE_FILE_NAME=".templatesyncignore"
TEMPLATE_VERSION_FILE_PATH=".templateversionrc"
TEMPLATE_SYNC_IGNORE_FILE_PATH=".templatesyncignore"
TEMPLATE_REMOTE_GIT_HASH=$(git ls-remote "${SOURCE_REPO}" HEAD | awk '{print $1}')
NEW_TEMPLATE_GIT_HASH=$(git rev-parse --short "${TEMPLATE_REMOTE_GIT_HASH}")
NEW_BRANCH="${PR_BRANCH_NAME_PREFIX}_${NEW_TEMPLATE_GIT_HASH}"

echo "::group::Check new changes"
echo "::debug::new Git HASH ${NEW_TEMPLATE_GIT_HASH}"
if [ -r ${TEMPLATE_VERSION_FILE_NAME} ]
then
CURRENT_TEMPLATE_GIT_HASH=$(cat ${TEMPLATE_VERSION_FILE_NAME})

# Check if the Version File exists inside root of the repository
if [[ -f "$TEMPLATE_VERSION_FILE_PATH" ]]; then
LuisHenri marked this conversation as resolved.
Show resolved Hide resolved
echo "::debug::version file is located in root folder"
else
# Else use it as if it is located in the .github folder
echo "::debug::version file is located either in .github folder or not present"
TEMPLATE_VERSION_FILE_PATH=".github/$TEMPLATE_VERSION_FILE_PATH"
fi
if [ -r ${TEMPLATE_VERSION_FILE_PATH} ]; then
CURRENT_TEMPLATE_GIT_HASH=$(cat ${TEMPLATE_VERSION_FILE_PATH})
echo "::debug::Current git hash ${CURRENT_TEMPLATE_GIT_HASH}"
fi

if [ "${NEW_TEMPLATE_GIT_HASH}" == "${CURRENT_TEMPLATE_GIT_HASH}" ]
then
if [ "${NEW_TEMPLATE_GIT_HASH}" == "${CURRENT_TEMPLATE_GIT_HASH}" ]; then
echo "::warn::repository is up to date"
exit 0
fi
Expand All @@ -58,19 +65,26 @@ echo "::endgroup::"

echo "::group::persist template version"
echo "write new template version file"
echo "${NEW_TEMPLATE_GIT_HASH}" > ${TEMPLATE_VERSION_FILE_NAME}
echo "::debug::wrote new template version file with content $(cat ${TEMPLATE_VERSION_FILE_NAME})"
echo "${NEW_TEMPLATE_GIT_HASH}" > ${TEMPLATE_VERSION_FILE_PATH}
echo "::debug::wrote new template version file with content $(cat ${TEMPLATE_VERSION_FILE_PATH})"
echo "::endgroup::"

echo "::group::commit and push changes"
git add .

# Check if the Ignore File exists inside root of the repository
if [[ -f "$TEMPLATE_SYNC_IGNORE_FILE_PATH" ]]; then
echo "::debug::ignore file is located in root folder"
else
# Else use it as if it is located in the .github folder
echo "::debug::ignore file is located either in .github folder or not present"
TEMPLATE_SYNC_IGNORE_FILE_PATH=".github/$TEMPLATE_SYNC_IGNORE_FILE_PATH"
fi
# we are checking the ignore file if it exists or is empty
# -s is true if the file contains whitespaces
if [ -s ${TEMPLATE_SYNC_IGNORE_FILE_NAME} ]
then
if [ -s ${TEMPLATE_SYNC_IGNORE_FILE_PATH} ]; then
echo "::debug::unstage files from template sync ignore"
git reset --pathspec-from-file="${TEMPLATE_SYNC_IGNORE_FILE_NAME}"
git reset --pathspec-from-file="${TEMPLATE_SYNC_IGNORE_FILE_PATH}"

echo "::debug::clean untracked files"
git clean -df
Expand Down