Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take screenshots during system tests, upload to Google Cloud storage, and append to Dangerbot output #5320

Closed
wants to merge 57 commits into from
Closed
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
cd852cf
Create screenshots_test
jywarren Mar 31, 2019
05d3f19
Rename screenshots_test to screenshots_test.rb
jywarren Mar 31, 2019
c217fcc
Update screenshots_test.rb
jywarren Mar 31, 2019
3d2b068
Update Dangerfile
jywarren Mar 31, 2019
4394add
relative path to screenshots
jywarren Mar 31, 2019
97667d8
Update Dangerfile
jywarren Mar 31, 2019
f8eecc1
gem "google-cloud-storage"
jywarren Mar 31, 2019
79981f6
try assert_select "ul.dropdown-menu li", count: 2
jywarren Apr 1, 2019
d871f8e
attempt gcloud upload
jywarren Apr 1, 2019
9ea5c1e
file.acl.public!
jywarren Apr 1, 2019
ee6d328
Update Dangerfile
jywarren Apr 1, 2019
d1da598
Also trying to comment out require "google/cloud/storage" to see if t…
jywarren Apr 1, 2019
548d712
Update Dangerfile
jywarren Apr 1, 2019
e900013
gem install google-cloud-storage
jywarren Apr 13, 2019
3197cd9
Run danger inside container
icarito Apr 15, 2019
fd99dce
Install Danger into container
icarito Apr 15, 2019
a005d89
Bundle exec danger
icarito Apr 15, 2019
6b87b2a
Not bundle exec danger
icarito Apr 15, 2019
faa039a
try system("bundle install")
jywarren Apr 16, 2019
081de73
Update Dangerfile
jywarren Apr 16, 2019
ba69f0d
add -e DANGER_GITHUB_API_TOKEN=$DANGER_GITHUB_API_TOKEN
jywarren Apr 16, 2019
3b3f7f3
Add Danger environment variable
icarito Apr 17, 2019
ef37820
Try adding back docker-compose -e
icarito Apr 17, 2019
b79d1a4
Put env variable before docker-compose command
icarito Apr 17, 2019
d988a83
Add many env vars
icarito Apr 17, 2019
e29fc4b
And even more env variables
icarito Apr 17, 2019
1c2cb58
add google-cloud-storage to .travis.yml step
jywarren May 5, 2019
0d02277
GOOGLE_CLOUD_KEYFILE_JSON in docker compose
jywarren May 5, 2019
5ee7ec9
Update .travis.yml
jywarren May 5, 2019
8606dfd
GOOGLE_APPLICATION_CREDENTIALS
jywarren May 5, 2019
6b074e2
put GOOGLE_APPLICATION_CREDENTIALS into a json file, change val to path
jywarren May 5, 2019
b391311
Update Dangerfile
jywarren May 5, 2019
11d5821
Update screenshots_test.rb
jywarren May 5, 2019
880326e
Update .travis.yml
jywarren May 5, 2019
ccad841
test echo JSON_TEST
jywarren May 5, 2019
3932a10
Update Dangerfile
jywarren May 6, 2019
590b580
Update Dangerfile
jywarren May 7, 2019
5875cd4
Merge branch 'master' into screenshot-test
jywarren May 22, 2019
2e65bef
Pass missing var
icarito May 25, 2019
36a9830
Fix yaml
icarito May 25, 2019
01cadf6
Missing ]
icarito May 25, 2019
ed8e5e2
Run danger in container
icarito May 25, 2019
234353b
Remove JSON test
icarito May 25, 2019
71443ac
Remove json test
icarito May 25, 2019
ef7bd7c
Pass on env var for phantomjs
icarito May 26, 2019
dae7a65
Avoid processing `.` or `..` screenshots
icarito Jun 8, 2019
734ac34
Use Dir.glob instead of Dir.foreach
icarito Jun 8, 2019
2395274
Convert issue number to string
icarito Jun 8, 2019
0aa9c20
add ".png"
jywarren Jun 10, 2019
508f133
change puts to message and output only file.name and file.public_url
jywarren Jun 10, 2019
a32d000
Update Dangerfile
jywarren Jun 10, 2019
4f65112
remove true emoji
jywarren Jun 10, 2019
442b96d
Update Dangerfile
jywarren Jun 10, 2019
b784006
Encoding.default_external = 'UTF-8'
jywarren Jun 10, 2019
53d2f28
Update Dangerfile
jywarren Jun 10, 2019
bcbecce
item.split('/').last
jywarren Jun 10, 2019
cb5a489
Update screenshots_test.rb
jywarren Jun 10, 2019
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
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@ install:
- docker-compose exec web bash -c "rake db:setup"
- docker-compose exec web bash -c "rake db:migrate"
- docker-compose exec web bash -c "rake assets:precompile"
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then gem install danger danger-junit; fi'
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash -c "docker-compose exec web gem install danger danger-junit google-cloud-storage"; fi'

script:
- docker-compose exec web bash -c 'echo "$GOOGLE_APPLICATION_CREDENTIALS_JSON" > /tmp/credentials.json' # needs to be a path to a json file, so we shuffle...
- docker-compose exec web bash -c "CI=TRUE GENERATE_REPORT=true $TASK"
- |
if [ $TASK != "rake test:all" ]; then
- if [ $TASK != "rake test:all" ]; then
echo -e '<?xml version="1.0" encoding="UTF-8"?>' > output.xml;
tail -n +2 -q ./test/reports/TEST*.xml >> output.xml;
fi
- |
if [ $TRAVIS_PULL_REQUEST != "false"; then
danger --verbose;
- if [ $TRAVIS_PULL_REQUEST != "false" ]; then
docker-compose exec web danger --verbose;
fi
17 changes: 17 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,20 @@ rescue => ex
fail "There was an error with Danger bot's Junit parsing: #{ex.message}"
message ex.inspect # view the entire error output in the log
end

# Store screenshots in Google Cloud
require "google/cloud/storage"
storage = Google::Cloud::Storage.new project_id: "public-lab"
bucket = storage.bucket "plots2-screenshots"
Encoding.default_external = 'UTF-8'
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Encoding.default_internal = Encoding::UTF_8

Copy link
Member

Choose a reason for hiding this comment

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

Ruby 2.0 and above: default string encoding is UTF-8.

Thus, if you use Ruby 2.0, you could skip the encoding comment and correctly assume UTF-8 encoding everywhere by default.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes maybe as a follow-up?


images = []
Dir.glob('tmp/screenshots/*') do |item|
file = bucket.create_file item, github.pr_json["number"].to_s + "-" + images.length.to_s + ".png"
file.acl.public!
message "Uploaded #{file.name} at #{file.public_url} from #{item.inspect}"
images << "<h3>#{file.name}</h3><p><img src='#{file.public_url}' /></p>"
end

screenshots = "<details><summary>Screenshots :camera_flash: (click to expand)</summary>" + images.join + "</details>"
markdown(screenshots)
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gem 'gemoji'
gem 'geocoder'
gem 'geokit-rails'
gem 'georuby', '2.0'
gem "google-cloud-storage"
gem 'grape'
gem 'grape-entity'
gem 'grape-swagger', '~> 0.32.1'
Expand Down
16 changes: 16 additions & 0 deletions containers/docker-compose-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ services:
- RAILS_ENV=${RAILS_ENV}
- SECRET_KEY_BASE=${SECRET_KEY_BASE}
- REDIS_URL=redis://redis:6379/0
- DANGER_GITHUB_API_TOKEN=${DANGER_GITHUB_API_TOKEN}
- TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST}
- TRAVIS_REPO_SLUG=${TRAVIS_REPO_SLUG}
- CI=${CI}
- TRAVIS=${TRAVIS}
- CONTINUOUS_INTEGRATION=${CONTINUOUS_INTEGRATION}
- HAS_JOSH_K_SEAL_OF_APPROVAL=${HAS_JOSH_K_SEAL_OF_APPROVAL}
Copy link
Member Author

Choose a reason for hiding this comment

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

Lol ummmmm

- GITHUB_ACTION=${GITHUB_ACTION}
- GITHUB_TOKEN=${GITHUB_TOKEN}
- GITHUB_REPOSITORY=${GITHUB_REPOSITORY}
- GITHUB_EVENT_PATH=${GITHUB_EVENT_PATH}
- GITHUB_EVENT_NAME=${GITHUB_EVENT_NAME}
- GOOGLE_CLOUD_KEYFILE_JSON=${GOOGLE_CLOUD_KEYFILE_JSON}
Copy link
Member Author

Choose a reason for hiding this comment

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

- GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS}
- GOOGLE_APPLICATION_CREDENTIALS_JSON=${GOOGLE_APPLICATION_CREDENTIALS_JSON}
- QT_QPA_PLATFORM=${QT_QPA_PLATFORM}
links:
- redis
volumes:
Expand Down
17 changes: 17 additions & 0 deletions test/system/screenshots_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "application_system_test_case"
# https://guides.rubyonrails.org/testing.html#implementing-a-system-test

class ScreenshotsTest < ApplicationSystemTestCase
test 'front page with navbar search autocomplete' do
visit '/'

fill_in("searchform_input", with: "Canon")

take_screenshot # remove this later
# we set RAILS_SYSTEM_TESTING_SCREENSHOT to 'inline', could be 'artifact' too... see Rails API guide

assert_selector ".typeahead li", text: "Canon A1200 IR conversion at PLOTS Barnraising at LUMCON", wait: 10

take_screenshot
end
end