green_day 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6db900740eb86bf00384ad3f97895ecd146d5f112f96db362c28a28cbfb391f
4
- data.tar.gz: c4f4a09dd97c634b671434735896294c13f5ad3992d97378db3cde64e804efae
3
+ metadata.gz: 971ee30b1f0c5e28050c22c9dad43ec540df4b62a8c98732cc087bd6073264ce
4
+ data.tar.gz: b466d89cbb1b7bf4b80bd4b6e6376c62b6bfab1582e0dacea346ceddd43e4996
5
5
  SHA512:
6
- metadata.gz: 15d1dfd04be33f629ec7f6f74ff7666175e39bd62e3dcb80f2d5ae936c86001ba479db6fe2a084839d7e12fedaede50b3d85c9c65d4ae9c88700127204c4a33e
7
- data.tar.gz: c5e5b31671f907460705f3baac9e9ebc6a0142fb3d2678e1783b3b8a382e266cb06cf4e793a096768632b8451f2925d6968550c32ae5ef355738f3ee23e8153c
6
+ metadata.gz: 89fbaca8563074011b950df0241164a97e0fbb0659126b00cc5a7a04a6cd4169dd0a63ece3d4d245aa19ccbb71421b2841d733bb209e893af48f3c22aeb4db3e
7
+ data.tar.gz: 02bcd53c57dd6c4d73e8871e0943cd494fe700b77ce61603d752f4f2ec4a97653288c9f9e03e4c9d91766d67d399a1647900ccd2ddd7a752d245310151057db4
@@ -0,0 +1,54 @@
1
+ name: Bump version and Push to RubyGems
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ miner-or-major:
7
+ description: 'Minor or major release'
8
+ required: true
9
+ default: 'minor'
10
+ options:
11
+ - 'minor'
12
+ - 'major'
13
+ email:
14
+ description: Your email
15
+ required: true
16
+ type: string
17
+
18
+
19
+ jobs:
20
+ build:
21
+ name: Build + Publish
22
+ runs-on: ubuntu-latest
23
+ permissions:
24
+ packages: write
25
+ contents: read
26
+
27
+ steps:
28
+ - uses: actions/checkout@v3
29
+ - name: Set up Ruby 3.2
30
+ uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: 3.2
33
+
34
+ - run: bundle install
35
+ - run: gem install gem-release
36
+
37
+ - name: config
38
+ run: |
39
+ git config --global user.email ${{ github.event.inputs.email }}
40
+ git config --global user.name ${{ github.actor }}
41
+
42
+ - name: Bump version
43
+ run: gem bump --version ${{ github.event.inputs.miner-or-major }}
44
+
45
+ - name: Publish to RubyGems
46
+ run: |
47
+ mkdir -p $HOME/.gem
48
+ touch $HOME/.gem/credentials
49
+ chmod 0600 $HOME/.gem/credentials
50
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
51
+ gem build *.gemspec
52
+ gem push *.gem
53
+ env:
54
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -11,8 +11,7 @@ jobs:
11
11
  strategy:
12
12
  matrix:
13
13
  ruby-version:
14
- - 2.7.1 # AtCoder公式が使用しているrubyは2.7.1
15
- - 3.1
14
+ - 3.2.1 # Atcoderが採用しているバージョン
16
15
  steps:
17
16
  - uses: actions/checkout@v3
18
17
  - name: Set up Ruby ${{ matrix.ruby-version }}
@@ -33,7 +32,7 @@ jobs:
33
32
  - uses: actions/checkout@v3
34
33
  - uses: ruby/setup-ruby@v1
35
34
  with:
36
- ruby-version: 3.1
35
+ ruby-version: 3.2.1
37
36
  - name: Bundle install
38
37
  run: bundle install
39
38
  - name: Run rubocop
data/Gemfile CHANGED
@@ -4,3 +4,13 @@ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in green_day.gemspec
6
6
  gemspec
7
+
8
+ gem 'bundler', '~> 2.0'
9
+ gem 'codecov'
10
+ gem 'dotenv'
11
+ gem 'rake', '>= 12.3.3'
12
+ gem 'rspec', '~> 3.0'
13
+ gem 'rubocop'
14
+ gem 'rubocop-rake'
15
+ gem 'rubocop-rspec'
16
+ gem 'vcr'
data/green_day.gemspec CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'green_day/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.required_ruby_version = '>= 2.7.1'
8
+ spec.required_ruby_version = '>= 3.2.1'
9
9
  spec.name = 'green_day'
10
10
  spec.executables = ['green_day']
11
11
  spec.version = GreenDay::VERSION
@@ -30,17 +30,6 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency 'faraday'
31
31
  spec.add_dependency 'faraday-cookie_jar'
32
32
  spec.add_dependency 'nokogiri'
33
- spec.add_dependency 'parallel'
34
33
  spec.add_dependency 'thor'
35
- spec.add_dependency 'webrick'
36
- spec.add_development_dependency 'bundler', '~> 2.0'
37
- spec.add_development_dependency 'codecov'
38
- spec.add_development_dependency 'dotenv'
39
- spec.add_development_dependency 'rake', '>= 12.3.3'
40
- spec.add_development_dependency 'rspec', '~> 3.0'
41
- spec.add_development_dependency 'rubocop'
42
- spec.add_development_dependency 'rubocop-rake'
43
- spec.add_development_dependency 'rubocop-rspec'
44
- spec.add_development_dependency 'vcr'
45
34
  spec.metadata['rubygems_mfa_required'] = 'true'
46
35
  end
@@ -2,18 +2,25 @@
2
2
 
3
3
  require 'faraday'
4
4
  require 'faraday-cookie_jar'
5
- require 'webrick/cookie'
6
5
  require 'nokogiri'
7
6
 
8
7
  module GreenDay
9
8
  class AtcoderClient
10
9
  ATCODER_ENDPOINT = 'https://atcoder.jp'
11
10
  COOKIE_FILE_NAME = '.cookie-store'
12
- attr_reader :client, :cookie_jar
11
+ attr_reader :conn, :cookie_jar
12
+
13
+ def self.login(username, password)
14
+ new.login(username, password)
15
+ end
16
+
17
+ def self.get_parsed_body(path)
18
+ new.get_parsed_body(path)
19
+ end
13
20
 
14
21
  def initialize
15
22
  @cookie_jar = create_or_load_cookie_jar
16
- @client = Faraday.new(url: ATCODER_ENDPOINT) do |builder|
23
+ @conn = Faraday.new(url: ATCODER_ENDPOINT) do |builder|
17
24
  builder.use :cookie_jar, jar: cookie_jar
18
25
  builder.request :url_encoded
19
26
  builder.adapter :net_http
@@ -21,17 +28,17 @@ module GreenDay
21
28
  end
22
29
 
23
30
  def get_parsed_body(path)
24
- res = client.get(path)
31
+ res = conn.get(path)
25
32
  Nokogiri::HTML.parse(res.body)
26
33
  end
27
34
 
28
35
  def login(username, password)
29
36
  csrf_token = obtain_atcoder_csrf_token
30
37
 
31
- client.post('/login',
32
- username: username,
33
- password: password,
34
- csrf_token: csrf_token)
38
+ conn.post('/login',
39
+ username:,
40
+ password:,
41
+ csrf_token:)
35
42
 
36
43
  unless login_succeed?
37
44
  ## ex error:Username or Password is incorrect
@@ -56,11 +63,11 @@ module GreenDay
56
63
  end
57
64
 
58
65
  def obtain_atcoder_csrf_token
59
- get_login_response = client.get('/login')
66
+ get_login_response = conn.get('/login')
60
67
  login_html = Nokogiri::HTML.parse(get_login_response.body)
61
68
  login_html.at('input[name="csrf_token"]')['value']
62
69
  rescue StandardError
63
- raise Error, 'cant get_csrf_token'
70
+ raise Error, 'can not get_csrf_token'
64
71
  end
65
72
 
66
73
  def login_succeed?
data/lib/green_day/cli.rb CHANGED
@@ -17,7 +17,7 @@ module GreenDay
17
17
  print 'password:'
18
18
  password = $stdin.noecho { |stdin| stdin.gets(chomp: true) }.tap { puts }
19
19
 
20
- AtcoderClient.new.login(username, password)
20
+ AtcoderClient.login(username, password)
21
21
  puts(
22
22
  "Successfully created #{AtcoderClient::COOKIE_FILE_NAME}"
23
23
  .colorize(:green)
@@ -26,38 +26,36 @@ module GreenDay
26
26
 
27
27
  desc 'new [contest name]', 'create contest workspace and spec'
28
28
  def new(contest_name)
29
- contest = Contest.new(contest_name, AtcoderClient.new)
29
+ contest = Contest.new(contest_name)
30
30
  FileUtils.makedirs("#{contest.name}/spec")
31
31
 
32
- Parallel.each(contest.tasks, in_threads: THREAD_COUNT) do |task|
33
- create_submit_file(task)
34
- create_spec_file(task)
35
- end
32
+ contest.tasks.map do |task|
33
+ create_files_in_thread(task)
34
+ end.each(&:join)
36
35
 
37
36
  puts "Successfully created #{contest.name} directory".colorize(:green)
38
37
  end
39
38
 
40
39
  private
41
40
 
42
- def create_submit_file(task)
43
- File.open(submit_file_path(task), 'w')
41
+ def create_files_in_thread(task)
42
+ Thread.new do
43
+ create_task_file(task)
44
+ create_task_spec_file(task)
45
+ end
44
46
  end
45
47
 
46
- def create_spec_file(task)
47
- test =
48
- TestBuilder.build_test(
49
- submit_file_path(task),
50
- task.sample_answers
51
- )
52
- File.write(spec_file_path(task), test)
48
+ def create_task_file(task)
49
+ FileUtils.touch(task_file_name(task))
53
50
  end
54
51
 
55
- def submit_file_path(task)
56
- "#{task.contest.name}/#{task.name}.rb"
52
+ def create_task_spec_file(task)
53
+ test_content = TestBuilder.build_test(task_file_name(task), task.sample_answers)
54
+ File.write("#{task.contest.name}/spec/#{task.name}_spec.rb", test_content)
57
55
  end
58
56
 
59
- def spec_file_path(task)
60
- "#{task.contest.name}/spec/#{task.name}_spec.rb"
57
+ def task_file_name(task)
58
+ "#{task.contest.name}/#{task.name}.rb"
61
59
  end
62
60
  end
63
61
  end
@@ -1,31 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'forwardable'
4
3
  require_relative 'task'
5
4
 
6
5
  module GreenDay
7
6
  class Contest
8
- extend Forwardable
9
- delegate get_parsed_body: :@client
10
-
11
7
  attr_reader :name, :tasks
12
8
 
13
- def initialize(contest_name, client)
14
- @client = client
9
+ def initialize(contest_name)
15
10
  @name = contest_name
16
11
 
17
- task_names_and_paths = fetch_task_names_and_paths
18
- @tasks =
19
- Parallel.map(task_names_and_paths,
20
- in_threads: THREAD_COUNT) do |task_name, task_path|
21
- Task.new(self, task_name, task_path, @client)
12
+ @tasks = fetch_task_names_and_paths.map.with_index do |(task_name, task_path), i|
13
+ if !i.zero? && (i % 10).zero? && !ENV['CI']
14
+ puts 'Sleeping 2 second to avoid 429 error'
15
+ sleep 2
16
+ end
17
+
18
+ Thread.new do
19
+ Task.new(self, task_name, task_path)
22
20
  end
21
+ end.map(&:value)
23
22
  end
24
23
 
25
24
  private
26
25
 
27
26
  def fetch_task_names_and_paths
28
- body = get_parsed_body("contests/#{name}/tasks")
27
+ body = AtcoderClient.get_parsed_body("contests/#{name}/tasks")
29
28
  task_elements = body.search('tbody tr td:first a')
30
29
 
31
30
  task_elements.to_h do |element|
@@ -1,16 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'forwardable'
4
-
5
3
  module GreenDay
6
4
  class Task
7
- extend Forwardable
8
- delegate get_parsed_body: :@client
9
-
10
5
  attr_reader :contest, :name, :path, :sample_answers
11
6
 
12
- def initialize(contest, name, path, client)
13
- @client = client
7
+ def initialize(contest, name, path)
14
8
  @contest = contest
15
9
  @name = name
16
10
  @path = path
@@ -26,7 +20,7 @@ module GreenDay
26
20
  end
27
21
 
28
22
  def fetch_inputs_and_outputs
29
- body = get_parsed_body(path)
23
+ body = AtcoderClient.get_parsed_body(path)
30
24
  samples = body.css('.lang-ja > .part > section > pre').map { |e| e.children.text }
31
25
 
32
26
  inputs, outputs = samples.partition.with_index { |_sample, i| i.even? }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GreenDay
4
- VERSION = '0.5.0'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: green_day
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - qwyng
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-30 00:00:00.000000000 Z
11
+ date: 2023-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: parallel
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: thor
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -94,146 +80,6 @@ dependencies:
94
80
  - - ">="
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: webrick
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: bundler
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '2.0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '2.0'
125
- - !ruby/object:Gem::Dependency
126
- name: codecov
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: dotenv
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: rake
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: 12.3.3
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: 12.3.3
167
- - !ruby/object:Gem::Dependency
168
- name: rspec
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: '3.0'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "~>"
179
- - !ruby/object:Gem::Version
180
- version: '3.0'
181
- - !ruby/object:Gem::Dependency
182
- name: rubocop
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
- - !ruby/object:Gem::Dependency
196
- name: rubocop-rake
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - ">="
200
- - !ruby/object:Gem::Version
201
- version: '0'
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- version: '0'
209
- - !ruby/object:Gem::Dependency
210
- name: rubocop-rspec
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - ">="
214
- - !ruby/object:Gem::Version
215
- version: '0'
216
- type: :development
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - ">="
221
- - !ruby/object:Gem::Version
222
- version: '0'
223
- - !ruby/object:Gem::Dependency
224
- name: vcr
225
- requirement: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - ">="
228
- - !ruby/object:Gem::Version
229
- version: '0'
230
- type: :development
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- requirements:
234
- - - ">="
235
- - !ruby/object:Gem::Version
236
- version: '0'
237
83
  description: CLI tool for AtCoder and Ruby
238
84
  email:
239
85
  - ikusawasi@gmail.com
@@ -242,7 +88,7 @@ executables:
242
88
  extensions: []
243
89
  extra_rdoc_files: []
244
90
  files:
245
- - ".github/workflows/publish_to_rubygems.yml"
91
+ - ".github/workflows/bump_version_and_push_to_rubygems.yml"
246
92
  - ".github/workflows/ruby.yml"
247
93
  - ".gitignore"
248
94
  - ".rspec"
@@ -278,14 +124,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
278
124
  requirements:
279
125
  - - ">="
280
126
  - !ruby/object:Gem::Version
281
- version: 2.7.1
127
+ version: 3.2.1
282
128
  required_rubygems_version: !ruby/object:Gem::Requirement
283
129
  requirements:
284
130
  - - ">="
285
131
  - !ruby/object:Gem::Version
286
132
  version: '0'
287
133
  requirements: []
288
- rubygems_version: 3.3.7
134
+ rubygems_version: 3.4.10
289
135
  signing_key:
290
136
  specification_version: 4
291
137
  summary: CLI tool for AtCoder and Ruby
@@ -1,31 +0,0 @@
1
- name: Publish to RubyGems
2
-
3
- on:
4
- workflow_dispatch:
5
-
6
- jobs:
7
- build:
8
- name: Build + Publish
9
- runs-on: ubuntu-latest
10
- permissions:
11
- packages: write
12
- contents: read
13
-
14
- steps:
15
- - uses: actions/checkout@v3
16
- - name: Set up Ruby 3.1
17
- uses: ruby/setup-ruby@v1
18
- with:
19
- ruby-version: 3.1
20
- - run: bundle install
21
-
22
- - name: Publish to RubyGems
23
- run: |
24
- mkdir -p $HOME/.gem
25
- touch $HOME/.gem/credentials
26
- chmod 0600 $HOME/.gem/credentials
27
- printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
28
- gem build *.gemspec
29
- gem push *.gem
30
- env:
31
- GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"