From 27f038ba9f66c48ce7a028bee223db5ac7d30b81 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Sun, 1 Oct 2023 19:37:11 -0700 Subject: [PATCH 01/23] ruby: start track for october challenge --- README.md | 1 + ruby/README.md | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 ruby/README.md diff --git a/README.md b/README.md index f4a45920..9aad5b63 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,7 @@ Exercism Workspace - [Common Lisp](common-lisp/README.md) - [C](c/README.md) - [C++](cpp/README.md) +- [Ruby](ruby/README.md) ## Tools/Scripts diff --git a/ruby/README.md b/ruby/README.md new file mode 100644 index 00000000..bba1e311 --- /dev/null +++ b/ruby/README.md @@ -0,0 +1,10 @@ +# Exercism Ruby Track + +[Home Page](https://exercism.org/tracks/ruby) + +[My Profile](https://exercism.org/profiles/vpayno) + +## Tools + +## [Exercises](https://exercism.org/tracks/ruby/exercises) + From be775626183f274da70b6c7eac56f44d163aefd9 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Sun, 1 Oct 2023 19:38:19 -0700 Subject: [PATCH 02/23] ruby(tools): add for_each script --- ruby/README.md | 2 ++ ruby/for_each | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100755 ruby/for_each diff --git a/ruby/README.md b/ruby/README.md index bba1e311..dfdbd800 100644 --- a/ruby/README.md +++ b/ruby/README.md @@ -6,5 +6,7 @@ ## Tools +- [for_each](./for_each) + ## [Exercises](https://exercism.org/tracks/ruby/exercises) diff --git a/ruby/for_each b/ruby/for_each new file mode 100755 index 00000000..717b1149 --- /dev/null +++ b/ruby/for_each @@ -0,0 +1,24 @@ +#!/bin/bash + +declare -i retval=0 +declare pkg_name +declare d + +time for d in ./*; do + [[ -d ${d} ]] || continue + cd "${d}" || continue + printf "[dir: %s]\n\n" "${PWD}" + + pkg_name="$(basename "${PWD}")" + + printf "[pkg: %s]\n\n" "${pkg_name}" + + echo "${@}" + time "${@}" || ((retval++)) + + printf "\n" + + cd - || break +done + +exit "${retval}" From 954d1c892651413930e4d27593d89355e71faab5 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Sun, 1 Oct 2023 19:51:50 -0700 Subject: [PATCH 03/23] ruby(tools): add submit_files script --- ruby/README.md | 1 + ruby/submit_files | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100755 ruby/submit_files diff --git a/ruby/README.md b/ruby/README.md index dfdbd800..543436c8 100644 --- a/ruby/README.md +++ b/ruby/README.md @@ -7,6 +7,7 @@ ## Tools - [for_each](./for_each) +- [submit_files](./submit_files) ## [Exercises](https://exercism.org/tracks/ruby/exercises) diff --git a/ruby/submit_files b/ruby/submit_files new file mode 100755 index 00000000..e8e6213f --- /dev/null +++ b/ruby/submit_files @@ -0,0 +1,38 @@ +#!/bin/bash + +if [[ ! -d .exercism ]]; then + printf "ERROR: Run from inside a project directory.\n\n" + exit 1 +fi + +# declare package_name_snake + +get_track_package_name() { + # these are kebab-case + basename "${PWD}" +} # get_track_package_name() + +kebab_case_to_pascal_case() { + printf "%s" "${@}" | sed -r -e 's/(^|[-])(\w)/\U\2/g' +} # kebab_case_to_pascal_case() + +kebab_case_to_camel_case() { + printf "%s" "${@}" | sed -r -e 's/([-])(\w)/\U\2/g' +} # kebab_case_to_camel_case() + +kebab_case_to_snake_case() { + printf "%s" "${@}" | sed -r -e 's/(\w)([-])(\w)/\1_\3/g' +} # kebab_case_to_snake_case() + +package_name_snake="$(kebab_case_to_snake_case "$(get_track_package_name)")" + +declare -a RUBY_FILES=("./${package_name_snake}.rb" ./run-tests-ruby.txt) + +# mapfile -t RUBY_FILES < <( +# find . -type f -name "*[.]go" | grep -v "_test[.]go" +# find . -type f -name "*_examples_test[.]go" +#) + +echo Running: exercism submit "${RUBY_FILES[@]}" +time exercism submit "${RUBY_FILES[@]}" +printf "\n" From 587ebdd505601011b07cdc4c40069ee929b1fe80 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Sun, 1 Oct 2023 20:12:28 -0700 Subject: [PATCH 04/23] ruby(tools): add update_readmes script --- ruby/README.md | 1 + ruby/update_readmes | 50 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100755 ruby/update_readmes diff --git a/ruby/README.md b/ruby/README.md index 543436c8..693c8c5b 100644 --- a/ruby/README.md +++ b/ruby/README.md @@ -8,6 +8,7 @@ - [for_each](./for_each) - [submit_files](./submit_files) +- [update_readmes](./update_readmes) ## [Exercises](https://exercism.org/tracks/ruby/exercises) diff --git a/ruby/update_readmes b/ruby/update_readmes new file mode 100755 index 00000000..311966de --- /dev/null +++ b/ruby/update_readmes @@ -0,0 +1,50 @@ +#!/bin/bash + +shopt -s nullglob + +if [[ ! -d .exercism ]]; then + printf "ERROR: Run from inside a project directory.\n\n" + exit 1 +fi + +declare package_name +declare project_dir + +get_track_package_name() { + basename "${PWD}" +} # get_track_package_name() + +package_name="$(get_track_package_name)" +project_dir="$(basename "${PWD}")" + +if ! grep -q ./"${project_dir}"/README.md ../README.md; then + + cat >>../README.md <>./README.md < Date: Mon, 2 Oct 2023 23:11:32 -0700 Subject: [PATCH 05/23] ruby(ci): add wrapper scripts --- .github/citools/includes/wrapper-library | 29 ++++++++++++ .github/citools/ruby/ruby-lint-rubycritic | 28 ++++++++++++ .github/citools/ruby/ruby-setup-config | 24 ++++++++++ .github/citools/ruby/ruby-setup-install | 37 +++++++++++++++ .github/citools/ruby/ruby-setup-verify | 48 ++++++++++++++++++++ .github/citools/ruby/ruby-test-with-coverage | 34 ++++++++++++++ 6 files changed, 200 insertions(+) create mode 100755 .github/citools/ruby/ruby-lint-rubycritic create mode 100755 .github/citools/ruby/ruby-setup-config create mode 100755 .github/citools/ruby/ruby-setup-install create mode 100755 .github/citools/ruby/ruby-setup-verify create mode 100755 .github/citools/ruby/ruby-test-with-coverage diff --git a/.github/citools/includes/wrapper-library b/.github/citools/includes/wrapper-library index c16f8ca3..ecf1447e 100644 --- a/.github/citools/includes/wrapper-library +++ b/.github/citools/includes/wrapper-library @@ -115,3 +115,32 @@ show_tool_versions_go() { # md_code_tag printf "\n" } # show_tool_versions_go() + +show_tool_versions_ruby_short() { + # md_code_tag text + printf "Ruby version:\n" + printf "\n" + ruby --version | paste /dev/null - + # md_code_tag + printf "\n" +} # show_tool_versions_ruby_short() + +show_tool_versions_ruby() { + # md_code_tag text + printf "Ruby version:\n" + printf "\n" + ruby --version | paste /dev/null - + # md_code_tag + printf "\n" + + if [[ -z ${GITHUB_ACTIONS} ]]; then + return + fi + + # md_code_tag text + printf "Installed Gem packages:\n" + printf "\n" + gem list | paste /dev/null - + # md_code_tag + printf "\n" +} # show_tool_versions_ruby() diff --git a/.github/citools/ruby/ruby-lint-rubycritic b/.github/citools/ruby/ruby-lint-rubycritic new file mode 100755 index 00000000..0c56607e --- /dev/null +++ b/.github/citools/ruby/ruby-lint-rubycritic @@ -0,0 +1,28 @@ +#!/bin/bash +# +# .github/citools/ruby/ruby-lint-rubycritic +# + +# shellcheck disable=SC1091 +source ../../.github/citools/includes/wrapper-library || exit + +declare -i retval=0 + +main() { + printf "\nRunning RubyCritic\n\n" + + show_tool_versions_ruby + + print_ruler + + # https://github.com/whitesmith/rubycritic + + run_command rubycritic --path .rubycritic --format console --no-browser . || ((retval++)) + + print_ruler + + echo Exit code: "${retval}" + return "${retval}" +} + +time main "${@}" diff --git a/.github/citools/ruby/ruby-setup-config b/.github/citools/ruby/ruby-setup-config new file mode 100755 index 00000000..e6bc45fa --- /dev/null +++ b/.github/citools/ruby/ruby-setup-config @@ -0,0 +1,24 @@ +#!/bin/bash +# +# .github/citools/ruby/ruby-setup-config +# + +# shellcheck disable=SC1091 +source ../../.github/citools/includes/wrapper-library || exit + +declare -i retval=0 + +main() { + printf "Setup Ruby Environment\n\n" + + print_ruler + + # printf "%s\n" "/root/.rustup/toolchains/stable-$(arch)-unknown-linux-gnu/bin" "/root/.cargo/bin" | tee -a "${GITHUB_PATH}" + + print_ruler + + echo Exit code: "${retval}" + return "${retval}" +} + +time main "${@}" diff --git a/.github/citools/ruby/ruby-setup-install b/.github/citools/ruby/ruby-setup-install new file mode 100755 index 00000000..47f45a6e --- /dev/null +++ b/.github/citools/ruby/ruby-setup-install @@ -0,0 +1,37 @@ +#!/bin/bash +# +# .github/citools/ruby/ruby-setup-install +# + +# shellcheck disable=SC1091 +source ../../.github/citools/includes/wrapper-library || exit + +declare -i retval=0 + +main() { + printf "Ruby Installation\n\n" + + print_ruler + + echo Running: sudo apt install ruby-full + time sudo apt install -y ruby-full || ((retval++)) + + print_ruler + + local -a gems + gems=( + rubycritic + simplecov + simplecov-cobertura + ) + + echo Running: gem install "${gems[@]}" + time gem install "${gems[@]}" || ((retval++)) + + print_ruler + + echo Exit code: "${retval}" + return "${retval}" +} + +time main "${@}" diff --git a/.github/citools/ruby/ruby-setup-verify b/.github/citools/ruby/ruby-setup-verify new file mode 100755 index 00000000..9a74e504 --- /dev/null +++ b/.github/citools/ruby/ruby-setup-verify @@ -0,0 +1,48 @@ +#!/bin/bash +# +# .github/citools/ruby/ruby-setup-verify +# + +# shellcheck disable=SC1091 +source ../../.github/citools/includes/wrapper-library || exit + +declare -i retval=0 + +declare -A ruby_cmds + +ruby_cmds=( + [ruby]=$( + command -v ruby >&/dev/null + echo "$?" + ) + [rubycritic]=$( + command -v rubycritic >&/dev/null + echo "$?" + ) +) + +main() { + for key in "${!ruby_cmds[@]}"; do + if [[ ${ruby_cmds[${key}]} -ne 0 ]]; then + printf "ERROR: command [%s] not found.\n" "${key}" + ((retval++)) + fi + done + + if [[ ${retval} -ne 0 ]]; then + return "${retval}" + fi + + printf "Verifying Ruby Installation\n\n" + + print_ruler + + show_tool_versions_ruby + + print_ruler + + echo Exit code: "${retval}" + return "${retval}" +} + +time main "${@}" diff --git a/.github/citools/ruby/ruby-test-with-coverage b/.github/citools/ruby/ruby-test-with-coverage new file mode 100755 index 00000000..da3ef674 --- /dev/null +++ b/.github/citools/ruby/ruby-test-with-coverage @@ -0,0 +1,34 @@ +#!/bin/bash +# +# .github/citools/ruby/ruby-test-with-coverage +# + +# shellcheck disable=SC1091 +source ../../.github/citools/includes/wrapper-library || exit + +declare -i retval=0 + +main() { + printf "\nRunning Ruby Tests With Coverage\n\n" + + show_tool_versions_ruby + + print_ruler + + run_command rm -rf ./coverage + + print_ruler + + # https://github.com/simplecov-ruby/simplecov + # https://github.com/dashingrocket/simplecov-cobertura + # https://about.codecov.io/blog/getting-started-with-code-coverage-for-ruby/ + + run_command ruby ./*_test.rb -v || ((retval++)) + + print_ruler + + echo Exit code: "${retval}" + return "${retval}" +} + +time main "${@}" From 8c0dcef73bf46664fdef74a19a620b40aae678e7 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Sun, 1 Oct 2023 20:13:53 -0700 Subject: [PATCH 06/23] ruby(ci): add initial workflow --- .github/workflows/ruby.yml | 203 +++++++++++++++++++++++++++++++++++++ README.md | 2 + 2 files changed, 205 insertions(+) create mode 100644 .github/workflows/ruby.yml diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml new file mode 100644 index 00000000..2bd39db6 --- /dev/null +++ b/.github/workflows/ruby.yml @@ -0,0 +1,203 @@ +--- +# +# .github/workflows/ruby.yml +# +name: Ruby Workflow 4.0 +on: # yamllint disable-line rule:truthy + pull_request: + workflow_dispatch: + +defaults: + run: + shell: bash + +jobs: + stage1: + name: Change Check + runs-on: 'ubuntu-latest' + outputs: + docs_changed: ${{ steps.check_file_changed.outputs.docs_changed }} + matrix_exercise: ${{ steps.check_file_changed.outputs.matrix_exercise }} + exercise_count: ${{ steps.check_file_changed.outputs.exercise_count }} + steps: + - name: Check GitHub Vars + id: github-vars + run: set | grep -e ^CI -e ^GITHUB_ -e ^RUNNER_ + - name: Checkout Repo + id: checkout-repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: ${{ github.ref }} + submodules: recursive + - name: Get Change List + id: check_file_changed + run: |- + { + printf "Workflow: %s\n\n" "${GITHUB_WORKFLOW}" + printf "Runner: name[%s] arch[%s]\n" "${RUNNER_NAME}" "${RUNNER_ARCH}" + printf "Repo: %s\n" "${GITHUB_REPOSITORY}" + printf "User: %s\n" "${GITHUB_TRIGGERING_ACTOR}" + printf "\n" + } | tee -a "${GITHUB_STEP_SUMMARY}" + + # get user info for default gh container + { + printf "\`\`\`text\n" + printf "Container user info:\n" + who + printf "\n" + id + printf "\`\`\`\n" + } | tee -a "${GITHUB_STEP_SUMMARY}" + printf "\n" + + # Diff HEAD with the previous commit then output to stdout. + GIT_DIFF="$(git diff --name-only HEAD^ HEAD | tee /tmp/changed_files.txt)" + { + printf "=== Which files changed? ===\n" + printf "\`\`\`text\n" + printf "%s\n" "${GIT_DIFF}" + printf "\`\`\`\n" + } | tee -a "${GITHUB_STEP_SUMMARY}" + HAS_WF_DIFF=false + HAS_EX_DIFF=false + if printf "%s\n" "${GIT_DIFF}" | grep -E '^(.github/workflows/ruby.yml|.github/citools/ruby/)$'; then + HAS_WF_DIFF=true + fi + if printf "%s\n" "${GIT_DIFF}" | grep -E '^ruby/.*[.]rb$'; then + HAS_EX_DIFF=true + fi + printf "\n" + printf "=== Did WF/CI change without exercise changes? ===\n" + CI_FORCE_FULL=false + if ${HAS_WF_DIFF} && ! ${HAS_EX_DIFF}; then + CI_FORCE_FULL=true + printf "%s\n" "${CI_FORCE_FULL}" + fi + printf "\n" + + # Get changed exercise list. + if [[ ${GITHUB_EVENT_NAME} == pull_request ]] && ! ${CI_FORCE_FULL}; then + printf "Generating pull request changed exercise list.\n" + grep -E '^ruby/[-a-z0-9]+./.*$' /tmp/changed_files.txt | cut -f1,2 -d/ | sort -Vu | tee /tmp/exercises.txt || true + else + printf "Generating complete exercise list.\n" + find ./ruby/ -type d -print | grep -v -E '^[.]/ruby/(|[.].*)$' | sed -r -e 's:[.]/(ruby/[-a-z0-9]+)/?.*$:\1:g' | sort -Vu | tee /tmp/exercises.txt + HAS_DIFF=true + fi + printf "\n" + + # Check if the files are present in the changed file list (added, modified, deleted) then output to stdout. + HAS_DIFF="${HAS_DIFF:-false}" + printf "=== Which Ruby files changed? ===\n" + if printf "%s\n" "${GIT_DIFF}" | grep -E '^(ruby/.*[.]rb|.github/workflows/ruby.yml|.github/citools/ruby/)$'; then + HAS_DIFF=true + printf "%s\n" "${HAS_DIFF}" + fi + printf "\n" + + # Did Ruby files change? + printf "=== Did Ruby files change? ===\n" + printf "%s\n" "${HAS_DIFF}" + printf "\n" + + # Generate exercise job matrix from changed files list. + printf "=== Generating matrix exercise list. ===\n" + declare -i last=0 + declare -i count=0 + last=$(wc -l /tmp/exercises.txt | cut -f1 -d\ ) + ((last -= 1)) || true + entries="" + while read -r line; do + if [[ ! ${count} -lt ${last} ]]; then + comma="" + else + comma="," + fi + printf -v entry "\"%s\"%s\n" "${line}" "${comma}" + ((count += 1)) + entries+="${entry}" + done < <(sort -V /tmp/exercises.txt) + jq --sort-keys . >/tmp/exercises.json <> "${GITHUB_OUTPUT}" + check-matrix: + runs-on: ubuntu-latest + needs: stage1 + steps: + - name: Install json2yaml + run: sudo npm install -g json2yaml + - name: Check matrix::exercises + run: |- + exercise_count='${{ needs.stage1.outputs.exercise_count }}' + matrix_exercise='${{ needs.stage1.outputs.matrix_exercise }}' + { + printf "\`\`\`text\n" + printf "exercise_count=%s\n" "${exercise_count}" + printf "matrix_exercise=%s\n" "${matrix_exercise}" + printf "\`\`\`\n" + printf "json:\n" + printf "\`\`\`text\n" + printf "%s" "${matrix_exercise}" | jq . + printf "\`\`\`\n" + } | tee -a "${GITHUB_STEP_SUMMARY}" + { + printf "yaml:\n" + printf "\`\`\`text\n" + printf "{ \"matrix\": { \"exercise\": %s } }" "${matrix_exercise}" | json2yaml + printf "\`\`\`\n" + } | tee -a "${GITHUB_STEP_SUMMARY}" + stage2: + name: Ruby Checks + strategy: + matrix: + os: ["ubuntu-latest", "windows-latest", "macos-latest"] + exclude: + - os: "macos-latest" + - os: "windows-latest" + exercise: ${{fromJson(needs.stage1.outputs.matrix_exercise)}} + runs-on: "${{ matrix.os }}" + container: + image: vpayno/ci-generic-debian:latest + needs: [stage1] + if: needs.stage1.outputs.docs_changed == 'true' + steps: + - name: Checkout Repo [${{ matrix.exercise }}] + id: checkout-repo + uses: actions/checkout@v3 + - name: Config Ruby Tools [${{ matrix.exercise }}] + id: config-ruby-tools + run: |- + ./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/ruby/ruby-setup-config + - name: Install Ruby Tools [${{ matrix.exercise }}] + id: install-ruby-tools + run: |- + ./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/ruby/ruby-setup-install + - name: Show Ruby version [${{ matrix.exercise }}] + id: ruby-version + run: |- + ./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/ruby/ruby-setup-verify + - name: Analysing the code with cargo check [${{ matrix.exercise }}] + id: cargo-check + run: |- + ./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/ruby/ruby-lint-rubycritic + - name: Testing with cargo test coverage [${{ matrix.exercise }}] + id: cargo-test-coverage + run: |- + ./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/ruby/ruby-test-with-coverage diff --git a/README.md b/README.md index 9aad5b63..85e8be8b 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ Exercism Workspace [![Common Lisp Workflow](https://github.com/vpayno/exercism-workspace/actions/workflows/common-lisp.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/common-lisp.yml) [![C Workflow](https://github.com/vpayno/exercism-workspace/actions/workflows/c.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/c.yml) [![CPP Workflow](https://github.com/vpayno/exercism-workspace/actions/workflows/cpp.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/cpp.yml) +[![Ruby Workflow](https://github.com/vpayno/exercism-workspace/actions/workflows/ruby.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/ruby.yml) [![Git PR Checks](https://github.com/vpayno/exercism-workspace/actions/workflows/git-pr.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/git-pr.yml) [![Check Links](https://github.com/vpayno/exercism-workspace/actions/workflows/links.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/links.yml) @@ -128,6 +129,7 @@ Exercism Workspace - [Common Lisp Workflow](.github/workflows/common-lisp.yml) - [C Workflow](.github/workflows/c.yml) - [C++ Workflow](.github/workflows/cpp.yml) +- [Ruby Workflow](.github/workflows/ruby.yml) - [Link Checker Workflow](.github/workflows/links.yml) - [CodeQL Workflow](.github/workflows/codeql-analysis.yml) - [Woke PR](.github/workflows/woke-pr.yml) From de3cc015ff8eefe61a88dcfe319db4f71ef3d010 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Sun, 1 Oct 2023 20:15:03 -0700 Subject: [PATCH 07/23] ruby(tools): add run-tests script --- README.md | 1 + ruby/README.md | 1 + ruby/run-tests | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100755 ruby/run-tests diff --git a/README.md b/README.md index 85e8be8b..d898e100 100644 --- a/README.md +++ b/README.md @@ -169,3 +169,4 @@ Exercism Workspace - [Common Lisp run-tests](./common-lisp/run-tests) - [C run-tests](./c/run-tests) - [C++ run-tests](./cpp/run-tests) +- [Ruby run-tests](./ruby/run-tests) diff --git a/ruby/README.md b/ruby/README.md index 693c8c5b..0d243b64 100644 --- a/ruby/README.md +++ b/ruby/README.md @@ -7,6 +7,7 @@ ## Tools - [for_each](./for_each) +- [run-tests](./run-tests) - [submit_files](./submit_files) - [update_readmes](./update_readmes) diff --git a/ruby/run-tests b/ruby/run-tests new file mode 100755 index 00000000..859b95c0 --- /dev/null +++ b/ruby/run-tests @@ -0,0 +1,39 @@ +#!/bin/bash + +print_ruler() { + printf "\n" + printf "=%.0s" {1..79} + printf "\n" + printf "\n" +} # print_ruler() + +main() { + printf "Running automated test file(s):\n\n" + + print_ruler + + echo Running: ../../.github/citools/ruby/ruby-lint-rubycritic + time ../../.github/citools/ruby/ruby-lint-rubycritic + + print_ruler + + echo Running: ../../.github/citools/ruby/ruby-test-with-coverage + time ../../.github/citools/ruby/ruby-test-with-coverage + + print_ruler + + # go install github.com/client9/misspell/cmd/misspell@latest + # still looking for a working version for ruby + + echo Running: misspell . + time misspell . + + print_ruler + + cd .. + pwd + + print_ruler +} # main() + +time main "$@" |& tee ./run-tests-ruby.txt From 038573c2d315159480e84dbe1c03d9e4513232bb Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Mon, 2 Oct 2023 23:07:59 -0700 Subject: [PATCH 08/23] ruby(tools): add code coverage test edit to update_readmes script --- ruby/update_readmes | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ruby/update_readmes b/ruby/update_readmes index 311966de..2137498f 100755 --- a/ruby/update_readmes +++ b/ruby/update_readmes @@ -48,3 +48,31 @@ sed -r -i -e 's/^(\s+)(skip)\b.*$/\1# \2/g' ./*_test.rb git add ./*_test.rb git diff --cached ./*_test.rb printf "\n" + +for f in ./*_test.rb; do + if ! grep -q simplecov "${f}"; then + { cat | sponge "${f}"; } <<-EOF + # frozen_string_literal: false + + # https://github.com/simplecov-ruby/simplecov + require 'simplecov' + + # line coverage + SimpleCov.start if ENV['COVERAGE'] != 'branch' + + # branch coverage + if ENV['COVERAGE'] == 'branch' + SimpleCov.start do + enable_coverage :branch + primary_coverage :branch + end + end + + # name the test file/group + SimpleCov.command_name 'test:exercism' + + # original exercism tests + $(cat "${f}") + EOF + fi +done From 31c996c615fa7e57631919e37f77c10520149aae Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Sun, 1 Oct 2023 19:33:06 -0700 Subject: [PATCH 09/23] ruby/hello-world: download exercise --- ruby/hello-world/.exercism/config.json | 39 +++++++++++++++++ ruby/hello-world/.exercism/metadata.json | 1 + ruby/hello-world/HELP.md | 54 ++++++++++++++++++++++++ ruby/hello-world/README.md | 52 +++++++++++++++++++++++ ruby/hello-world/hello_world.rb | 5 +++ ruby/hello-world/hello_world_test.rb | 9 ++++ 6 files changed, 160 insertions(+) create mode 100644 ruby/hello-world/.exercism/config.json create mode 100644 ruby/hello-world/.exercism/metadata.json create mode 100644 ruby/hello-world/HELP.md create mode 100644 ruby/hello-world/README.md create mode 100644 ruby/hello-world/hello_world.rb create mode 100644 ruby/hello-world/hello_world_test.rb diff --git a/ruby/hello-world/.exercism/config.json b/ruby/hello-world/.exercism/config.json new file mode 100644 index 00000000..f38024e0 --- /dev/null +++ b/ruby/hello-world/.exercism/config.json @@ -0,0 +1,39 @@ +{ + "authors": [ + "ramonh" + ], + "contributors": [ + "abartov", + "bgrabow", + "budmc29", + "gilmatic", + "hilary", + "iHiD", + "Insti", + "jpotts244", + "Kosmas", + "kotp", + "kytrinyx", + "mike-hewitson", + "NeimadTL", + "sivabudh", + "skeskali", + "thejoycekung", + "trayo", + "tryantwit" + ], + "files": { + "solution": [ + "hello_world.rb" + ], + "test": [ + "hello_world_test.rb" + ], + "example": [ + ".meta/example.rb" + ] + }, + "blurb": "The classical introductory exercise. Just say \"Hello, World!\".", + "source": "This is an exercise to introduce users to using Exercism", + "source_url": "https://en.wikipedia.org/wiki/%22Hello,_world!%22_program" +} diff --git a/ruby/hello-world/.exercism/metadata.json b/ruby/hello-world/.exercism/metadata.json new file mode 100644 index 00000000..89b03e35 --- /dev/null +++ b/ruby/hello-world/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"ruby","exercise":"hello-world","id":"b1dd6717fcb54524b591175ff6a60ade","url":"https://exercism.org/tracks/ruby/exercises/hello-world","handle":"vpayno","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/ruby/hello-world/HELP.md b/ruby/hello-world/HELP.md new file mode 100644 index 00000000..4388e216 --- /dev/null +++ b/ruby/hello-world/HELP.md @@ -0,0 +1,54 @@ +# Help + +## Running the tests + +For running the tests provided, you will need the Minitest gem. Open a +terminal window and run the following command to install minitest: + +``` +gem install minitest +``` + + +Run the tests from the exercise directory using the following command: + +``` +ruby _test.rb +``` + +Please replace `` with your exercise name in snake_case. + +## Color output + +You can `require 'minitest/pride'` or run the following command to get colored output: + +``` +ruby -r minitest/pride _test.rb +``` + +## Submitting your solution + +You can submit your solution using the `exercism submit hello_world.rb` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Ruby track's documentation](https://exercism.org/docs/tracks/ruby) +- The [Ruby track's programming category on the forum](https://forum.exercism.org/c/programming/ruby) +- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Ruby Documentation](http://ruby-doc.org/) +- [StackOverflow](http://stackoverflow.com/questions/tagged/ruby) +- [/r/ruby](https://www.reddit.com/r/ruby) is the Ruby subreddit. \ No newline at end of file diff --git a/ruby/hello-world/README.md b/ruby/hello-world/README.md new file mode 100644 index 00000000..bad3b73f --- /dev/null +++ b/ruby/hello-world/README.md @@ -0,0 +1,52 @@ +# Hello World + +Welcome to Hello World on Exercism's Ruby Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +The classical introductory exercise. +Just say "Hello, World!". + +["Hello, World!"][hello-world] is the traditional first program for beginning programming in a new language or environment. + +The objectives are simple: + +- Modify the provided code so that it produces the string "Hello, World!". +- Run the test suite and make sure that it succeeds. +- Submit your solution and check it at the website. + +If everything goes well, you will be ready to fetch your first real exercise. + +[hello-world]: https://en.wikipedia.org/wiki/%22Hello,_world!%22_program + +## Source + +### Created by + +- @ramonh + +### Contributed to by + +- @abartov +- @bgrabow +- @budmc29 +- @gilmatic +- @hilary +- @iHiD +- @Insti +- @jpotts244 +- @Kosmas +- @kotp +- @kytrinyx +- @mike-hewitson +- @NeimadTL +- @sivabudh +- @skeskali +- @thejoycekung +- @trayo +- @tryantwit + +### Based on + +This is an exercise to introduce users to using Exercism - https://en.wikipedia.org/wiki/%22Hello,_world!%22_program \ No newline at end of file diff --git a/ruby/hello-world/hello_world.rb b/ruby/hello-world/hello_world.rb new file mode 100644 index 00000000..4298d604 --- /dev/null +++ b/ruby/hello-world/hello_world.rb @@ -0,0 +1,5 @@ +class HelloWorld + def self.hello + "Goodbye, Mars!" + end +end diff --git a/ruby/hello-world/hello_world_test.rb b/ruby/hello-world/hello_world_test.rb new file mode 100644 index 00000000..a16c3d01 --- /dev/null +++ b/ruby/hello-world/hello_world_test.rb @@ -0,0 +1,9 @@ +require 'minitest/autorun' +require_relative 'hello_world' + +class HelloWorldTest < Minitest::Test + def test_say_hi + # skip + assert_equal "Hello, World!", HelloWorld.hello + end +end From b4d9e79e1fdaa971ded5b623c90db8ffac1deb91 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Mon, 2 Oct 2023 08:38:08 -0700 Subject: [PATCH 10/23] ruby/hello-world: 1st iteration --- ruby/README.md | 1 + ruby/hello-world/.rubycritic/lint.txt | 3 + ruby/hello-world/README.md | 7 +- ruby/hello-world/coverage/.last_run.json | 5 + ruby/hello-world/coverage/.resultset.json | 16 ++ .../hello-world/coverage/.resultset.json.lock | 0 ruby/hello-world/coverage/coverage.xml | 22 +++ ruby/hello-world/hello_world.rb | 2 +- ruby/hello-world/hello_world_test.rb | 24 +++ ruby/hello-world/run-tests-ruby.txt | 137 ++++++++++++++++++ 10 files changed, 215 insertions(+), 2 deletions(-) create mode 100644 ruby/hello-world/.rubycritic/lint.txt create mode 100644 ruby/hello-world/coverage/.last_run.json create mode 100644 ruby/hello-world/coverage/.resultset.json create mode 100644 ruby/hello-world/coverage/.resultset.json.lock create mode 100644 ruby/hello-world/coverage/coverage.xml create mode 100644 ruby/hello-world/run-tests-ruby.txt diff --git a/ruby/README.md b/ruby/README.md index 0d243b64..3efcdf78 100644 --- a/ruby/README.md +++ b/ruby/README.md @@ -13,3 +13,4 @@ ## [Exercises](https://exercism.org/tracks/ruby/exercises) +- [hello-world](./hello-world/README.md) diff --git a/ruby/hello-world/.rubycritic/lint.txt b/ruby/hello-world/.rubycritic/lint.txt new file mode 100644 index 00000000..3966a05e --- /dev/null +++ b/ruby/hello-world/.rubycritic/lint.txt @@ -0,0 +1,3 @@ +hello_world.rb:1: (IrresponsibleModule) HelloWorld has no descriptive comment + +hello_world_test.rb:28: (IrresponsibleModule) HelloWorldTest has no descriptive comment diff --git a/ruby/hello-world/README.md b/ruby/hello-world/README.md index bad3b73f..3f7fdf4c 100644 --- a/ruby/hello-world/README.md +++ b/ruby/hello-world/README.md @@ -49,4 +49,9 @@ If everything goes well, you will be ready to fetch your first real exercise. ### Based on -This is an exercise to introduce users to using Exercism - https://en.wikipedia.org/wiki/%22Hello,_world!%22_program \ No newline at end of file +This is an exercise to introduce users to using Exercism - https://en.wikipedia.org/wiki/%22Hello,_world!%22_program + +### My Solution + +- [my solution](./hello_world.rb) +- [run-tests](./run-tests-ruby.txt) diff --git a/ruby/hello-world/coverage/.last_run.json b/ruby/hello-world/coverage/.last_run.json new file mode 100644 index 00000000..52d2bf29 --- /dev/null +++ b/ruby/hello-world/coverage/.last_run.json @@ -0,0 +1,5 @@ +{ + "result": { + "line": 100.0 + } +} diff --git a/ruby/hello-world/coverage/.resultset.json b/ruby/hello-world/coverage/.resultset.json new file mode 100644 index 00000000..5e765975 --- /dev/null +++ b/ruby/hello-world/coverage/.resultset.json @@ -0,0 +1,16 @@ +{ + "test:exercism": { + "coverage": { + "/home/vpayno/git_vpayno/exercism-workspace/ruby/hello-world/hello_world.rb": { + "lines": [ + 1, + 1, + 1, + null, + null + ] + } + }, + "timestamp": 1696313634 + } +} diff --git a/ruby/hello-world/coverage/.resultset.json.lock b/ruby/hello-world/coverage/.resultset.json.lock new file mode 100644 index 00000000..e69de29b diff --git a/ruby/hello-world/coverage/coverage.xml b/ruby/hello-world/coverage/coverage.xml new file mode 100644 index 00000000..c15d48be --- /dev/null +++ b/ruby/hello-world/coverage/coverage.xml @@ -0,0 +1,22 @@ + + + + + + /home/vpayno/git_vpayno/exercism-workspace/ruby/hello-world + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ruby/hello-world/hello_world.rb b/ruby/hello-world/hello_world.rb index 4298d604..a89cc196 100644 --- a/ruby/hello-world/hello_world.rb +++ b/ruby/hello-world/hello_world.rb @@ -1,5 +1,5 @@ class HelloWorld def self.hello - "Goodbye, Mars!" + "Hello, World!" end end diff --git a/ruby/hello-world/hello_world_test.rb b/ruby/hello-world/hello_world_test.rb index a16c3d01..4fdccd44 100644 --- a/ruby/hello-world/hello_world_test.rb +++ b/ruby/hello-world/hello_world_test.rb @@ -1,3 +1,27 @@ +# frozen_string_literal: false + +# https://github.com/simplecov-ruby/simplecov +require 'simplecov' + +# https://about.codecov.io/blog/getting-started-with-code-coverage-for-ruby/ +require 'simplecov-cobertura' +SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter + +# line coverage +SimpleCov.start if ENV['COVERAGE'] != 'branch' + +# branch coverage +if ENV['COVERAGE'] == 'branch' + SimpleCov.start do + enable_coverage :branch + primary_coverage :branch + end +end + +# name the test file/group +SimpleCov.command_name 'test:exercism' + +# original exercism tests require 'minitest/autorun' require_relative 'hello_world' diff --git a/ruby/hello-world/run-tests-ruby.txt b/ruby/hello-world/run-tests-ruby.txt new file mode 100644 index 00000000..d997d0c3 --- /dev/null +++ b/ruby/hello-world/run-tests-ruby.txt @@ -0,0 +1,137 @@ +Running automated test file(s): + + +=============================================================================== + +Running: ../../.github/citools/ruby/ruby-lint-rubycritic + +Running RubyCritic + +Ruby version: + + ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux] + + + ============================================================================== + +Running: rubycritic --path .rubycritic --format console --no-browser . + +running flay smells + +running flog smells +.. +running reek smells +.. +running complexity +.. +running attributes +.. +running churn +.. +running simple_cov +.. +/home/vpayno/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubycritic-4.6.1/lib/rubycritic/generators/text/list.rb:13: warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments. +/home/vpayno/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubycritic-4.6.1/lib/rubycritic/generators/text/list.rb:13: warning: Passing trim_mode with the 3rd argument of ERB.new is deprecated. Use keyword argument like ERB.new(str, trim_mode: ...) instead. +HelloWorld: + Rating: A + Churn: 0 + Complexity: 0.0 + Duplication: 0 + Smells: 1 + * (IrresponsibleModule) HelloWorld has no descriptive comment + - hello_world.rb:1 + +HelloWorldTest: + Rating: A + Churn: 0 + Complexity: 2.4 + Duplication: 0 + Smells: 1 + * (IrresponsibleModule) HelloWorldTest has no descriptive comment + - hello_world_test.rb:28 +Score: 99.7 + +real 0m0.610s +user 0m0.479s +sys 0m0.130s + + + ============================================================================== + +Exit code: 0 + +real 0m0.660s +user 0m0.495s +sys 0m0.165s + +real 0m0.664s +user 0m0.497s +sys 0m0.167s + +=============================================================================== + +Running: ../../.github/citools/ruby/ruby-test-with-coverage + +Running Ruby Tests With Coverage + +Ruby version: + + ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux] + + + ============================================================================== + +Running: rm -rf ./coverage + + +real 0m0.001s +user 0m0.000s +sys 0m0.001s + + + ============================================================================== + +Running: ruby ./hello_world_test.rb -v + +Run options: -v --seed 41052 + +# Running: + +HelloWorldTest#test_say_hi = 0.00 s = . + +Finished in 0.001509s, 662.5219 runs/s, 662.5219 assertions/s. + +1 runs, 1 assertions, 0 failures, 0 errors, 0 skips +Coverage report generated for test:exercism to /home/vpayno/git_vpayno/exercism-workspace/ruby/hello-world/coverage/coverage.xml. 3 / 3 LOC (100.00%) covered + +real 0m0.171s +user 0m0.125s +sys 0m0.046s + + + ============================================================================== + +Exit code: 0 + +real 0m0.209s +user 0m0.139s +sys 0m0.072s + +real 0m0.211s +user 0m0.140s +sys 0m0.074s + +=============================================================================== + +Running: misspell . + +real 0m0.026s +user 0m0.020s +sys 0m0.019s + +=============================================================================== + +/home/vpayno/git_vpayno/exercism-workspace/ruby + +=============================================================================== + From 24126db331ee41c032ae7d17ada544ebf1c6a5d0 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Mon, 2 Oct 2023 23:07:08 -0700 Subject: [PATCH 11/23] ruby(tools): add gitignore file --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 77b30143..49b6cd4a 100644 --- a/.gitignore +++ b/.gitignore @@ -77,3 +77,6 @@ rust/index.scip # tcl # vimscript + +# ruby +# coverage From f2242a8e09f14fa704ebc41dc4e32fe6338139d7 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Mon, 2 Oct 2023 23:47:40 -0700 Subject: [PATCH 12/23] ruby(tools): fix setup script --- .github/citools/ruby/ruby-setup-config | 2 +- .github/citools/ruby/ruby-setup-install | 91 ++++++++++++++++++++++++- .github/citools/ruby/ruby-setup-verify | 10 +++ 3 files changed, 100 insertions(+), 3 deletions(-) diff --git a/.github/citools/ruby/ruby-setup-config b/.github/citools/ruby/ruby-setup-config index e6bc45fa..c3cc946c 100755 --- a/.github/citools/ruby/ruby-setup-config +++ b/.github/citools/ruby/ruby-setup-config @@ -13,7 +13,7 @@ main() { print_ruler - # printf "%s\n" "/root/.rustup/toolchains/stable-$(arch)-unknown-linux-gnu/bin" "/root/.cargo/bin" | tee -a "${GITHUB_PATH}" + printf "%s\n" "/root/.rbenv/bin" "${HOME}/.rbenv/bin" "${HOME}/home/.rbenv/bin" | tee -a "${GITHUB_PATH}" print_ruler diff --git a/.github/citools/ruby/ruby-setup-install b/.github/citools/ruby/ruby-setup-install index 47f45a6e..68f056da 100755 --- a/.github/citools/ruby/ruby-setup-install +++ b/.github/citools/ruby/ruby-setup-install @@ -13,13 +13,100 @@ main() { print_ruler - echo Running: sudo apt install ruby-full - time sudo apt install -y ruby-full || ((retval++)) + echo Running: sudo apt update + time sudo apt update || ((retval++)) + + print_ruler + + local -a debs + debs=( + autoconf + automake + bison + build-essential + curl + g++ + gcc + git + gnupg + libc6-dev + libffi-dev + libgdbm-dev + libgmp-dev + libncurses5-dev + libreadline-dev + libsqlite3-dev + libssl-dev + libtool + libyaml-dev + make + pkg-config + sqlite3 + zlib1g-dev + ) + + echo Running: sudo apt install -y "${debs[@]}" + time sudo apt install -y "${debs[@]}" || ((retval++)) + + print_ruler + + echo Running: curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer \| bash + time curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash || ((retval++)) + + print_ruler + + echo Running: curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor \| bash + time curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor | bash || ((retval++)) + + print_ruler + + echo Running: rbenv -v + time rbenv -v || ((retval++)) + + print_ruler + + printf "Configuring Shell: " + # shellcheck disable=SC2016 + echo 'export PATH="${HOME}/.rbenv/bin:${PATH}"' >>/etc/profile.d/rbenv.sh + # shellcheck disable=SC2016 + echo 'eval "$(rbenv init -)"' >>/etc/profile.d/rbenv.sh + # shellcheck disable=SC1090 + source /etc/profile.d/rbenv.sh + printf "done\n" + + print_ruler + + echo Running: rbenv install --list + time rbenv install --list || ((retval++)) + + print_ruler + + local ruby_version + ruby_version="$(rbenv install --list 2>/dev/null | grep '^3[.]1[.]' | tail -n 1)" || ((retval++)) + + echo Running: rbenv install "${ruby_version}" + time rbenv install "${ruby_version}" || ((retval++)) + + print_ruler + + echo Running: rbenv global "${ruby_version}" + time rbenv global "${ruby_version}" || ((retval++)) + + print_ruler + + echo Running: ruby -v + time ruby -v || ((retval++)) print_ruler local -a gems gems=( + rspec + rspec-core + rspec-expectations + rspec-mocks + rspec-parameterized + rspec-support rubycritic simplecov simplecov-cobertura diff --git a/.github/citools/ruby/ruby-setup-verify b/.github/citools/ruby/ruby-setup-verify index 9a74e504..95014b0e 100755 --- a/.github/citools/ruby/ruby-setup-verify +++ b/.github/citools/ruby/ruby-setup-verify @@ -37,6 +37,16 @@ main() { print_ruler + printf "RBENV_SHELL=%s\n" "${RBENV_SHELL}" + printf "PATH=%s\n" "${PATH}" + + print_ruler + + echo Running: rbenv init - + time rbenv init - + + print_ruler + show_tool_versions_ruby print_ruler From 66d72876ca3670d4931ae59bad3ad9fdbe7f6f65 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Tue, 3 Oct 2023 08:58:16 -0700 Subject: [PATCH 13/23] ruby(tools): add track_errors() and use it in setup script to debug error codes --- .github/citools/includes/wrapper-library | 5 +++++ .github/citools/ruby/ruby-setup-install | 22 +++++++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.github/citools/includes/wrapper-library b/.github/citools/includes/wrapper-library index ecf1447e..bc76e21f 100644 --- a/.github/citools/includes/wrapper-library +++ b/.github/citools/includes/wrapper-library @@ -25,6 +25,11 @@ run_command() { # md_code_tag } # run_command() +track_errors() { + ((retval++)) + printf "\nERROR: Failure detected in last command.\n" +} # track_errors() + print_ruler() { printf "\n " printf "=%.0s" {1..78} diff --git a/.github/citools/ruby/ruby-setup-install b/.github/citools/ruby/ruby-setup-install index 68f056da..8a919ae5 100755 --- a/.github/citools/ruby/ruby-setup-install +++ b/.github/citools/ruby/ruby-setup-install @@ -14,7 +14,7 @@ main() { print_ruler echo Running: sudo apt update - time sudo apt update || ((retval++)) + time sudo apt update || track_errors print_ruler @@ -46,22 +46,22 @@ main() { ) echo Running: sudo apt install -y "${debs[@]}" - time sudo apt install -y "${debs[@]}" || ((retval++)) + time sudo apt install -y "${debs[@]}" || track_errors print_ruler echo Running: curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer \| bash - time curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash || ((retval++)) + time curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash || track_errors print_ruler echo Running: curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor \| bash - time curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor | bash || ((retval++)) + time curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor | bash || track_errors print_ruler echo Running: rbenv -v - time rbenv -v || ((retval++)) + time rbenv -v || track_errors print_ruler @@ -77,25 +77,25 @@ main() { print_ruler echo Running: rbenv install --list - time rbenv install --list || ((retval++)) + time rbenv install --list || track_errors print_ruler local ruby_version - ruby_version="$(rbenv install --list 2>/dev/null | grep '^3[.]1[.]' | tail -n 1)" || ((retval++)) + ruby_version="$(rbenv install --list 2>/dev/null | grep '^3[.][0-9][.]' | tail -n 1)" || track_errors echo Running: rbenv install "${ruby_version}" - time rbenv install "${ruby_version}" || ((retval++)) + time rbenv install "${ruby_version}" || track_errors print_ruler echo Running: rbenv global "${ruby_version}" - time rbenv global "${ruby_version}" || ((retval++)) + time rbenv global "${ruby_version}" || track_errors print_ruler echo Running: ruby -v - time ruby -v || ((retval++)) + time ruby -v || track_errors print_ruler @@ -113,7 +113,7 @@ main() { ) echo Running: gem install "${gems[@]}" - time gem install "${gems[@]}" || ((retval++)) + time gem install "${gems[@]}" || track_errors print_ruler From 3d1a5182a71876991f7d0f61a579fdb96953cac5 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Tue, 3 Oct 2023 12:21:30 -0700 Subject: [PATCH 14/23] ruby(tools): move rbenv-doctor call to after ruby is setup --- .github/citools/ruby/ruby-setup-install | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/citools/ruby/ruby-setup-install b/.github/citools/ruby/ruby-setup-install index 8a919ae5..a5be4ca7 100755 --- a/.github/citools/ruby/ruby-setup-install +++ b/.github/citools/ruby/ruby-setup-install @@ -55,11 +55,6 @@ main() { print_ruler - echo Running: curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor \| bash - time curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor | bash || track_errors - - print_ruler - echo Running: rbenv -v time rbenv -v || track_errors @@ -117,6 +112,11 @@ main() { print_ruler + echo Running: curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor \| bash + time curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor | bash || track_errors + + print_ruler + echo Exit code: "${retval}" return "${retval}" } From 93a476709a59252f4905fe2cb0197dbfc559e31d Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Tue, 3 Oct 2023 19:39:21 -0700 Subject: [PATCH 15/23] ruby(tools): move ruby-setup-verify fixes --- .github/citools/ruby/ruby-setup-verify | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/citools/ruby/ruby-setup-verify b/.github/citools/ruby/ruby-setup-verify index 95014b0e..c28cbfb2 100755 --- a/.github/citools/ruby/ruby-setup-verify +++ b/.github/citools/ruby/ruby-setup-verify @@ -22,17 +22,6 @@ ruby_cmds=( ) main() { - for key in "${!ruby_cmds[@]}"; do - if [[ ${ruby_cmds[${key}]} -ne 0 ]]; then - printf "ERROR: command [%s] not found.\n" "${key}" - ((retval++)) - fi - done - - if [[ ${retval} -ne 0 ]]; then - return "${retval}" - fi - printf "Verifying Ruby Installation\n\n" print_ruler @@ -45,6 +34,17 @@ main() { echo Running: rbenv init - time rbenv init - + for key in "${!ruby_cmds[@]}"; do + if [[ ${ruby_cmds[${key}]} -ne 0 ]]; then + printf "ERROR: command [%s] not found.\n" "${key}" + ((retval++)) + fi + done + + if [[ ${retval} -ne 0 ]]; then + return "${retval}" + fi + print_ruler show_tool_versions_ruby From e19d10809029fbf9d4a50fa3e2eba666e21ba19d Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Tue, 3 Oct 2023 22:19:34 -0700 Subject: [PATCH 16/23] ruby(tools): add profile changes to /etc/skel --- .github/citools/ruby/ruby-setup-install | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/citools/ruby/ruby-setup-install b/.github/citools/ruby/ruby-setup-install index a5be4ca7..b760698a 100755 --- a/.github/citools/ruby/ruby-setup-install +++ b/.github/citools/ruby/ruby-setup-install @@ -62,9 +62,14 @@ main() { printf "Configuring Shell: " # shellcheck disable=SC2016 - echo 'export PATH="${HOME}/.rbenv/bin:${PATH}"' >>/etc/profile.d/rbenv.sh - # shellcheck disable=SC2016 - echo 'eval "$(rbenv init -)"' >>/etc/profile.d/rbenv.sh + { + #echo 'export PATH="${HOME}/.rbenv/bin:${PATH}"' >>/etc/profile.d/rbenv.sh + #echo 'export PATH="${HOME}/.rbenv/bin:${PATH}"' >>/etc/skell/.bashrc + echo 'export PATH="${HOME}/.rbenv/bin:${PATH}"' >>"${HOME}"/.bashrc + #echo 'eval "$(rbenv init -)"' >>/etc/profile.d/rbenv.sh + #echo 'eval "$(rbenv init -)"' >>/etc/skell/.bashrc + echo 'eval "$(rbenv init -)"' >>"${HOME}"/.bashrc + } # shellcheck disable=SC1090 source /etc/profile.d/rbenv.sh printf "done\n" From 7468f7e9d7016ba0e480e52f6c78f89522b5a4e6 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Wed, 4 Oct 2023 09:06:06 -0700 Subject: [PATCH 17/23] ruby(tools): profile/shell fixes for ci runs --- .github/citools/ruby/ruby-setup-config | 2 +- .github/citools/ruby/ruby-setup-install | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/citools/ruby/ruby-setup-config b/.github/citools/ruby/ruby-setup-config index c3cc946c..e779a863 100755 --- a/.github/citools/ruby/ruby-setup-config +++ b/.github/citools/ruby/ruby-setup-config @@ -13,7 +13,7 @@ main() { print_ruler - printf "%s\n" "/root/.rbenv/bin" "${HOME}/.rbenv/bin" "${HOME}/home/.rbenv/bin" | tee -a "${GITHUB_PATH}" + printf "%s\n" "${HOME}/.rbenv/bin" "${HOME}/.rbenv/shims" | tee -a "${GITHUB_PATH}" print_ruler diff --git a/.github/citools/ruby/ruby-setup-install b/.github/citools/ruby/ruby-setup-install index b760698a..78ae5468 100755 --- a/.github/citools/ruby/ruby-setup-install +++ b/.github/citools/ruby/ruby-setup-install @@ -63,15 +63,11 @@ main() { printf "Configuring Shell: " # shellcheck disable=SC2016 { - #echo 'export PATH="${HOME}/.rbenv/bin:${PATH}"' >>/etc/profile.d/rbenv.sh - #echo 'export PATH="${HOME}/.rbenv/bin:${PATH}"' >>/etc/skell/.bashrc - echo 'export PATH="${HOME}/.rbenv/bin:${PATH}"' >>"${HOME}"/.bashrc - #echo 'eval "$(rbenv init -)"' >>/etc/profile.d/rbenv.sh - #echo 'eval "$(rbenv init -)"' >>/etc/skell/.bashrc + echo 'export PATH="${HOME}/.rbenv/bin::${HOME}/.rbenv/bin/shims:${PATH}"' >>"${HOME}"/.bashrc echo 'eval "$(rbenv init -)"' >>"${HOME}"/.bashrc } # shellcheck disable=SC1090 - source /etc/profile.d/rbenv.sh + source "${HOME}"/.bashrc || track_errors printf "done\n" print_ruler From 8e35b464e18d7e8c9b4525724eb45b53e303934a Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Wed, 4 Oct 2023 09:26:39 -0700 Subject: [PATCH 18/23] ruby(tools): add rbenv version to show_tool_versions*() functions --- .github/citools/includes/wrapper-library | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/citools/includes/wrapper-library b/.github/citools/includes/wrapper-library index bc76e21f..367dd941 100644 --- a/.github/citools/includes/wrapper-library +++ b/.github/citools/includes/wrapper-library @@ -126,6 +126,7 @@ show_tool_versions_ruby_short() { printf "Ruby version:\n" printf "\n" ruby --version | paste /dev/null - + rbenv --version | paste /dev/null - # md_code_tag printf "\n" } # show_tool_versions_ruby_short() @@ -135,6 +136,7 @@ show_tool_versions_ruby() { printf "Ruby version:\n" printf "\n" ruby --version | paste /dev/null - + rbenv --version | paste /dev/null - # md_code_tag printf "\n" From 86929a21a9bce583ed22ae0b007aa441d339a3ce Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Wed, 4 Oct 2023 09:27:08 -0700 Subject: [PATCH 19/23] ruby(tools): use show_tool_versions_ruby_short() in test and lint scripts --- .github/citools/ruby/ruby-lint-rubycritic | 2 +- .github/citools/ruby/ruby-test-with-coverage | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/citools/ruby/ruby-lint-rubycritic b/.github/citools/ruby/ruby-lint-rubycritic index 0c56607e..9d8dadb4 100755 --- a/.github/citools/ruby/ruby-lint-rubycritic +++ b/.github/citools/ruby/ruby-lint-rubycritic @@ -11,7 +11,7 @@ declare -i retval=0 main() { printf "\nRunning RubyCritic\n\n" - show_tool_versions_ruby + show_tool_versions_ruby_short print_ruler diff --git a/.github/citools/ruby/ruby-test-with-coverage b/.github/citools/ruby/ruby-test-with-coverage index da3ef674..253c8bff 100755 --- a/.github/citools/ruby/ruby-test-with-coverage +++ b/.github/citools/ruby/ruby-test-with-coverage @@ -11,7 +11,7 @@ declare -i retval=0 main() { printf "\nRunning Ruby Tests With Coverage\n\n" - show_tool_versions_ruby + show_tool_versions_ruby_short print_ruler From 3aea4570b1e30b7fb6a53a92dee6fdc93b7bd070 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Wed, 4 Oct 2023 19:02:08 -0700 Subject: [PATCH 20/23] ruby(ci): coverage report to test wrapper script --- .github/citools/ruby/ruby-test-with-coverage | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/citools/ruby/ruby-test-with-coverage b/.github/citools/ruby/ruby-test-with-coverage index 253c8bff..b21db200 100755 --- a/.github/citools/ruby/ruby-test-with-coverage +++ b/.github/citools/ruby/ruby-test-with-coverage @@ -27,6 +27,12 @@ main() { print_ruler + local coverage_raw + coverage_raw="$(xq -q coverage -a line-rate ./coverage/coverage.xml)" + printf "Coverage: %.1f%%\n" "$(bc <<<"scale=1; ${coverage_raw}* 100")" + + print_ruler + echo Exit code: "${retval}" return "${retval}" } From 87e1979aede4442464abbccb4891dd1ff0890ff2 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Thu, 5 Oct 2023 00:00:09 -0700 Subject: [PATCH 21/23] ruby(tools): add bc and xq to install script --- .github/citools/ruby/ruby-setup-install | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/citools/ruby/ruby-setup-install b/.github/citools/ruby/ruby-setup-install index 78ae5468..eed343e2 100755 --- a/.github/citools/ruby/ruby-setup-install +++ b/.github/citools/ruby/ruby-setup-install @@ -23,6 +23,7 @@ main() { autoconf automake bison + bc build-essential curl g++ @@ -45,6 +46,11 @@ main() { zlib1g-dev ) + echo Running: go install github.com/sibprogrammer/xq@latest + time go install github.com/sibprogrammer/xq@latest + + print_ruler + echo Running: sudo apt install -y "${debs[@]}" time sudo apt install -y "${debs[@]}" || track_errors From fe209d11f4689223bcbfca393c45b7e43926e566 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Thu, 5 Oct 2023 08:59:44 -0700 Subject: [PATCH 22/23] ruby(ci): update var info step and add user info step --- .github/workflows/ruby.yml | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 2bd39db6..fc5abd89 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -21,8 +21,30 @@ jobs: exercise_count: ${{ steps.check_file_changed.outputs.exercise_count }} steps: - name: Check GitHub Vars - id: github-vars - run: set | grep -e ^CI -e ^GITHUB_ -e ^RUNNER_ + id: github-vars-check + run: |- + { + printf "\`\`\`text\n" + printf "Runner environment info:\n" + set | grep -e ^CI -e ^GITHUB_ -e ^RUNNER_ + printf "\`\`\`\n" + } | tee -a "${GITHUB_STEP_SUMMARY}" + - name: Check GitHub User + id: github-user-check + run: |- + # get user info for default gh container + { + printf "\`\`\`text\n" + printf "Container user info:\n" + who + printf "\n" + id + printf "\n" + printf "HOME: %s\n" "${HOME}" + printf "\n" + printf "SHELL: %s\n" "$(getent passwd "${USER}" | awk -F: '{print $NF}')" + printf "\`\`\`\n" + } | tee -a "${GITHUB_STEP_SUMMARY}" - name: Checkout Repo id: checkout-repo uses: actions/checkout@v3 @@ -41,17 +63,6 @@ jobs: printf "\n" } | tee -a "${GITHUB_STEP_SUMMARY}" - # get user info for default gh container - { - printf "\`\`\`text\n" - printf "Container user info:\n" - who - printf "\n" - id - printf "\`\`\`\n" - } | tee -a "${GITHUB_STEP_SUMMARY}" - printf "\n" - # Diff HEAD with the previous commit then output to stdout. GIT_DIFF="$(git diff --name-only HEAD^ HEAD | tee /tmp/changed_files.txt)" { From 2562f2a2184d6b0bcdb39ebcdf334a7db1fb5ad9 Mon Sep 17 00:00:00 2001 From: Victor Payno Date: Fri, 6 Oct 2023 12:45:19 -0700 Subject: [PATCH 23/23] ruby(ci): xq is now included in the ci container --- .github/citools/ruby/ruby-setup-install | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/citools/ruby/ruby-setup-install b/.github/citools/ruby/ruby-setup-install index eed343e2..bdd766a3 100755 --- a/.github/citools/ruby/ruby-setup-install +++ b/.github/citools/ruby/ruby-setup-install @@ -46,11 +46,6 @@ main() { zlib1g-dev ) - echo Running: go install github.com/sibprogrammer/xq@latest - time go install github.com/sibprogrammer/xq@latest - - print_ruler - echo Running: sudo apt install -y "${debs[@]}" time sudo apt install -y "${debs[@]}" || track_errors