Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ jobs:
bundler-cache: true
- run: bundle exec rubocop
- run: bundle exec rspec
- name: E2E tests
if: ${{ success() && matrix.os != 'macos-10.15' }}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't run E2E tests on Mac because it doesn't come with docker, see actions/runner-images#17.

run: bash spec/e2e/e2e_run.sh
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-c --order rand
-c --order rand --tag ~e2e
4 changes: 2 additions & 2 deletions lib/mina/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def name
end

# :nocov:
def run
def run(*args)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how run method is defined in Rake::Application.

Rake.application = self
super
super(*args)
end
# :nocov:

Expand Down
4 changes: 2 additions & 2 deletions lib/mina/runner/pretty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ class Pretty
attr_reader :script

def initialize(script)
@script = script
@script = Shellwords.shellsplit(script)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bug I introduced in #686, E2E tests caught it.

@coathooks = 0
end

def run # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
exit_status = nil

Open3.popen3(script) do |_stdin, stdout, stderr, wait_thr|
Open3.popen3(*script) do |_stdin, stdout, stderr, wait_thr|
pid = wait_thr.pid

trap('INT') { handle_sigint(pid) }
Expand Down
25 changes: 25 additions & 0 deletions spec/configs/e2e.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require 'mina/git'

set :simulate, false
set :user, 'mina-ssh'
set :domain, '0.0.0.0'
set :port, 2222
set :deploy_to, '/app'

set :repository, 'https://github.com/mina-deploy/mina.git'
set :branch, 'master'

set :identity_file, 'spec/e2e/ssh'

set :ssh_options, '-o StrictHostKeyChecking=no'

desc 'Deploys to the server'
task :e2e_deploy do
deploy do
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'deploy:cleanup'
end
end
21 changes: 21 additions & 0 deletions spec/e2e/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: '3.8'
services:
mina-ssh:
image: ghcr.io/linuxserver/openssh-server
container_name: mina-ssh
hostname: mina-ssh
environment:
- PUID=1000
- PGID=1000
- TZ=UTC
- PUBLIC_KEY
- SUDO_ACCESS=true
- USER_NAME=mina-ssh
ports:
- 2222:2222
command: >
sh -c "
apk update && apk add git ruby && gem install bundler &&
touch /tmp/ready.txt &&
tail -f /dev/null
"
11 changes: 11 additions & 0 deletions spec/e2e/e2e_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cd spec/e2e/
chmod 600 ssh
PUBLIC_KEY="$(cat ssh.pub)" docker-compose up -d mina-ssh \
&& docker exec mina-ssh sh -c "while [ ! -f /tmp/ready.txt ]; do sleep 2; done"
cd -
[[ -z "${CI}" ]] && ssh-keygen -R \[0.0.0.0\]:2222
bundle exec rspec --tag e2e --order defined
status=$?
cd spec/e2e
docker-compose down
exit $status
35 changes: 35 additions & 0 deletions spec/e2e/e2e_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require 'spec_helper'

# IMPORTANT: run only through e2e_run.sh script
describe 'E2E tests', :e2e, type: :rake do
before do
load_config 'e2e'
end

describe 'deploy without setup' do
it 'exits with an error message' do
expect do
rake.run(['e2e_deploy'])
end.to raise_error(SystemExit)
.and output(output_file('e2e_deploy_without_setup')).to_stdout
end
end

describe 'setup' do
it 'sets up directories' do
expect do
rake.run(['setup'])
end.to output(output_file('e2e_setup')).to_stdout
end
end

describe 'deploy after setup' do
it 'deploys the app' do
expect do
rake.run(['e2e_deploy'])
end.to output(output_file('e2e_deploy_after_setup')).to_stdout
end
end
end
27 changes: 27 additions & 0 deletions spec/e2e/ssh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN OPENSSH PRIVATE KEY-----

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually this isn't safe to keep in repos, but I generated this key just for e2e purposes.

b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn
NhAAAAAwEAAQAAAQEAskzzKcHPV/0n84dIXUKO3q/s4MX8+R+ogsbbEr/XRo0e2BtEmD52
VLEJczYaxICqTOmlOvyx0oWOSPbim6Cpq6YskbxVaUqYSdzafdRXmc3+6BSXgGZH3dHWYc
2vQFx01PVRXdb4EwQBwmCLX7v7+/OxXVq5MHxxXNHblut2c//Udp53F5fVm3WgE3iTIpxL
0h/0H25kaE0HyZrFhFdPItAu/owkOhra6yX1PE8vcyQRs7d9uWwd3n+odCjwhTJ3431PFJ
SyCSTCKbDGMIB44E85e6Vr4EK9Xjrxb6Zrc8ayg4GEX9jqpltjup9vWKhdM7q4vrkEK2uC
lYGurnfEAwAAA8ilS5nwpUuZ8AAAAAdzc2gtcnNhAAABAQCyTPMpwc9X/Sfzh0hdQo7er+
zgxfz5H6iCxtsSv9dGjR7YG0SYPnZUsQlzNhrEgKpM6aU6/LHShY5I9uKboKmrpiyRvFVp
SphJ3Np91FeZzf7oFJeAZkfd0dZhza9AXHTU9VFd1vgTBAHCYItfu/v787FdWrkwfHFc0d
uW63Zz/9R2nncXl9WbdaATeJMinEvSH/QfbmRoTQfJmsWEV08i0C7+jCQ6GtrrJfU8Ty9z
JBGzt325bB3ef6h0KPCFMnfjfU8UlLIJJMIp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ff line number Diff line change
@@ -0,0 +1 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCyTPMpwc9X/Sfzh0hdQo7er+zgxfz5H6iCxtsSv9dGjR7YG0SYPnZUsQlzNhrEgKpM6aU6/LHShY5I9uKboKmrpiyRvFVpSphJ3Np91FeZzf7oFJeAZkfd0dZhza9AXHTU9VFd1vgTBAHCYItfu/v787FdWrkwfHFc0duW63Zz/9R2nncXl9WbdaATeJMinEvSH/QfbmRoTQfJmsWEV08i0C7+jCQ6GtrrJfU8Ty9zJBGzt325bB3ef6h0KPCFMnfjfU8UlLIJJMIpsMYwgHjgTzl7pWvgQr1eOvFvpmtzxrKDgYRf2OqmW2O6n29YqF0zuri+uQQra4KVga6ud8QD mina-e2e-test
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
end

config.after do
Rake.application.instance_variable_get(:@tasks).keep_if { |task_name, _| initial_task_names.include?(task_name) }
Rake.application.tasks.each(&:reenable)
Rake.application.instance_variable_get(:@tasks).keep_if { |task_name, _| initial_task_names.include?(task_name) }
end

config.around(:each, :suppressed_output) do |example|
Expand Down
1 change: 1 addition & 0 deletions spec/support/outputs/e2e_deploy_after_setup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(?m)Cloning the Git repository.*Done\. Deployed version 1
1 change: 1 addition & 0 deletions spec/support/outputs/e2e_deploy_without_setup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The directory '/app/releases' does not exist on the server\.
1 change: 1 addition & 0 deletions spec/support/outputs/e2e_setup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Setting up /app