From fe68867f58784c3ce8856b29318e700a287c28b7 Mon Sep 17 00:00:00 2001 From: Tomas Dvorak Date: Fri, 30 Aug 2024 17:16:27 +0200 Subject: [PATCH] ci: improve copyright script Ref: #11 --- scripts/copyright.sh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/scripts/copyright.sh b/scripts/copyright.sh index 29b56119..4188b6d9 100755 --- a/scripts/copyright.sh +++ b/scripts/copyright.sh @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + set -e # Path to the package.json file @@ -27,8 +28,24 @@ fi AUTHOR=$(jq -r '.author' "$PACKAGE_JSON_PATH") # Check if the author property is not null or empty -if [[ ! -n "$AUTHOR" ]]; then +if [[ -z "$AUTHOR" ]]; then echo "Error: author property not found in package.json" + exit 1 +fi + +# Check if 'nwa' command is not available and 'go' is available, then install 'nwa' +if ! command -v nwa &> /dev/null && command -v go &> /dev/null; then + echo "Installing 'nwa' via 'go' (https://github.com/B1NARY-GR0UP/nwa)" + go install github.com/B1NARY-GR0UP/nwa@latest + # Ensure the GOPATH is added to the PATH environment variable + export PATH=$PATH:$(go env GOPATH)/bin fi -nwa add -l apache -c "$AUTHOR" src dist tests +if command -v nwa &> /dev/null; then + nwa add -l apache -c "$AUTHOR" src dist tests scripts +elif command -v docker &> /dev/null; then + docker run -it -v "${PWD}:/src" ghcr.io/b1nary-gr0up/nwa:main add -l apache -c "$AUTHOR" src dist tests scripts +else + echo "Error: 'nwa' is not available. Either install it manually or install go/docker." + exit 1 +fi