Skip to content

Instantly share code, notes, and snippets.

@queue-tip
Created December 7, 2023 15:13
Show Gist options
  • Save queue-tip/3ef0cd26f7d0a7a073ebef5ded60827d to your computer and use it in GitHub Desktop.
Save queue-tip/3ef0cd26f7d0a7a073ebef5ded60827d to your computer and use it in GitHub Desktop.
Bash script to run ruby script with 2 versions of ruby and compare their outputs for diffs
#!/bin/bash
RUBY2=2.6.10
RUBY3=3.2.2
EXECUTABLE=$(basename "$0")
function usage() {
echo "NAME
$EXECUTABLE - Compares ruby-based pipelines for submission to Buildkite
SYNOPSIS
Usage: $EXECUTABLE PIPELINE_SCRIPT [BUILDKITE_ENV]
DESCRIPTION
The $EXECUTABLE script runs the PIPELINE_SCRIPT with both ruby v2.6.10 and
ruby 3.2.2, comparing the generated yaml files.
If you haven't already loaded a Buildkite job's environment, you can pass
the shell script's name as the BUILDKITE_ENV argument. It should export
all env vars for the build.
If they differ it exits with a status of 1"
}
if [ $# -lt 1 ]; then
usage
exit
fi
PIPELINE_SCRIPT=$1
BUILDKITE_ENV=$2
if [ -n "$BUILDKITE_ENV" ]; then
if [ -f "$BUILDKITE_ENV" ]; then
source $BUILDKITE_ENV
fi
fi
for ruby_version in $RUBY2 $RUBY3; do
RBENV_VERSION=$ruby_version ruby "$PIPELINE_SCRIPT" >"/tmp/ruby-$ruby_version.out"
done
diff /tmp/ruby-$RUBY2.out /tmp/ruby-$RUBY3.out
if [ ! "$(diff ruby-$RUBY2.out ruby-$RUBY3.out)" ]; then
echo -e "\n\n\nThe rubies produce the same yaml"
result=0
else
echo -e "\n\n\nThe output differs"
result=1
fi
exit $result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment