Skip to content

Commit

Permalink
Fix copyright update script on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
ffried committed Jan 3, 2024
1 parent 2df0a9e commit 178d91b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/copyright-updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Update copyright years

on:
schedule:
- cron: '42 14 3 1 *' # 3rd of January at 14:42
- cron: '42 13 3 1 *' # 3rd of January at 13:42 UTC
workflow_dispatch:
inputs:
year:
Expand Down
37 changes: 24 additions & 13 deletions Scripts/update-copyright.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ last_year() {
# Arg1: Mode (full, usage_only). Defaults to 'full'.
print_usage() {
echo "Usage: ${SCRIPT_NAME} [OLD_YEAR NEW_YEAR]"
if [[ "${1:-full}" == "full" ]]; then
echo ""
echo "If called with OLD_YEAR and NEW_YEAR arguments, updates the copyright years from OLD_YEAR to NEW_YEAR."
echo "If called with no arguments but OLD_YEAR and NEW_YEAR environment variables defined, updates from OLD_YEAR to NEW_YEAR."
echo "If called with no arguments and OLD_YEAR and NEW_YEAR not being defined, updates from last year to the current year."
echo ""
echo "Examples:"
if [[ "${1:-full}" = 'full' ]]; then
echo ''
echo 'If called with OLD_YEAR and NEW_YEAR arguments, updates the copyright years from OLD_YEAR to NEW_YEAR.'
echo 'If called with no arguments but OLD_YEAR and NEW_YEAR environment variables defined, updates from OLD_YEAR to NEW_YEAR.'
echo 'If called with no arguments and OLD_YEAR and NEW_YEAR not being defined, updates from last year to the current year.'
echo ''
echo 'Examples:'
echo "$ ${SCRIPT_NAME} 2016 2017 # Updates from 2016 to 2017."
echo "$ OLD_YEAR=2017 NEW_YEAR=2018 ${SCRIPT_NAME} # Updates from 2017 to 2018."
echo "$ ${SCRIPT_NAME} # Updates from $(last_year) to $(current_year)."
Expand All @@ -43,13 +43,13 @@ if [[ $# -gt 0 ]]; then
if [[ $# -eq 2 ]]; then
OLD_YEAR="$1"
NEW_YEAR="$2"
elif [[ $# -eq 1 ]] && [[ $1 == "--help" ]] || [[ $1 == "-h" ]]; then
elif [[ $# -eq 1 ]] && [[ $1 == '--help' ]] || [[ $1 == '-h' ]]; then
print_usage 'full'
exit 0
else
echo "Specifying years via command line arguments requires two arguments (OLD_YEAR and NEW_YEAR)!"
echo "For more information use --help."
echo ""
echo 'Specifying years via command line arguments requires two arguments (OLD_YEAR and NEW_YEAR)!'
echo 'For more information use --help.'
echo ''
print_usage 'usage_only'
exit -1
fi
Expand All @@ -58,9 +58,20 @@ fi
# We need to export the function so that bash can call it from the find exec argument.
export -f replace_copyright

EXTENDED_REGEX_FLAG_POST_PATH='-regextype posix-extended'
EXTENDED_REGEX_FLAG_PRE_PATH=''
if [[ "$(uname -s)" = 'Darwin' ]]; then
EXTENDED_REGEX_FLAG_PRE_PATH='-E'
EXTENDED_REGEX_FLAG_POST_PATH=''
fi

pushd "$(dirname $0)/../" > /dev/null
find -E . -regex ".*\.([hm]|swift|pch)" -exec bash -c "replace_copyright \"${OLD_YEAR}\" \"${NEW_YEAR}\" \"{}\"" \;
replace_copyright "${OLD_YEAR}" "${NEW_YEAR}" "./LICENSE"
find ${EXTENDED_REGEX_FLAG_PRE_PATH} \
. \
${EXTENDED_REGEX_FLAG_POST_PATH} \
-regex ".*\.([hm]|swift|pch)" \
-exec bash -c "replace_copyright \"${OLD_YEAR}\" \"${NEW_YEAR}\" \"{}\"" \;
replace_copyright "${OLD_YEAR}" "${NEW_YEAR}" './LICENSE'
popd > /dev/null

# Delete the function again
Expand Down

0 comments on commit 178d91b

Please sign in to comment.