Skip to content

Commit 27dea30

Browse files
authored
Merge pull request #10 from doximity/setup-ci
Setup CI and Gem Publishing + better form validation
2 parents ae776ac + 80f93a3 commit 27dea30

18 files changed

+351
-85
lines changed

.circleci/config.yml

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
---
2+
3+
version: 2.1
4+
5+
orbs:
6+
gem: doximity/gem-publisher@0
7+
8+
executors:
9+
ruby-latest:
10+
resource_class: small
11+
docker:
12+
- image: circleci/ruby:2.7.2
13+
environment:
14+
BUNDLE_VERSION: "~> 2.2.8"
15+
16+
# yaml anchor filters
17+
master_only: &master_only
18+
filters:
19+
branches:
20+
only: master
21+
tags:
22+
ignore: /.*/
23+
pr_only: &pr_only
24+
filters:
25+
branches:
26+
ignore: master
27+
tags:
28+
ignore: /.*/
29+
version_tags_only: &version_tags_only
30+
filters:
31+
branches:
32+
ignore: /.*/
33+
tags:
34+
only: /^v.*/
35+
36+
jobs:
37+
build:
38+
executor: ruby-latest
39+
steps:
40+
- checkout
41+
- run:
42+
name: Install Bundler specific version
43+
command: |
44+
gem install bundler --version "${BUNDLE_VERSION}" --force
45+
- restore_cache:
46+
keys:
47+
- v1-bundle-{{ checksum "Gemfile.lock" }}-
48+
- run:
49+
name: Install Bundler specific version
50+
command: |
51+
gem install bundler --version "~> 1.17" --force
52+
- run:
53+
name: Install Ruby Dependencies
54+
command: bundle check --path=vendor/bundle || bundle install
55+
- save_cache:
56+
key: v1-bundle-{{ checksum "Gemfile.lock" }}-
57+
paths:
58+
- vendor/bundle
59+
- run:
60+
name: Run Tests
61+
command: bundle exec rake test
62+
- store_test_results:
63+
name: Store test results
64+
path: tmp/test-results
65+
- run:
66+
name: Run StandardRB
67+
command: bundle exec standardrb
68+
- store_artifacts:
69+
name: Saves documentation
70+
path: doc
71+
- persist_to_workspace:
72+
root: .
73+
paths:
74+
- vendor/bundle
75+
76+
workflows:
77+
version: 2
78+
79+
pull-requests:
80+
jobs:
81+
- build:
82+
<<: *pr_only
83+
- gem/build:
84+
executor: ruby-latest
85+
requires:
86+
- build
87+
- pre-release-approval:
88+
type: approval
89+
requires:
90+
- gem/build
91+
- gem/publish:
92+
to_nexus: true
93+
pre_release: true
94+
requires:
95+
- pre-release-approval
96+
context: artifact_publishing
97+
98+
trunk:
99+
jobs:
100+
- build:
101+
<<: *master_only
102+
- gem/build:
103+
executor: ruby-latest
104+
requires:
105+
- build
106+
107+
final-release:
108+
jobs:
109+
- build:
110+
<<: *version_tags_only
111+
- gem/build:
112+
<<: *version_tags_only
113+
executor: ruby-latest
114+
requires:
115+
- build
116+
- gem/publish:
117+
<<: *version_tags_only
118+
name: gem-publish
119+
to_rubygems: true
120+
pre_release: false
121+
requires:
122+
- gem/build
123+
context: artifact_publishing

CHANGELOG.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased]
7+
## [0.0.1]
8+
* Setup CI and Gem Publishing, add better form Validations
9+
[#10](https://github.com/doximity/rake-ui/pull/10)
10+
* Add Search Filtering, Remove Jbuilder and Fix Bug in Dir Existing
11+
[#12](https://github.com/doximity/rake-ui/pull/12)
12+
* Add StandardRB
13+
[#10](https://github.com/doximity/rake-ui/pull/11)
14+
* Fix But with FILE_ITEM_SEPARATOR reference
15+
[#9](https://github.com/doximity/rake-ui/pull/9)
16+
* Add View for Rake Task Logs
17+
[#8](https://github.com/doximity/rake-ui/pull/8)
18+
* Add VitalCSS
19+
[#7](https://github.com/doximity/rake-ui/pull/7)
20+
* Add Ability to track task execution status
21+
[#6](https://github.com/doximity/rake-ui/pull/6)
22+
* Add RakeTaskLog model
23+
[#4](https://github.com/doximity/rake-ui/pull/4)
24+
* Add ability to execute a RakeTask
25+
[#3](https://github.com/doximity/rake-ui/pull/3)
26+
* Add RakeTask Model
27+
[#2](https://github.com/doximity/rake-ui/pull/2)
828
* Initialize Rake UI Engine
929
[#1](https://github.com/doximity/rake-ui/pull/1)

Gemfile.lock

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
rake-ui (0.1.0)
4+
rake-ui (0.0.1)
55
actionpack
66
activesupport
77
railties
@@ -65,6 +65,7 @@ GEM
6565
minitest (~> 5.1)
6666
tzinfo (~> 1.1)
6767
zeitwerk (~> 2.2, >= 2.2.2)
68+
ast (2.4.2)
6869
builder (3.2.4)
6970
coderay (1.1.3)
7071
concurrent-ruby (1.1.8)
@@ -92,6 +93,9 @@ GEM
9293
racc (~> 1.4)
9394
nokogiri (1.11.1-x86_64-linux)
9495
racc (~> 1.4)
96+
parallel (1.20.1)
97+
parser (3.0.0.0)
98+
ast (~> 2.4.1)
9599
pry (0.13.1)
96100
coderay (~> 1.1)
97101
method_source (~> 1.0)
@@ -125,7 +129,25 @@ GEM
125129
method_source
126130
rake (>= 0.8.7)
127131
thor (>= 0.20.3, < 2.0)
132+
rainbow (3.0.0)
128133
rake (13.0.3)
134+
regexp_parser (2.0.3)
135+
rexml (3.2.4)
136+
rubocop (1.8.1)
137+
parallel (~> 1.10)
138+
parser (>= 3.0.0.0)
139+
rainbow (>= 2.2.2, < 4.0)
140+
regexp_parser (>= 1.8, < 3.0)
141+
rexml
142+
rubocop-ast (>= 1.2.0, < 2.0)
143+
ruby-progressbar (~> 1.7)
144+
unicode-display_width (>= 1.4.0, < 3.0)
145+
rubocop-ast (1.4.1)
146+
parser (>= 2.7.1.5)
147+
rubocop-performance (1.9.2)
148+
rubocop (>= 0.90.0, < 2.0)
149+
rubocop-ast (>= 0.4.0)
150+
ruby-progressbar (1.11.0)
129151
sprockets (4.0.2)
130152
concurrent-ruby (~> 1.0)
131153
rack (> 1, < 3)
@@ -134,10 +156,16 @@ GEM
134156
activesupport (>= 4.0)
135157
sprockets (>= 3.0.0)
136158
sqlite3 (1.4.2)
159+
standard (0.12.0)
160+
rubocop (= 1.8.1)
161+
rubocop-performance (= 1.9.2)
162+
standardrb (1.0.0)
163+
standard
137164
thor (1.1.0)
138165
thread_safe (0.3.6)
139166
tzinfo (1.2.9)
140167
thread_safe (~> 0.1)
168+
unicode-display_width (2.0.0)
141169
websocket-driver (0.7.3)
142170
websocket-extensions (>= 0.1.0)
143171
websocket-extensions (0.1.5)
@@ -152,6 +180,7 @@ DEPENDENCIES
152180
rails
153181
rake-ui!
154182
sqlite3
183+
standardrb
155184

156185
BUNDLED WITH
157186
2.2.8

README.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ Rake UI is a Rails engine that enables the discovery and execution rake tasks in
55
Add this line to your application's Gemfile:
66

77
```ruby
8-
gem 'rake-ui'
8+
group :development do
9+
gem 'rake-ui'
10+
end
911
```
1012

1113
And then execute:
@@ -21,10 +23,21 @@ $ gem install rake-ui
2123
once it is installed, mount the engine
2224
```rb
2325
Rails.application.routes.draw do
24-
mount RakeUi::Engine => "/rake-ui"
26+
# only mounting when defined will allow us only include in development/test
27+
if defined? RakeUi::Engine
28+
mount RakeUi::Engine => "/rake-ui"
29+
end
2530
end
2631
```
2732

33+
### Securing RakeUi
34+
35+
This tool is built to enable developer productivity in development. It exposes rake tasks through a UI.
36+
37+
This tool will currently not work in production because we add a guard in the root controller to respond not found if the environment is development or test.
38+
39+
We recommend adding guards in your route to ensure that the proper authentication is in place to ensure that users are authenticated so that if this were ever to be rendered in production, you would be covered. The best way for that is [router constraints](https://guides.rubyonrails.org/routing.html#specifying-constraints)
40+
2841
## Testing
2942

3043
`bundle exec rake test`

app/controllers/rake_ui/application_controller.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
module RakeUi
44
class ApplicationController < ActionController::Base
5-
before_action :guard_not_production
5+
before_action :black_hole_production
66

77
private
88

9-
def guard_not_production
10-
respond :unauthorized unless Rails.env.test? || Rails.env.development?
9+
def black_hole_production
10+
raise ActionController::RoutingError, "Not Found" unless Rails.env.test? || Rails.env.development?
1111
end
1212
end
1313
end

app/models/rake_ui/rake_task.rb

+15-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@
22

33
module RakeUi
44
class RakeTask
5+
def self.to_safe_identifier(id)
6+
CGI.escape(id)
7+
end
8+
9+
def self.from_safe_identifier(id)
10+
CGI.unescape(id)
11+
end
12+
513
def self.load
14+
# Enables 'desc' to show up as full_comments
15+
if Rake::TaskManager.respond_to? :record_task_metadata
16+
Rake::TaskManager.record_task_metadata = true
17+
end
18+
619
Rails.application.load_tasks
720
Rake::Task.tasks
821
end
@@ -21,7 +34,7 @@ def self.internal
2134

2235
def self.find_by_id(id)
2336
t = all
24-
i = CGI.unescape(id)
37+
i = from_safe_identifier(id)
2538

2639
t.find do |task|
2740
task.name == i
@@ -36,7 +49,7 @@ def initialize(task)
3649
end
3750

3851
def id
39-
CGI.escape(name)
52+
RakeUi::RakeTask.to_safe_identifier(name)
4053
end
4154

4255
# actions will be something like #<Proc:0x000055a2737fe778@/some/rails/app/lib/tasks/auto_annotate_models.rake:4>

app/models/rake_ui/rake_task_log.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def self.all
7474

7575
def self.find_by_id(id)
7676
all.find do |a|
77-
a.id == id || a.id == CGI.escape(id)
77+
a.id == id || a.id == RakeUi::RakeTask.to_safe_identifier(id)
7878
end
7979
end
8080

@@ -139,7 +139,7 @@ def parsed_log_file_name
139139
@parsed_log_file_name ||= {}.tap do |parsed|
140140
date, name = id.split(FILE_DELIMITER, 2)
141141
parsed[:date] = date
142-
parsed[:name] = CGI.unescape(name)
142+
parsed[:name] = RakeUi::RakeTask.from_safe_identifier(name)
143143
end
144144
end
145145

0 commit comments

Comments
 (0)