From cc1be019d7582eaeab4667d5a23e713fc7dc4fde Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Mon, 3 Jun 2024 16:36:12 +0100 Subject: [PATCH 01/10] editorconfig: update to align with reality Set the root = true flag, so tools don't continue traversing the tree looking for more editorconfig files. In practise we have Unix line endings so adjust the end_of_line flag and enable UTF-8 charset. Enable final newline for all files but patches - most editors already insert one and git gets unhappy otherwise. Finally, use 4 space indent for shell scripts... In practise their style varies _a lot_ but this seems reasonable default IMHO. Signed-off-by: Emil Velikov --- .editorconfig | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/.editorconfig b/.editorconfig index 478b03e9..892334f8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,5 +1,15 @@ -[*.{yaml,sh,gn_args}] -tab_width = 2 +root = true + +[*] +charset = utf-8 +end_of_line = lf indent_size = 2 -end_of_line = crlf -indent_style = space \ No newline at end of file +indent_style = space +insert_final_newline = true + +[*.sh] +indent_size = 4 +indent_style = space + +[*.patch] +insert_final_newline = false From abde6d117a4f983648e7f3c6f2114c412a95e2f3 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Mon, 3 Jun 2024 16:40:16 +0100 Subject: [PATCH 02/10] tools: remove unused fields Category/Context Signed-off-by: Emil Velikov --- tools/extract-patch-data.sh | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tools/extract-patch-data.sh b/tools/extract-patch-data.sh index 4823313d..dc918677 100644 --- a/tools/extract-patch-data.sh +++ b/tools/extract-patch-data.sh @@ -15,18 +15,12 @@ do elif [[ $current_line =~ ^License:* ]]; then LICENSE=`echo ${current_line:9} | cut -d ' ' -f1` - elif [[ $current_line =~ ^Category:* ]]; then - CATEGORY=`echo ${current_line:9} | cut -d ' ' -f1` - elif [[ $current_line =~ ^"Original License:"* ]]; then continue elif [[ $current_line =~ ^From:* ]]; then FROM=`echo ${current_line:5} | cut -d ' ' -f1` - elif [[ $current_line =~ ^Context:* ]]; then - CONTEXT=${current_line:8} - elif [[ $current_line =~ ^---* ]]; then break @@ -43,8 +37,6 @@ done # echo SUBJECT: $SUBJECT # echo DATE: $DATE # echo LICENSE: $LICENSE -# echo CONTEXT: $CONTEXT -# echo CATEGORY: $CATEGORY # echo -e MESSAGE: $MESSAGE SUBJECT=`echo $SUBJECT | xargs` @@ -53,7 +45,6 @@ echo "|**$SUBJECT**" \ "
"$DATE"" \ "
File: [$(basename $PATCH)](/build/patches/$(basename $PATCH))" \ "
Author: "$FROM"" \ - "
Context: "$CONTEXT"" \ "
License: "$LICENSE"" \ "|"$MESSAGE"|" ) From 62947d3569b9e18596297e36c61f6aab2dbe84b3 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Mon, 3 Jun 2024 17:05:48 +0100 Subject: [PATCH 03/10] tools: rework patch handling Feed the (base) filename as yet another token and do read from stdin for the child script. Signed-off-by: Emil Velikov --- tools/extract-all-patch-data.sh | 10 ++++++---- tools/extract-patch-data.sh | 10 +++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tools/extract-all-patch-data.sh b/tools/extract-all-patch-data.sh index 2a43f4aa..e27ac33e 100644 --- a/tools/extract-all-patch-data.sh +++ b/tools/extract-all-patch-data.sh @@ -1,13 +1,15 @@ #!/bin/bash -FOLDER=$1 -SCRIPT_FOLDER="$(dirname "$0")" +SCRIPT_FOLDER="$(realpath "$(dirname "$0")")" +SCRIPT="$SCRIPT_FOLDER/extract-patch-data.sh" OUTPUT="$SCRIPT_FOLDER"/../docs/PATCHES.md test -f $OUTPUT && rm $OUTPUT -for filename in "$FOLDER"/*.patch; do - bash $SCRIPT_FOLDER/extract-patch-data.sh $filename >>$OUTPUT +pushd "$1" >/dev/null + +for filename in *.patch; do + (echo "Filename: $filename"; cat "$filename") | bash "$SCRIPT" >>"$OUTPUT" done sort -k1 -t"|" -o $OUTPUT $OUTPUT diff --git a/tools/extract-patch-data.sh b/tools/extract-patch-data.sh index dc918677..ecce8166 100644 --- a/tools/extract-patch-data.sh +++ b/tools/extract-patch-data.sh @@ -1,12 +1,13 @@ #!/bin/bash -PATCH=$1 CR=$(printf "\r") -cat $PATCH | ( while read current_line do - if [[ $current_line =~ ^Subject:* ]]; then + if [[ $current_line =~ ^Filename:* ]]; then + FILENAME=${current_line:9} + + elif [[ $current_line =~ ^Subject:* ]]; then SUBJECT=${current_line:8} elif [[ $current_line =~ ^Date:* ]]; then @@ -43,8 +44,7 @@ SUBJECT=`echo $SUBJECT | xargs` echo "|**$SUBJECT**" \ "
"$DATE"" \ - "
File: [$(basename $PATCH)](/build/patches/$(basename $PATCH))" \ + "
File: [$FILENAME](/build/patches/$FILENAME)" \ "
Author: "$FROM"" \ "
License: "$LICENSE"" \ "|"$MESSAGE"|" -) From d637fea1e7621fe4b2ca85c3918faccbf60f7bfd Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Mon, 3 Jun 2024 17:07:18 +0100 Subject: [PATCH 04/10] tools: remove dubious CR and SUBJECT handling CR is (seemingly) unused, while the SUBJECT cannot be multi-line, so the xargs doesn't do anything. Signed-off-by: Emil Velikov --- tools/extract-patch-data.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools/extract-patch-data.sh b/tools/extract-patch-data.sh index ecce8166..fa3dd73b 100644 --- a/tools/extract-patch-data.sh +++ b/tools/extract-patch-data.sh @@ -1,7 +1,5 @@ #!/bin/bash -CR=$(printf "\r") - while read current_line do if [[ $current_line =~ ^Filename:* ]]; then @@ -40,8 +38,6 @@ done # echo LICENSE: $LICENSE # echo -e MESSAGE: $MESSAGE -SUBJECT=`echo $SUBJECT | xargs` - echo "|**$SUBJECT**" \ "
"$DATE"" \ "
File: [$FILENAME](/build/patches/$FILENAME)" \ From a82400d14b823356b6b32761572a7a7f423dbb23 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Mon, 3 Jun 2024 17:09:58 +0100 Subject: [PATCH 05/10] tools: unconditionally remove previous file Drop the test -f, use rm -f - it does the same thing. Modulo, if we accidentally end up with folder/char devices of the same name. In which case existing code already explodes. Signed-off-by: Emil Velikov --- tools/extract-all-patch-data.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/extract-all-patch-data.sh b/tools/extract-all-patch-data.sh index e27ac33e..5b89071b 100644 --- a/tools/extract-all-patch-data.sh +++ b/tools/extract-all-patch-data.sh @@ -4,7 +4,7 @@ SCRIPT_FOLDER="$(realpath "$(dirname "$0")")" SCRIPT="$SCRIPT_FOLDER/extract-patch-data.sh" OUTPUT="$SCRIPT_FOLDER"/../docs/PATCHES.md -test -f $OUTPUT && rm $OUTPUT +rm -f "$OUTPUT" pushd "$1" >/dev/null From 239281614858fe83ab78172c2c392bfbcaecc547 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Mon, 3 Jun 2024 17:21:12 +0100 Subject: [PATCH 06/10] tools: pipe the output directly into sort Signed-off-by: Emil Velikov --- tools/extract-all-patch-data.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/extract-all-patch-data.sh b/tools/extract-all-patch-data.sh index 5b89071b..6d8d9a55 100644 --- a/tools/extract-all-patch-data.sh +++ b/tools/extract-all-patch-data.sh @@ -9,10 +9,8 @@ rm -f "$OUTPUT" pushd "$1" >/dev/null for filename in *.patch; do - (echo "Filename: $filename"; cat "$filename") | bash "$SCRIPT" >>"$OUTPUT" -done - -sort -k1 -t"|" -o $OUTPUT $OUTPUT + (echo "Filename: $filename"; cat "$filename") | bash "$SCRIPT" +done | sort -k1 -t"|" -o "$OUTPUT" sed -i '1s/^/| Patch | Message |\n/' $OUTPUT sed -i '2s/^/|--------|--------|\n/' $OUTPUT From 9bfe299184c6516008c99a042882c605bf7741b8 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Mon, 3 Jun 2024 17:35:57 +0100 Subject: [PATCH 07/10] tools: quote as appropriate Drop a few erroneous quotes and add some as needed. Signed-off-by: Emil Velikov --- tools/extract-all-patch-data.sh | 6 +++--- tools/extract-patch-data.sh | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/extract-all-patch-data.sh b/tools/extract-all-patch-data.sh index 6d8d9a55..01acf24e 100644 --- a/tools/extract-all-patch-data.sh +++ b/tools/extract-all-patch-data.sh @@ -3,7 +3,7 @@ SCRIPT_FOLDER="$(realpath "$(dirname "$0")")" SCRIPT="$SCRIPT_FOLDER/extract-patch-data.sh" -OUTPUT="$SCRIPT_FOLDER"/../docs/PATCHES.md +OUTPUT="$SCRIPT_FOLDER/../docs/PATCHES.md" rm -f "$OUTPUT" pushd "$1" >/dev/null @@ -12,5 +12,5 @@ for filename in *.patch; do (echo "Filename: $filename"; cat "$filename") | bash "$SCRIPT" done | sort -k1 -t"|" -o "$OUTPUT" -sed -i '1s/^/| Patch | Message |\n/' $OUTPUT -sed -i '2s/^/|--------|--------|\n/' $OUTPUT +sed -i '1s/^/| Patch | Message |\n/' "$OUTPUT" +sed -i '2s/^/|--------|--------|\n/' "$OUTPUT" diff --git a/tools/extract-patch-data.sh b/tools/extract-patch-data.sh index fa3dd73b..78cfdade 100644 --- a/tools/extract-patch-data.sh +++ b/tools/extract-patch-data.sh @@ -39,8 +39,8 @@ done # echo -e MESSAGE: $MESSAGE echo "|**$SUBJECT**" \ - "
"$DATE"" \ + "
$DATE" \ "
File: [$FILENAME](/build/patches/$FILENAME)" \ - "
Author: "$FROM"" \ - "
License: "$LICENSE"" \ - "|"$MESSAGE"|" + "
Author: $FROM" \ + "
License: $LICENSE" \ + "|$MESSAGE|" From fe92d1b2387f1d54de86457d2dd7823e93a44440 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Mon, 3 Jun 2024 17:37:08 +0100 Subject: [PATCH 08/10] tools: enable bash "safe mode" Signed-off-by: Emil Velikov --- tools/extract-all-patch-data.sh | 2 ++ tools/extract-patch-data.sh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tools/extract-all-patch-data.sh b/tools/extract-all-patch-data.sh index 01acf24e..82b52acd 100644 --- a/tools/extract-all-patch-data.sh +++ b/tools/extract-all-patch-data.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -euo pipefail + SCRIPT_FOLDER="$(realpath "$(dirname "$0")")" SCRIPT="$SCRIPT_FOLDER/extract-patch-data.sh" diff --git a/tools/extract-patch-data.sh b/tools/extract-patch-data.sh index 78cfdade..7c34044b 100644 --- a/tools/extract-patch-data.sh +++ b/tools/extract-patch-data.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -euo pipefail + while read current_line do if [[ $current_line =~ ^Filename:* ]]; then From f24116b3fce5c3b70c7624dfbd0133615f30ce7a Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Mon, 3 Jun 2024 21:00:30 +0100 Subject: [PATCH 09/10] tools: fixup the remaining shellcheck issues Namely: - use $() over deprecated `` - read -r, so \ is not mangled - use -n instead of ! -z Signed-off-by: Emil Velikov --- tools/extract-patch-data.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tools/extract-patch-data.sh b/tools/extract-patch-data.sh index 7c34044b..d14eb118 100644 --- a/tools/extract-patch-data.sh +++ b/tools/extract-patch-data.sh @@ -2,8 +2,7 @@ set -euo pipefail -while read current_line -do +while read -r current_line; do if [[ $current_line =~ ^Filename:* ]]; then FILENAME=${current_line:9} @@ -14,19 +13,19 @@ do DATE=${current_line:5} elif [[ $current_line =~ ^License:* ]]; then - LICENSE=`echo ${current_line:9} | cut -d ' ' -f1` + LICENSE=$(echo "${current_line:9}" | cut -d ' ' -f1) elif [[ $current_line =~ ^"Original License:"* ]]; then continue elif [[ $current_line =~ ^From:* ]]; then - FROM=`echo ${current_line:5} | cut -d ' ' -f1` + FROM=$(echo "${current_line:5}" | cut -d ' ' -f1) elif [[ $current_line =~ ^---* ]]; then break - elif [ ! -z "$current_line" ]; then - if [ ! -z "$MESSAGE" ]; then + elif [ -n "$current_line" ]; then + if [ -n "$MESSAGE" ]; then MESSAGE+="
" fi MESSAGE+=$current_line From 20300e5e91c1c883a4052e548faeaa0360d94cec Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Mon, 3 Jun 2024 21:09:13 +0100 Subject: [PATCH 10/10] CI: remove unnecessary variables and indirection Drop the indirection - we don't need to checkout to custom location. Thus we can drop the no longer used HOME and RTAG variables. Signed-off-by: Emil Velikov --- .github/workflows/update-patches-doc.yaml | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/.github/workflows/update-patches-doc.yaml b/.github/workflows/update-patches-doc.yaml index f3f7275a..c3b7f889 100644 --- a/.github/workflows/update-patches-doc.yaml +++ b/.github/workflows/update-patches-doc.yaml @@ -32,33 +32,19 @@ jobs: build: runs-on: ubuntu-latest steps: - - - name: "Get value from dispatch" - run: | - if [ -z "${RTAG}" ]; then - echo "RTAG=$GITHUB_SHA" >> $GITHUB_ENV - echo "RTAG=$RTAG" - fi - - name: Checkout 'uazo/cromite' ${{ env.BRANCH }} uses: actions/checkout@v2 with: repository: 'uazo/cromite' ref: ${{ github.event.inputs.rtag }} - path: 'cromite' fetch-depth: 1 - name: Generate patches doc run: | - export HOME=$GITHUB_WORKSPACE - - bash ~/cromite/tools/extract-all-patch-data.sh ~/cromite/build/patches + bash ./tools/extract-all-patch-data.sh ./build/patches - name: Check differences CHANGES=${{ env.CHANGES }} run: | - export HOME=$GITHUB_WORKSPACE - - cd ~/cromite CHANGES=0 && git diff --quiet || CHANGES=1 echo "CHANGES=$CHANGES" >> $GITHUB_ENV