From 670708158376fe6f4138dd74f3c9ab80c27895ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Thu, 30 May 2024 14:58:55 +0000 Subject: [PATCH 01/13] Add code sample frontmatter in docstring --- code-samples/actors-sequential.pony | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/code-samples/actors-sequential.pony b/code-samples/actors-sequential.pony index 49915fdf..9b3c4799 100644 --- a/code-samples/actors-sequential.pony +++ b/code-samples/actors-sequential.pony @@ -1,3 +1,10 @@ +""" +description: "Execution order of actor behaviors" +stdout: This is printed first\nThis is printed last\n +stderr: +exitcode: 0 +""" + actor Main new create(env: Env) => call_me_later(env) From 1d44c08ed7c96ee89566ef4f0adbde397ec49b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Fri, 31 May 2024 00:30:54 +0000 Subject: [PATCH 02/13] Setup GitHub action --- .github/workflows/check-code-samples.sh | 65 ++++++++++++++++++++++++ .github/workflows/check-code-samples.yml | 17 +++++++ code-samples.json | 12 +++++ 3 files changed, 94 insertions(+) create mode 100755 .github/workflows/check-code-samples.sh create mode 100644 .github/workflows/check-code-samples.yml create mode 100644 code-samples.json diff --git a/.github/workflows/check-code-samples.sh b/.github/workflows/check-code-samples.sh new file mode 100755 index 00000000..0399e524 --- /dev/null +++ b/.github/workflows/check-code-samples.sh @@ -0,0 +1,65 @@ +cd ./code-samples/ +files=$(ls | wc -l) +echo "Check $files files …" +failedFiles=() +i=0 +for file in *.pony; do # actors-sequential.pony + ((i++)) + percentage=$(((i*100)/files)) + echo -e "#$i Test $file … ($i/$files \u2192 $percentage %)" + contents=$(cat "$file") # code-samples/ + #echo "contents: $contents" + regex='^"""\n(?^(?[a-z_]+):\s?(?.*?)$\n)+"""' # TODO: Get frontmatter from AST + regex='^"""\n(.*)\n"""' + expectations=$(jq --arg file "${file}" ".[\"$file\"]" ../code-samples.json) # -r + #echo "Expectations for $file $expectations" + expectedStdout=$(echo "$expectations" | jq '.stdout') + expectedStderr=$(echo "$expectations" | jq '.stderr') + expectedExitcode=$(echo "$expectations" | jq '.exitcode') + #echo "stdout for $file: " + #echo "$contents" | grep -e $regex + if [ $(echo "$contents" | grep -qe $regex) ]; then # TODO: fix regex + frontmatter="${BASH_REMATCH[0]}" + readarray -d "\n" -t lines <<< frontmatter + echo "Expectations 1: ${lines[0]}" + fi + if [[ "$contents" =~ $regex ]]; then + frontmatter="${BASH_REMATCH[0]}" + readarray -d "\n" -t lines <<< frontmatter + echo "Expectations: ${lines[0]}" + fi + encoded=$(sed -E -e ':a;N;$!ba;s/\r\n|\r|\n/\\n/g' "$file") #code-samples/ + encoded=${encoded//\"/\\\"} + encoded=${encoded// /\\t} + json="{\"code\": \"$encoded\", \"separate_output\": true, \"color\": true, \"branch\": \"release\"}" + #echo "Send $json…" + response=$(curl -s --header "Content-Type: application/json" \ + --request POST \ + --data "$json" \ + "https://playground.ponylang.io/evaluate.json") + success=$(echo "$response" | jq '.success') + actualStdout=$(echo "$response" | jq '.stdout') + actualStderr=$(echo "$response" | jq '.stderr') + if $success && ! [ -z "$expectations" ] && [ "$expectedExitcode" = "0" ] && [ "$actualStdout" = "$expectedStdout" ]; then + echo -e "\u2705 File fulfilled expectations" + elif ! $success && ! [ -z "$expectations" ] && [ "$expectedExitcode" = "1" ] && [ "$actualStderr" = "$expectedStderr" ]; then + echo -e "\u2705 File fulfilled expectations" + else + failedFiles+=(file) + echo -e "\u274C File didn't fulfill expectations" + if [ "$expectedExitcode" = "0" ]; then + echo "Success = true (actual: $success), stdout = $expectedStdout (actual: ${actualStdout-null})" + else + echo "Success = false (actual: $success), stderr = $expectedStderr (actual: ${actualStderr-null})" + fi + echo $response + echo $expectations + echo $expectedExitcode + fi + #break +done +if [ "${#failedFiles[@]}" != 0 ]; then + echo -e "πŸ’₯ ${#failedFiles[@]}/$files file(s) had errors" +else + echo -e "πŸŽ‰ All $files files were checked successfully" +fi \ No newline at end of file diff --git a/.github/workflows/check-code-samples.yml b/.github/workflows/check-code-samples.yml new file mode 100644 index 00000000..4379e40e --- /dev/null +++ b/.github/workflows/check-code-samples.yml @@ -0,0 +1,17 @@ +name: Check code samples + +on: + pull_request: + push: + +jobs: + check-code-samples: + name: Check code samples + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - name: Install jq + run: curl -sS https://webi.sh/jq | bash + - name: Check code samples + run: ./check-code-samples.sh diff --git a/code-samples.json b/code-samples.json new file mode 100644 index 00000000..77f25a9b --- /dev/null +++ b/code-samples.json @@ -0,0 +1,12 @@ +{ + "actors-sequential.pony": { + "stdout": "This is printed first\nThis is printed last\n", + "stderr": null, + "exitcode": 0 + }, + "actors-sequential2.pony": { + "stdout": null, + "stderr": "This is printed first\nThis is printed last\n", + "exitcode": 1 + } +} \ No newline at end of file From 0f7b1350c2fa9ce21239860a241bd3030957f463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Fri, 31 May 2024 00:35:19 +0000 Subject: [PATCH 03/13] Use workspace variable as base path --- .github/workflows/check-code-samples.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-code-samples.sh b/.github/workflows/check-code-samples.sh index 0399e524..e8436ae1 100755 --- a/.github/workflows/check-code-samples.sh +++ b/.github/workflows/check-code-samples.sh @@ -1,4 +1,4 @@ -cd ./code-samples/ +cd "${GITHUB_WORKSPACE}/code-samples/" files=$(ls | wc -l) echo "Check $files files …" failedFiles=() From 74419d7374d788140377bbf1eb7e9ea3e476ae1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Fri, 31 May 2024 00:37:11 +0000 Subject: [PATCH 04/13] Use workspace variable in workflow to run shell script --- .github/workflows/check-code-samples.sh | 2 +- .github/workflows/check-code-samples.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-code-samples.sh b/.github/workflows/check-code-samples.sh index e8436ae1..0399e524 100755 --- a/.github/workflows/check-code-samples.sh +++ b/.github/workflows/check-code-samples.sh @@ -1,4 +1,4 @@ -cd "${GITHUB_WORKSPACE}/code-samples/" +cd ./code-samples/ files=$(ls | wc -l) echo "Check $files files …" failedFiles=() diff --git a/.github/workflows/check-code-samples.yml b/.github/workflows/check-code-samples.yml index 4379e40e..9a1f9a4a 100644 --- a/.github/workflows/check-code-samples.yml +++ b/.github/workflows/check-code-samples.yml @@ -14,4 +14,4 @@ jobs: - name: Install jq run: curl -sS https://webi.sh/jq | bash - name: Check code samples - run: ./check-code-samples.sh + run: ${GITHUB_WORKSPACE}/check-code-samples.sh From 510fb56c0d4c0813788f9d321de012b9691b770e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Fri, 31 May 2024 00:38:40 +0000 Subject: [PATCH 05/13] Add directory path between workspace base path and file name --- .github/workflows/check-code-samples.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-code-samples.yml b/.github/workflows/check-code-samples.yml index 9a1f9a4a..4350fcc3 100644 --- a/.github/workflows/check-code-samples.yml +++ b/.github/workflows/check-code-samples.yml @@ -14,4 +14,4 @@ jobs: - name: Install jq run: curl -sS https://webi.sh/jq | bash - name: Check code samples - run: ${GITHUB_WORKSPACE}/check-code-samples.sh + run: ${GITHUB_WORKSPACE}/.github/workflow/check-code-samples.sh From 81402e939186a68f966d6bd21e84057324ddca32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Fri, 31 May 2024 00:39:33 +0000 Subject: [PATCH 06/13] =?UTF-8?q?Typo=20=F0=9F=A4=A6=F0=9F=8F=BB=E2=80=8D?= =?UTF-8?q?=E2=99=82=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/check-code-samples.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-code-samples.yml b/.github/workflows/check-code-samples.yml index 4350fcc3..7e2959e7 100644 --- a/.github/workflows/check-code-samples.yml +++ b/.github/workflows/check-code-samples.yml @@ -14,4 +14,4 @@ jobs: - name: Install jq run: curl -sS https://webi.sh/jq | bash - name: Check code samples - run: ${GITHUB_WORKSPACE}/.github/workflow/check-code-samples.sh + run: ${GITHUB_WORKSPACE}/.github/workflows/check-code-samples.sh From 9e3f0ed8530476215056bc1003ac7836fb4128a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Fri, 31 May 2024 00:46:52 +0000 Subject: [PATCH 07/13] Set exit codes --- .github/workflows/check-code-samples.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check-code-samples.sh b/.github/workflows/check-code-samples.sh index 0399e524..fe25793b 100755 --- a/.github/workflows/check-code-samples.sh +++ b/.github/workflows/check-code-samples.sh @@ -60,6 +60,8 @@ for file in *.pony; do # actors-sequential.pony done if [ "${#failedFiles[@]}" != 0 ]; then echo -e "πŸ’₯ ${#failedFiles[@]}/$files file(s) had errors" + exit 1 else echo -e "πŸŽ‰ All $files files were checked successfully" + exit 0 fi \ No newline at end of file From eb85a71ab44157137a1589ccd4f23bc7a197e64b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Fri, 31 May 2024 00:55:32 +0000 Subject: [PATCH 08/13] Add colors to echo --- .github/workflows/check-code-samples.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-code-samples.sh b/.github/workflows/check-code-samples.sh index fe25793b..ba0d52fb 100755 --- a/.github/workflows/check-code-samples.sh +++ b/.github/workflows/check-code-samples.sh @@ -41,12 +41,12 @@ for file in *.pony; do # actors-sequential.pony actualStdout=$(echo "$response" | jq '.stdout') actualStderr=$(echo "$response" | jq '.stderr') if $success && ! [ -z "$expectations" ] && [ "$expectedExitcode" = "0" ] && [ "$actualStdout" = "$expectedStdout" ]; then - echo -e "\u2705 File fulfilled expectations" + echo -e "\e[1;32m\u2705 File fulfilled expectations\e[0m" elif ! $success && ! [ -z "$expectations" ] && [ "$expectedExitcode" = "1" ] && [ "$actualStderr" = "$expectedStderr" ]; then - echo -e "\u2705 File fulfilled expectations" + echo -e "\e[1;32m\u2705 File fulfilled expectations\e[0m" else failedFiles+=(file) - echo -e "\u274C File didn't fulfill expectations" + echo -e "\e[1;31m\u274C File didn't fulfill expectations\e[0m" if [ "$expectedExitcode" = "0" ]; then echo "Success = true (actual: $success), stdout = $expectedStdout (actual: ${actualStdout-null})" else @@ -59,9 +59,9 @@ for file in *.pony; do # actors-sequential.pony #break done if [ "${#failedFiles[@]}" != 0 ]; then - echo -e "πŸ’₯ ${#failedFiles[@]}/$files file(s) had errors" + echo -e "\e[1;31mπŸ’₯ ${#failedFiles[@]}/$files file(s) had errors\e[0m" exit 1 else - echo -e "πŸŽ‰ All $files files were checked successfully" + echo -e "\e[1;32mπŸŽ‰ All $files files were checked successfully\e[0m" exit 0 fi \ No newline at end of file From 146ed6423b347530355770ace0efc39b01f9511f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Fri, 31 May 2024 00:58:13 +0000 Subject: [PATCH 09/13] Only check runnable files --- .github/workflows/check-code-samples.sh | 12 ++++++++++-- code-samples.json | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-code-samples.sh b/.github/workflows/check-code-samples.sh index ba0d52fb..819cee9b 100755 --- a/.github/workflows/check-code-samples.sh +++ b/.github/workflows/check-code-samples.sh @@ -2,6 +2,7 @@ cd ./code-samples/ files=$(ls | wc -l) echo "Check $files files …" failedFiles=() +notRunnable=0 i=0 for file in *.pony; do # actors-sequential.pony ((i++)) @@ -13,6 +14,12 @@ for file in *.pony; do # actors-sequential.pony regex='^"""\n(.*)\n"""' expectations=$(jq --arg file "${file}" ".[\"$file\"]" ../code-samples.json) # -r #echo "Expectations for $file $expectations" + isRunnable=$(echo "$expectations" | jq '.runnable') + if ! $isRunnable; then + echo -e "\u2139\uFE0F File not runnable. Skip" + ((notRunnable++)) + break + fi expectedStdout=$(echo "$expectations" | jq '.stdout') expectedStderr=$(echo "$expectations" | jq '.stderr') expectedExitcode=$(echo "$expectations" | jq '.exitcode') @@ -58,10 +65,11 @@ for file in *.pony; do # actors-sequential.pony fi #break done +runnableFiles=$((files-notRunnable)) if [ "${#failedFiles[@]}" != 0 ]; then - echo -e "\e[1;31mπŸ’₯ ${#failedFiles[@]}/$files file(s) had errors\e[0m" + echo -e "\e[1;31mπŸ’₯ ${#failedFiles[@]}/$runnableFiles file(s) had errors\e[0m" exit 1 else - echo -e "\e[1;32mπŸŽ‰ All $files files were checked successfully\e[0m" + echo -e "\e[1;32mπŸŽ‰ All $files files ($runnableFiles runnable) were checked successfully\e[0m" exit 0 fi \ No newline at end of file diff --git a/code-samples.json b/code-samples.json index 77f25a9b..3dd2d19a 100644 --- a/code-samples.json +++ b/code-samples.json @@ -1,12 +1,17 @@ { "actors-sequential.pony": { + "runnable": true, "stdout": "This is printed first\nThis is printed last\n", "stderr": null, "exitcode": 0 }, "actors-sequential2.pony": { + "runnable": true, "stdout": null, "stderr": "This is printed first\nThis is printed last\n", "exitcode": 1 + }, + "actors-behaviors.pony": { + "runnable": false } } \ No newline at end of file From 0970b68694ceb9a743d8cc4eeeccb8188b8f8496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Fri, 31 May 2024 00:59:21 +0000 Subject: [PATCH 10/13] Wrong keyword, yay --- .github/workflows/check-code-samples.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-code-samples.sh b/.github/workflows/check-code-samples.sh index 819cee9b..d4568f92 100755 --- a/.github/workflows/check-code-samples.sh +++ b/.github/workflows/check-code-samples.sh @@ -18,7 +18,7 @@ for file in *.pony; do # actors-sequential.pony if ! $isRunnable; then echo -e "\u2139\uFE0F File not runnable. Skip" ((notRunnable++)) - break + continue fi expectedStdout=$(echo "$expectations" | jq '.stdout') expectedStderr=$(echo "$expectations" | jq '.stderr') From ee216905d8cd69a68861a0c69adfa143a0d71176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Fri, 31 May 2024 01:00:52 +0000 Subject: [PATCH 11/13] Only check if runnable when file has expectations set --- .github/workflows/check-code-samples.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-code-samples.sh b/.github/workflows/check-code-samples.sh index d4568f92..d762f168 100755 --- a/.github/workflows/check-code-samples.sh +++ b/.github/workflows/check-code-samples.sh @@ -15,7 +15,7 @@ for file in *.pony; do # actors-sequential.pony expectations=$(jq --arg file "${file}" ".[\"$file\"]" ../code-samples.json) # -r #echo "Expectations for $file $expectations" isRunnable=$(echo "$expectations" | jq '.runnable') - if ! $isRunnable; then + if ! [ -z "$expectations" ] && ! $isRunnable; then echo -e "\u2139\uFE0F File not runnable. Skip" ((notRunnable++)) continue From bde0999b62cf99bc0239b078f1ff076fe88491e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Fri, 31 May 2024 01:06:24 +0000 Subject: [PATCH 12/13] Tweak expectations to have diverse results --- code-samples.json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/code-samples.json b/code-samples.json index 3dd2d19a..80c1b022 100644 --- a/code-samples.json +++ b/code-samples.json @@ -5,13 +5,19 @@ "stderr": null, "exitcode": 0 }, - "actors-sequential2.pony": { + "traits-and-interfaces-private-methods.pony": { "runnable": true, "stdout": null, - "stderr": "This is printed first\nThis is printed last\n", + "stderr": "interfaces can't have private methods, only traits can\n", "exitcode": 1 }, "actors-behaviors.pony": { "runnable": false + }, + "appendices-examples-access-command-line-arguments.pony": { + "runnable": true, + "stdout": "This is printed first\nThis is printed last\n", + "stderr": null, + "exitcode": 0 } } \ No newline at end of file From 0eff5c92172526db8642829246c741ef3a99bd5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=A4drich?= <11225821+shaedrich@users.noreply.github.com> Date: Fri, 31 May 2024 01:10:09 +0000 Subject: [PATCH 13/13] Make output consistent (more or less) --- .github/workflows/check-code-samples.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-code-samples.sh b/.github/workflows/check-code-samples.sh index d762f168..2dd6d771 100755 --- a/.github/workflows/check-code-samples.sh +++ b/.github/workflows/check-code-samples.sh @@ -67,7 +67,7 @@ for file in *.pony; do # actors-sequential.pony done runnableFiles=$((files-notRunnable)) if [ "${#failedFiles[@]}" != 0 ]; then - echo -e "\e[1;31mπŸ’₯ ${#failedFiles[@]}/$runnableFiles file(s) had errors\e[0m" + echo -e "\e[1;31mπŸ’₯ ${#failedFiles[@]}/$runnableFiles file(s) ($files total) had errors\e[0m" exit 1 else echo -e "\e[1;32mπŸŽ‰ All $files files ($runnableFiles runnable) were checked successfully\e[0m"