Skip to content

Commit

Permalink
pipelines/ruby: add new pipelines to ruby packages
Browse files Browse the repository at this point in the history
Signed-off-by: Dentrax <furkan.turkal@chainguard.dev>
  • Loading branch information
Dentrax committed Sep 11, 2024
1 parent aaa2459 commit ae4bafc
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 1 deletion.
2 changes: 1 addition & 1 deletion e2e-tests/README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
28 changes: 28 additions & 0 deletions e2e-tests/ruby3.2-json-test.yaml
Original file line number Diff line number Diff line change
@@ -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'
85 changes: 85 additions & 0 deletions pkg/build/pipelines/ruby/require.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Test a Ruby package require, with optional load clause

needs:
packages:
- ${{inputs.ruby}}

inputs:
ruby:
description: Which Ruby to use
default: ruby
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" = "ruby" ]; 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_REQUIRE'" || fail_flag=1
else
echo "No package specified for require."
fail_flag=1
fi
exit $fail_flag
14 changes: 14 additions & 0 deletions pkg/build/pipelines/ruby/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Test a Ruby package

needs:
packages:
- busybox

inputs:
command:
description: |
The command to run.
required: true

pipeline:
- runs: ${{inputs.command}}

0 comments on commit ae4bafc

Please sign in to comment.