From b4554e13f261b2290c3d7f0dfb1f796ebbc33949 Mon Sep 17 00:00:00 2001 From: Dentrax Date: Mon, 9 Sep 2024 15:13:00 +0300 Subject: [PATCH] pipelines/ruby: add new pipelines to ruby packages Signed-off-by: Dentrax --- e2e-tests/README.md | 2 +- e2e-tests/ruby3.2-json-test.yaml | 28 +++++++++ pkg/build/pipelines/ruby/require.yaml | 85 +++++++++++++++++++++++++++ pkg/build/pipelines/ruby/test.yaml | 14 +++++ 4 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 e2e-tests/ruby3.2-json-test.yaml create mode 100644 pkg/build/pipelines/ruby/require.yaml create mode 100644 pkg/build/pipelines/ruby/test.yaml diff --git a/e2e-tests/README.md b/e2e-tests/README.md index 2c5ac256a..a3c0edd00 100644 --- a/e2e-tests/README.md +++ b/e2e-tests/README.md @@ -1,6 +1,6 @@ # e2e-tests .yaml files in this directory will be built by melange via -the 'run-tests' script. +the 'run-tests' script that you can run with `make test-e2e`. Melange options are based on yaml file name. diff --git a/e2e-tests/ruby3.2-json-test.yaml b/e2e-tests/ruby3.2-json-test.yaml new file mode 100644 index 000000000..0b51da7d2 --- /dev/null +++ b/e2e-tests/ruby3.2-json-test.yaml @@ -0,0 +1,28 @@ +package: + name: ruby3.2-json + version: 2.7.2 + epoch: 1 + description: Tests for ruby3.2-json using Ruby test pipelines + +pipeline: + +# Test ruby/require, and ruby/test pipelines +test: + environment: + contents: + packages: + - ruby-3.2 + pipeline: + # Test require with command + - uses: ruby/test + with: + command: ruby -e "require 'json'" + # Test require directly + - uses: ruby/require + with: + require: json + # Test require with multiple requires + - uses: ruby/require + with: + requires: | + require 'json' diff --git a/pkg/build/pipelines/ruby/require.yaml b/pkg/build/pipelines/ruby/require.yaml new file mode 100644 index 000000000..6ead2263c --- /dev/null +++ b/pkg/build/pipelines/ruby/require.yaml @@ -0,0 +1,85 @@ +name: Test a Ruby package require, with optional load clause + +needs: + packages: + - wolfi-base + +inputs: + ruby: + description: Which Ruby to use + default: DEFAULT + require: + description: | + The package to require. + required: false + requires: + description: | + Commands to require packages, each line is a separate command. Example: + require 'foo' + # test that otherthing can be required from asdf + require 'asdf' + require 'bark' # this is like woof + + full-line and inline comments are supported via '#' + required: false + +pipeline: + - runs: | + set +x + RUBY="${{inputs.ruby}}" + SINGLE_REQUIRE="${{inputs.require}}" + MULTIPLE_REQUIRES="${{inputs.requires}}" + + perform_require() { + command="$1" + if $RUBY -e "$command"; then + echo "$RUBY -e \"$command\": PASS" + else + echo "$RUBY -e \"$command\": FAIL" + return 1 + fi + } + + if [ "$RUBY" = "DEFAULT" ]; then + glob="/usr/bin/ruby-3.[0-9][0-9] /usr/bin/ruby-3.[789] /usr/bin/ruby" + n=0 + for p in $glob; do + [ -x "$p" ] && n=$((n+1)) && rb=$p + done + if [ "$n" -ne 1 ]; then + echo "FAIL: must set inputs.ruby: " \ + "found $n executables matching $glob" + [ "$n" -eq 0 ] || echo "found:" $glob + exit 1 + fi + echo "using ruby $rb" + RUBY=$rb + fi + + if [ -n "$SINGLE_REQUIRE" ] && [ -n "$MULTIPLE_REQUIRES" ]; then + echo "Error: Cannot mix 'require' with 'requires'." + exit 1 + fi + + fail_flag=0 + if [ -n "$MULTIPLE_REQUIRES" ]; then + requiref=$(mktemp) || { echo "failed mktemp"; exit 1; } + printf "%s\n" "$MULTIPLE_REQUIRES" > "$requiref" || + { echo "failed to write to temp file"; exit 1; } + + while read line; do + # Drop anything after # + line=${line%%#*} + cmd=$(set -f; echo $line) # normalize/trim whitespace + [ -z "$cmd" ] && continue + perform_require "$cmd" || fail_flag=1 + done < "$requiref" + rm -f "$requiref" + elif [ -n "$SINGLE_REQUIRE" ]; then + perform_require "require '$SINGLE_IMPORT'" || fail_flag=1 + else + echo "No package specified for require." + fail_flag=1 + fi + + exit $fail_flag diff --git a/pkg/build/pipelines/ruby/test.yaml b/pkg/build/pipelines/ruby/test.yaml new file mode 100644 index 000000000..f415369e0 --- /dev/null +++ b/pkg/build/pipelines/ruby/test.yaml @@ -0,0 +1,14 @@ +name: Test a Ruby package + +needs: + packages: + - wolfi-base + +inputs: + command: + description: | + The command to run. + required: true + +pipeline: + - runs: ${{inputs.command}}