From 902b4cfe9da7041db3ce76e5dd4500973369fe69 Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov Date: Sun, 14 Aug 2022 16:35:06 +0300 Subject: [PATCH 1/4] Update cloc.sh Delete .tokeignore Update cloc.sh Create .clocignore Update .clocignore Create cloc.sh Create Badge.yml Update cloc.sh Update .clocignore Update Badge.yml Update cloc.sh Update Badge.yml Update .clocignore Update .clocignore Update .clocignore Update cloc.sh Update .clocignore Update .clocignore Update .clocignore Update cloc.sh Update cloc.sh Update .clocignore Update cloc.sh Update .clocignore Update .clocignore Update .clocignore Update cloc.sh Update cloc.sh Update cloc.sh Update cloc.sh Update .clocignore Update cloc.sh Update .clocignore Update .clocignore Update .clocignore Update .clocignore Update cloc.sh Delete .clocignore Update cloc.sh Update cloc.sh Update cloc.sh Update cloc.sh Update cloc.sh Create .clocignore Update .clocignore Update .clocignore Update cloc.sh Update Sophia.yml Create cloc.yml Update .clocignore Update cloc.yml Update cloc.yml Update cloc.yml Update cloc.yml Update cloc.yml Update cloc.yml Update cloc.yml Update cloc.yml Update cloc.yml Update cloc.yml Update cloc.yml Update cloc.yml Update cloc.yml Update cloc.yml Update cloc.yml Update cloc.yml Delete Badge.yml --- .clocignore | 5 +++ .github/workflows/Sophia.yml | 3 +- .github/workflows/cloc.yml | 51 +++++++++++++++++++++++++++++ .tokeignore | 15 --------- Scripts/cloc.sh | 62 ++++++++++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 17 deletions(-) create mode 100644 .clocignore create mode 100644 .github/workflows/cloc.yml delete mode 100644 .tokeignore create mode 100644 Scripts/cloc.sh diff --git a/.clocignore b/.clocignore new file mode 100644 index 00000000..23665b86 --- /dev/null +++ b/.clocignore @@ -0,0 +1,5 @@ +"Sophia Script/Sophia Script for Windows 10/Module/Sophia.psm1" +"Sophia Script/Sophia Script for Windows 10 LTSC 2019/Module/Sophia.psm1" +"Sophia Script/Sophia Script for Windows 10 LTSC 2021/Module/Sophia.psm1" +"Sophia Script/Sophia Script for Windows 10 PowerShell 7/Module/Sophia.psm1" +"Sophia Script/Sophia Script for Windows 11 PowerShell 7/Module/Sophia.psm1" diff --git a/.github/workflows/Sophia.yml b/.github/workflows/Sophia.yml index b8b0fc0e..e67764c7 100644 --- a/.github/workflows/Sophia.yml +++ b/.github/workflows/Sophia.yml @@ -4,14 +4,13 @@ on: push: tags: - '*.*.*' - - '*.*' jobs: patch: runs-on: windows-latest timeout-minutes: 5 steps: - - uses: actions/checkout@master + - uses: actions/checkout@main - name: Signing all .ps1, .psm1, .psd1 files run: | . Scripts\Sign.ps1 diff --git a/.github/workflows/cloc.yml b/.github/workflows/cloc.yml new file mode 100644 index 00000000..1535bf98 --- /dev/null +++ b/.github/workflows/cloc.yml @@ -0,0 +1,51 @@ +name: Badges + +on: + push: + branches: + - '*' + +jobs: + update-badges: + name: Update Badges + runs-on: windows-latest + steps: + - name: Checkout Repository + uses: actions/checkout@main + - name: Download cloc + run: | + $Parameters = @{ + Uri = "https://api.github.com/repos/AlDanial/cloc/releases/latest" + UseBasicParsing = $true + Verbose = $true + } + $Tag = (Invoke-RestMethod @Parameters).tag_name.replace("v", "") + + $Parameters = @{ + Uri = "https://github.com/AlDanial/cloc/releases/download/v$Tag/cloc-$Tag.exe" + OutFile = "$PSScriptRoot\cloc.exe" + UseBasicParsing = $true + Verbose = $true + } + Invoke-WebRequest @Parameters + + - name: Get the Numbers + run: | + $JSON = & "$PSScriptRoot\cloc.exe" "Sophia Script\Sophia Script for Windows 11\Module\Sophia.psm1" --json | ConvertFrom-Json + $blank = $JSON.SUM.blank + $comment = $JSON.SUM.comment + $code = $JSON.SUM.code + $Summary = "$(($($blank + $comment + $code)/1000).ToString("#.#").replace(",", "."))k" + + echo "CODE_LINES=$Summary" >> $env:GITHUB_ENV + + - name: Create Lines-of-Code-Badge + uses: schneegans/dynamic-badges-action@master + with: + auth: ${{ secrets.GIST_SophiaScript }} + gistID: 9852d6b9569a91bf69ceba8a94cc97f4 + filename: SophiaScript.json + label: Lines of Code + message: ${{ env.CODE_LINES }} + namedLogo: PowerShell + color: brightgreen diff --git a/.tokeignore b/.tokeignore deleted file mode 100644 index 000b160c..00000000 --- a/.tokeignore +++ /dev/null @@ -1,15 +0,0 @@ -Sophia Script for Windows 10 LTSC 2019/ -Sophia Script for Windows 10 LTSC 2021/ -Sophia Script for Windows 10 PowerShell 7/ -Sophia Script for Windows 10/ -Sophia Script for Windows 11 PowerShell 7/bin/Start_Layout/ -Sophia Script for Windows 11/bin/Start_Layout/ -Wrapper/ -.github/ -img/ -gitattributes -CHANGELOG.md -.tokeignore -LICENSE -README.md -sophia_script_versions.json diff --git a/Scripts/cloc.sh b/Scripts/cloc.sh new file mode 100644 index 00000000..f311cdc1 --- /dev/null +++ b/Scripts/cloc.sh @@ -0,0 +1,62 @@ +# This scripts counts the lines of code and comments in all JavaScript files. +# The copyright-headers are substracted. It uses the command line tool "cloc". +# You can either pass --loc, --comments or --percentage to show the respective values only. + +# Exit the script when one command fails. +set -e + +# Go to the repo root. +cd "$( cd "$( dirname "$0" )" && pwd )/.." || \ + { echo "ERROR: Could not find the repo root."; exit 1; } + +# Run cloc - this counts code lines, blank lines and comment lines for the specified extensions. +# We are only interested in the summary, therefore the tail -1 +# https://github.com/AlDanial/cloc#options- +SUMMARY="$(cloc --include-ext="psd1" --exclude-list-file=.clocignore . --md | tail -1)" + +# The $SUMMARY is one line of a markdown table and looks like this: +# SUM:|101|3123|2238|10783 +# We use the following command to split it into an array. +IFS='|' read -r -a TOKENS <<< "$SUMMARY" + +# Store the individual tokens for better readability. +NUMBER_OF_FILES=${TOKENS[1]} +COMMENT_LINES=${TOKENS[3]} +LINES_OF_CODE=${TOKENS[4]} + +# To make the estimate of commented lines more accurate, we have to substract the +# copyright header which is included in each file. This header has the length of five lines. +# As cloc does not count inline comments, the overall estimate should be rather conservative. +COMMENT_LINES=$((COMMENT_LINES - 5 * NUMBER_OF_FILES)) + +# Print all results if no arguments are given. +if [[ $# -eq 0 ]] ; then + awk -v a="$LINES_OF_CODE" \ + 'BEGIN {printf "Lines of source code: %6.1fk\n", a/1000}' + awk -v a=$COMMENT_LINES \ + 'BEGIN {printf "Lines of comments: %6.1fk\n", a/1000}' + awk -v a=$COMMENT_LINES -v b="$LINES_OF_CODE" \ + 'BEGIN {printf "Comment Percentage: %6.1f%\n", 100*a/(a+b)}' + exit 0 +fi + +# Show lines of code. +if [[ "$*" == *--loc* ]] +then + awk -v a="$LINES_OF_CODE" \ + 'BEGIN {printf "%.1fk\n", a/1000}' +fi + +# Show lines of comments. +if [[ "$*" == *--comments* ]] +then + awk -v a=$COMMENT_LINES \ + 'BEGIN {printf "%.1fk\n", a/1000}' +fi + +# Show precentage of comments. +if [[ "$*" == *--percentage* ]] +then + awk -v a=$COMMENT_LINES -v b="$LINES_OF_CODE" \ + 'BEGIN {printf "%.1f\n", 100*a/(a+b)}' +fi From 65cf8c8d653df73e62a8d580f78fb77170f019fa Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov Date: Sun, 14 Aug 2022 23:03:51 +0300 Subject: [PATCH 2/4] Delete .clocignore --- .clocignore | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .clocignore diff --git a/.clocignore b/.clocignore deleted file mode 100644 index 23665b86..00000000 --- a/.clocignore +++ /dev/null @@ -1,5 +0,0 @@ -"Sophia Script/Sophia Script for Windows 10/Module/Sophia.psm1" -"Sophia Script/Sophia Script for Windows 10 LTSC 2019/Module/Sophia.psm1" -"Sophia Script/Sophia Script for Windows 10 LTSC 2021/Module/Sophia.psm1" -"Sophia Script/Sophia Script for Windows 10 PowerShell 7/Module/Sophia.psm1" -"Sophia Script/Sophia Script for Windows 11 PowerShell 7/Module/Sophia.psm1" From 16d3a404a706bd58b563117848458a041a6b416c Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov Date: Sun, 14 Aug 2022 23:05:27 +0300 Subject: [PATCH 3/4] Update cloc.yml --- .github/workflows/cloc.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cloc.yml b/.github/workflows/cloc.yml index 1535bf98..3c3808e7 100644 --- a/.github/workflows/cloc.yml +++ b/.github/workflows/cloc.yml @@ -2,8 +2,8 @@ name: Badges on: push: - branches: - - '*' + tags: + - '*.*.*' jobs: update-badges: From 2a95ff8c57ccedb11b944c6acfad1dec913c8624 Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov Date: Sun, 14 Aug 2022 23:53:39 +0300 Subject: [PATCH 4/4] Delete cloc.sh --- Scripts/cloc.sh | 62 ------------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 Scripts/cloc.sh diff --git a/Scripts/cloc.sh b/Scripts/cloc.sh deleted file mode 100644 index f311cdc1..00000000 --- a/Scripts/cloc.sh +++ /dev/null @@ -1,62 +0,0 @@ -# This scripts counts the lines of code and comments in all JavaScript files. -# The copyright-headers are substracted. It uses the command line tool "cloc". -# You can either pass --loc, --comments or --percentage to show the respective values only. - -# Exit the script when one command fails. -set -e - -# Go to the repo root. -cd "$( cd "$( dirname "$0" )" && pwd )/.." || \ - { echo "ERROR: Could not find the repo root."; exit 1; } - -# Run cloc - this counts code lines, blank lines and comment lines for the specified extensions. -# We are only interested in the summary, therefore the tail -1 -# https://github.com/AlDanial/cloc#options- -SUMMARY="$(cloc --include-ext="psd1" --exclude-list-file=.clocignore . --md | tail -1)" - -# The $SUMMARY is one line of a markdown table and looks like this: -# SUM:|101|3123|2238|10783 -# We use the following command to split it into an array. -IFS='|' read -r -a TOKENS <<< "$SUMMARY" - -# Store the individual tokens for better readability. -NUMBER_OF_FILES=${TOKENS[1]} -COMMENT_LINES=${TOKENS[3]} -LINES_OF_CODE=${TOKENS[4]} - -# To make the estimate of commented lines more accurate, we have to substract the -# copyright header which is included in each file. This header has the length of five lines. -# As cloc does not count inline comments, the overall estimate should be rather conservative. -COMMENT_LINES=$((COMMENT_LINES - 5 * NUMBER_OF_FILES)) - -# Print all results if no arguments are given. -if [[ $# -eq 0 ]] ; then - awk -v a="$LINES_OF_CODE" \ - 'BEGIN {printf "Lines of source code: %6.1fk\n", a/1000}' - awk -v a=$COMMENT_LINES \ - 'BEGIN {printf "Lines of comments: %6.1fk\n", a/1000}' - awk -v a=$COMMENT_LINES -v b="$LINES_OF_CODE" \ - 'BEGIN {printf "Comment Percentage: %6.1f%\n", 100*a/(a+b)}' - exit 0 -fi - -# Show lines of code. -if [[ "$*" == *--loc* ]] -then - awk -v a="$LINES_OF_CODE" \ - 'BEGIN {printf "%.1fk\n", a/1000}' -fi - -# Show lines of comments. -if [[ "$*" == *--comments* ]] -then - awk -v a=$COMMENT_LINES \ - 'BEGIN {printf "%.1fk\n", a/1000}' -fi - -# Show precentage of comments. -if [[ "$*" == *--percentage* ]] -then - awk -v a=$COMMENT_LINES -v b="$LINES_OF_CODE" \ - 'BEGIN {printf "%.1f\n", 100*a/(a+b)}' -fi