Skip to content

Commit

Permalink
Merge pull request #325 from davetron5000/upgrade-to-minitest-of-10-y…
Browse files Browse the repository at this point in the history
…ears-ago

Upgrade to new Minitest constant + new dev env + 3.3 bugfix
  • Loading branch information
davetron5000 authored Jul 16, 2024
2 parents 70968f9 + e4e2b1a commit e7758f5
Show file tree
Hide file tree
Showing 35 changed files with 532 additions and 74 deletions.
30 changes: 0 additions & 30 deletions .circleci/config.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ results.html
.DS_Store
Session.vim
scaffold_test
dx/docker-compose.local.env
docker-compose.dx.yml
.tool-versions
.ruby-version
1 change: 0 additions & 1 deletion .tool-versions

This file was deleted.

81 changes: 60 additions & 21 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,60 @@
Contributions are welcome as long as they are part of my vision for GLI (or can be treated as optional to the user). I am obsessive about backwards-compatibility, so you may need to default things to disable your features. Sorry, not ready to bump a major version any time soon.

1. Fork my Repository
2. Create a branch off of main
3. Make your changes:
* Please include tests and watch out for reek and roodi; i.e. keep your code clean
* If you make changes to the gli executable or the scaffolding, please update the cucumber features
* Please rubydoc any new methods and update the rubydoc to methods you change in the following format:
```ruby
# Short description
#
# Longer description if needed
#
# +args+:: get documented using this syntax
# +args+:: please state the TYPE of every arg
#
# Returns goes here, please state the TYPE of what's returned, if anything
```
* Use <code># :nodoc:</code> for methods that a _user_ of GLI should not call (but still please do document all methods)
4. Make sure your branch will merge with my gli-2 branch (or just rebase your branch from my gli-2 branch)
5. Create a pull request explaining your change
# Contributing/Developing

## Types of Contributions

GLI is relatively stable. As such:

* No major new features should be added
* No refactorings or "modernization" is desired
* No runtime dependencies should be added.

If you really want to make a change like this, open an issue first to discuss.

That said, I welcome:

* Bugfixes
* Doc changes
* Minor improvements

I am responsive on issues, so reach out there if you have a question.

## How to Do Development

GLI us using a Docker-based development system to ensure consistency. To use it, you will need to have Docker installed, as well
as Bash. This should all work under Windows Subsystem for Linux.

### Setting Up

1. Install Docker
2. `dx/build`

This will use `Dockerfile.dx` to create one Docker image for each supported Ruby version (see `dx/docker-compose.env`'s `RUBY_VERSIONS` variable for the current list). This will also generate `docker-compose.dx.yml` which will run all versions of Ruby for GLI at the same time.
3. `dx/start`

This will start Docker using `docker-compose.dx.yml`, which will run containers for all the images generated by `dx/build`

4. From here, you can run commands inside the running containers, or you can run `bash` inside a container to effectively "log
in" and run commands.

### Doing Development

Once you are set up, you should run `dx/exec bash`. This will log you into the container running the oldest supported version of
Ruby. This is the version where you should do your basic work. This container has access to the source code you cloned from
GitHub.

1. `on-your-computer> dx/exec bash`
2. `inside-docker-container> bin/setup # installs all gems`
3. `inside-docker-container> bin/rake # runs all tests`

Once you have stuff working, run tests on the other versions. Since the container you were working in was operating on your
checked-out files, the other containers will have access as well.

1. `on-your-computer> dx/exec -v 3.3 bash # connects to the conatiner where Ruby 3.3 is installed`
2. `inside-docker-container> bin/setup # installs all gems`
3. `inside-docker-container> bin/rake # runs all tests`

#### If You Want To Use Your Local Computer

In theory, GLI can be worked on using RVM, RBEnv, asdf, or whatever other way you want to manage Ruby. You can create a
`.ruby-version` or `.tool-versions`. These are ignored so you can keep them on your machine. I don't support this setup, so if
something is wrong, I probably can't help. This is why I have it set up with Docker.
28 changes: 28 additions & 0 deletions Dockerfile.dx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ARG RUBY_VERSION
FROM ruby:${RUBY_VERSION}

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -y update


# dx.snippet.start=templates/snippets/bundler/latest__bundler.dockerfile-snippet
# Based on documentation at https://guides.rubygems.org/command-reference/#gem-update
# based on the vendor's documentation
RUN echo "gem: --no-document" >> ~/.gemrc && \
gem update --system && \
gem install bundler

# dx.snippet.end=templates/snippets/bundler/latest__bundler.dockerfile-snippet


# dx.snippet.start=templates/snippets/vim/bullseye_vim.dockerfile-snippet
# Based on documentation at https://packages.debian.org/search?keywords=vim
# based on the vendor's documentation
ENV EDITOR=vim
RUN apt-get install -y vim && \
echo "set -o vi" >> /root/.bashrc
# dx.snippet.end=templates/snippets/vim/bullseye_vim.dockerfile-snippet

# This entrypoint produces a nice help message and waits around for you to do
# something with the container.
COPY dx/show-help-in-app-container-then-wait.sh /root
8 changes: 6 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,20 @@ Get a more detailed walkthrough on the {main site}[http://davetron5000.github.io

== Supported Platforms

See `.circleci/config.yml` for the supported rubies, but general we're running tests on the all MRI rubies receiving support, which tends to be the most recent four versions.
See `dx/docker-compose.env` and the variable `RUBY_VERSIONS` for the versions that are supported. This should generally track with the supported version of Ruby from Ruby's maintainers.

GLI should work on older Rubies and JRuby, but it's too much work to keep tests passing for those.
That said, GLI should generally work on other Rubies as it doesn't have any runtime dependencies and there are no plans to use more modern features of Ruby in the codebase.

== Documentation

Extensive documentation is {available at the wiki}[https://github.com/davetron5000/gli/wiki].

API Documentation is available {here}[http://davetron5000.github.io/gli/rdoc/index.html]. Recommend starting with GLI::DSL or GLI::App.

== Developing

See `CONTRIBUTING.md`

== Credits

Author:: Dave Copeland (mailto:davetron5000 at g mail dot com)
Expand Down
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ Rake::TestTask.new("test:unit") do |t|
ENV["RUBYOPT"].split(/\s/).each do |opt|
t.ruby_opts << opt
end
if t.ruby_opts.none? { |x| x =~ /^\-W/ }
t.ruby_opts << "-W0"
end
t.test_files = FileList["test/unit/**/*_test.rb"]
end

Expand All @@ -89,6 +92,9 @@ Rake::TestTask.new("test:integration") do |t|
ENV["RUBYOPT"].split(/\s/).each do |opt|
t.ruby_opts << opt
end
if t.ruby_opts.none? { |x| x =~ /^\-W/ }
t.ruby_opts << "-W0"
end
explicitly_named_files = ARGV[1..-1]
if Array(explicitly_named_files).size == 0
t.test_files = FileList["test/integration/**/*_test.rb"]
Expand Down
10 changes: 8 additions & 2 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash

set -e

bundle check || bundle install
if [ Gemfile.lock -ot gli.gemspec ] ; then
echo "[ bin/setup ] gli.gemspec has been modified - deleting Gemfile.lock"
rm Gemfile.lock
bundle install
else
echo "[ bin/setup ] checking bundle and updating as necessary"
bundle check || bundle install
fi
60 changes: 60 additions & 0 deletions dx/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

set -e

SCRIPT_DIR=$( cd -- "$( dirname -- "${0}" )" > /dev/null 2>&1 && pwd )

. "${SCRIPT_DIR}/dx.sh.lib"

require_command "docker"
load_docker_compose_env

usage_on_help "Builds the Docker image based on the Dockerfile" "" "build.pre" "build.post" "${@}"

for ruby_version in ${RUBY_VERSIONS[@]}; do
dockerfile="Dockerfile.dx"
docker_image_name="${IMAGE}:ruby-${ruby_version}"

log "Building for Ruby '${ruby_version}' using Docker image name '${docker_image_name}'"

exec_hook_if_exists "build.pre" "${dockerfile}" "${docker_image_name}"

docker build \
--file "${dockerfile}" \
--build-arg="RUBY_VERSION=${ruby_version}" \
--tag "${docker_image_name}" \
./

exec_hook_if_exists "build.post" "${dockerfile}" "${docker_image_name}"
log "🌈" "Your Docker image has been built tagged '${docker_image_name}'"
done

log "" "All images built"

log "" "Creating docker-compose.dx.yml"
compose_file="docker-compose.dx.yml"
log "🗑️" "Deleting previous ${compose_file}"

rm "${compose_file}"
echo "# THIS IS GENERATED - DO NOT EDIT" > "${compose_file}"
echo "" >> "${compose_file}"
echo "services:" >> "${compose_file}"

for ruby_version in ${RUBY_VERSIONS[@]}; do
log "Generating stanza for version '${ruby_version}'"
docker_image_name="${IMAGE}:ruby-${ruby_version}"
echo " gli-${ruby_version}:" >> "${compose_file}"
echo " image: ${docker_image_name}" >> "${compose_file}"
echo " init: true" >> "${compose_file}"
echo " volumes:" >> "${compose_file}"
echo " - type: bind" >> "${compose_file}"
echo " source: \"./\"" >> "${compose_file}"
echo " target: \"/root/work\"" >> "${compose_file}"
echo " consistency: \"consistent\"" >> "${compose_file}"
echo " entrypoint: /root/show-help-in-app-container-then-wait.sh" >> "${compose_file}"
echo " working_dir: /root/work" >> "${compose_file}"
done
log "🎼" "${compose_file} is noq created"
log "🔄" "You can run dx/start to start it up, though you may need to stop it first with Ctrl-C"

# vim: ft=bash
5 changes: 5 additions & 0 deletions dx/docker-compose.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This array must include the oldest Ruby first!
RUBY_VERSIONS=("3.1" "3.2" "3.3")
IMAGE=davetron5000/gli-dev
PROJECT_NAME=gli
# vim: ft=bash
24 changes: 24 additions & 0 deletions dx/dx.sh.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# shellcheck shell=bash

. "${SCRIPT_DIR}/setupkit.sh.lib"

require_command "realpath"
require_command "cat"

ENV_FILE=$(realpath "${SCRIPT_DIR}")/docker-compose.env

load_docker_compose_env() {
. "${ENV_FILE}"
}

exec_hook_if_exists() {
script_name=$1
shift
if [ -x "${SCRIPT_DIR}"/"${script_name}" ]; then
log "🪝" "${script_name} exists - executing"
"${SCRIPT_DIR}"/"${script_name}" "${@}"
else
debug "${script_name} does not exist"
fi
}
# vim: ft=bash
59 changes: 59 additions & 0 deletions dx/exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

set -e

SCRIPT_DIR=$( cd -- "$( dirname -- "${0}" )" > /dev/null 2>&1 && pwd )

. "${SCRIPT_DIR}/dx.sh.lib"

require_command "docker"
load_docker_compose_env

usage_description="Execute a command inside the app's container."
usage_args="[-s service] [-v ruby_version] command"
usage_pre="exec.pre"
usage_on_help "${usage_description}" "${usage_args}" "${usage_pre}" "" "${@}"

LATEST_RUBY=${RUBY_VERSIONS[0]}
DEFAULT_SERVICE=gli-${LATEST_RUBY}
SERVICE="${SERVICE_NAME:-${DEFAULT_SERVICE}}"
while getopts "v:s:" opt "${@}"; do
case ${opt} in
v )
SERVICE="gli-${OPTARG}"
;;
s )
SERVICE="${OPTARG}"
;;
\? )
log "🛑" "Unknown option: ${opt}"
usage "${description}" "${usage_args}" "${usage_pre}"
;;
: )
log "🛑" "Invalid option: ${opt} requires an argument"
usage "${description}" "${usage_args}" "${usage_pre}"
;;
esac
done
shift $((OPTIND -1))

if [ $# -eq 0 ]; then
log "🛑" "You must provide a command e.g. bash or ls -l"
usage "${description}" "${usage_args}" "${usage_pre}"
fi


exec_hook_if_exists "exec.pre"

log "🚂" "Running '${*}' inside container with service name '${SERVICE}'"

docker \
compose \
--file docker-compose.dx.yaml \
--project-name "${PROJECT_NAME}" \
--env-file "${ENV_FILE}" \
exec \
"${SERVICE}" \
"${@}"

# vim: ft=bash
19 changes: 19 additions & 0 deletions dx/prune
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -e

SCRIPT_DIR=$( cd -- "$( dirname -- "${0}" )" > /dev/null 2>&1 && pwd )

. "${SCRIPT_DIR}/dx.sh.lib"
require_command "docker"
load_docker_compose_env

usage_on_help "Prune containers for this repo" "" "" "" "${@}"

for container_id in $(docker container ls -a -f "name=^${PROJECT_NAME}-.*-1$" --format="{{.ID}}"); do
log "🗑" "Removing container with id '${container_id}'"
docker container rm "${container_id}"
done
echo "🧼" "Containers removed"

# vim: ft=bash
Loading

0 comments on commit e7758f5

Please sign in to comment.