Skip to content

Commit

Permalink
feat: add fix-copyrights.sh script (#254)
Browse files Browse the repository at this point in the history
Signed-off-by: Phil Adams <phil_adams@us.ibm.com>
  • Loading branch information
padamstx authored Aug 13, 2024
1 parent 13ec7f3 commit c867fd4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
27 changes: 27 additions & 0 deletions scripts/fix-copyrights.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
#
# * Copyright 2017 - 2024 IBM Corporation.
# * SPDX-License-Identifier: Apache2.0
#

#
# The purpose of this script is to revert changes to generated files where the file changed
# only in the copyright statement (i.e. no other differences in the file contents).
#
# Run this script in a git repo containing uncommitted changes produced from SDK generation.
#
# Usage:
# <project-root>/scripts/fix-copyrights.sh
#

git diff --name-only | while read f; do
# Must be only one line added and one deleted
git diff --shortstat "$f" | grep "1 insertion(+), 1 deletion(-)" > /dev/null
if [ $? == 0 ]; then
git diff "$f" | grep "(C) Copyright IBM Corp\. 20[0-9][0-9]." > /dev/null
if [ $? == 0 ]; then
echo "Reverting copyright change in $f"
git checkout -- "$f"
fi
fi
done
23 changes: 23 additions & 0 deletions update_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,29 @@ Example:
git diff # alternative: use the "source control" view within vscode
```

#### Revert insignificant changes
When the Java SDK code for a service is re-generated, it is not uncommon for some generated classes
(especially model classes) to see changes only in their copyright statements, with no other changes
to their generated source.

These types of changes are insignificant, and they can (and to some degree should), be reverted.
Reverting these changes will help to avoid cluttering your PRs and git change history,
and in some respects the copyright year should not be changed if no other changes are being made to the file.
Unfortunately, it's difficult for the generator to operate this way so it simply re-generates all classes
associated with a service and if this re-generation is occurring in a different year than the previous
generation, then you'll see the change to the copyright statement.

To automatically revert these changes, just run the `fix-copyrights.sh` script
in the project root directory:
```
cd <project-root>
scripts/fix-copyrights.sh
```
The script will examine each file with uncommitted changes, and for those files with changes
only in their copyright statement, a `git checkout` is performed to
discard the changes and revert the files to their pervious version.


### 5. Run unit tests
Next, run the unit tests. You can run the unit tests for all the services like this:
```sh
Expand Down

0 comments on commit c867fd4

Please sign in to comment.