-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ruby stack first implementation
Add first implementation of a Ruby stack using Rubocop as the linter Resolves: #60
- Loading branch information
1 parent
afed003
commit 3ff6a3e
Showing
15 changed files
with
415 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
cli/tests/fixtures/ruby/rubocop-lint/expected/.github/workflows/pipelinit.ruby.lint.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated with pipelinit 0.2.2 | ||
# https://pipelinit.com/ | ||
name: Lint Ruby | ||
on: | ||
pull_request: | ||
paths: | ||
- "**.rb" | ||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: "2.5.0" | ||
bundler-cache: true | ||
- run: bundle exec rubocop --lint . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
platforms = ["github"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source "https://rubygems.org" | ||
|
||
gemspec | ||
|
||
gem 'rubocop', '~> 0.57.2', require: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
main (0.3.1) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
ast (2.4.2) | ||
jaro_winkler (1.5.4) | ||
parallel (1.21.0) | ||
parser (3.0.2.0) | ||
ast (~> 2.4.1) | ||
powerpack (0.1.3) | ||
rainbow (2.2.2) | ||
rake | ||
rake (10.5.0) | ||
rubocop (0.57.2) | ||
jaro_winkler (~> 1.5.1) | ||
parallel (~> 1.10) | ||
parser (>= 2.5) | ||
powerpack (~> 0.1) | ||
rainbow (>= 2.2.2, < 4.0) | ||
ruby-progressbar (~> 1.7) | ||
unicode-display_width (~> 1.0, >= 1.0.1) | ||
ruby-progressbar (1.11.0) | ||
unicode-display_width (1.8.0) | ||
|
||
PLATFORMS | ||
ruby | ||
x86_64-linux | ||
|
||
DEPENDENCIES | ||
bundler (>= 1.16) | ||
main! | ||
rubocop (~> 0.57.2) | ||
|
||
BUNDLED WITH | ||
2.2.30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# test-ruby-pipelinit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'main/version' | ||
require 'main/hash' | ||
require 'main/script' | ||
require 'main/report' | ||
require 'main/config' | ||
require 'main/cli' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'main' | ||
spec.version = '0.3.1' | ||
spec.author = 'pipelinit' | ||
|
||
spec.required_ruby_version = '>= 2.5.0' | ||
|
||
spec.summary = 'Aplicação para gerar' | ||
spec.description = 'Aplicação para gerar' | ||
|
||
spec.add_development_dependency 'bundler', '>= 1.16' | ||
spec.add_development_dependency 'rubocop', '~> 1.22' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Context } from "../../../types.ts"; | ||
|
||
const rubyDepRegex = /(?:(["'])(?<DependencyName>[a-zA-Z\-_\.]+)["'])/gm; | ||
|
||
function notEmpty<TValue>(value: TValue | null | undefined): value is TValue { | ||
return value !== null && value !== undefined; | ||
} | ||
|
||
const readDependencyFile = async (context: Context) => { | ||
for await (const file of await context.files.each("**/Gemfile")) { | ||
const rubyDepsText = await context.files.readText(file.path); | ||
|
||
const depsRuby: string[] = Array.from( | ||
rubyDepsText.matchAll(rubyDepRegex), | ||
(match) => !match.groups ? null : match.groups.DependencyName, | ||
).filter(notEmpty); | ||
|
||
if (depsRuby) { | ||
return depsRuby; | ||
} | ||
} | ||
return []; | ||
}; | ||
|
||
export const hasRubyDependency = async ( | ||
context: Context, | ||
dependencyName: string, | ||
): Promise<boolean> => { | ||
const dependencies = await readDependencyFile(context); | ||
return dependencies.some((dep) => dep === dependencyName); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { IntrospectFn } from "../../../types.ts"; | ||
import { introspect as introspectRubocop, Rubocop } from "./rubocop.ts"; | ||
|
||
export type Linters = { | ||
rubocop?: Rubocop; | ||
}; | ||
|
||
export const introspect: IntrospectFn<Linters> = async (context) => { | ||
const linters: Linters = {}; | ||
const logger = context.getLogger("ruby"); | ||
|
||
const rubocopInfo = await introspectRubocop(context); | ||
if (rubocopInfo) { | ||
logger.debug("detected Rubocop"); | ||
linters.rubocop = rubocopInfo; | ||
} else { | ||
if (context.suggestDefault) { | ||
logger.warning( | ||
"No linters for ruby were identified in the project, creating default pipeline with 'Rubocop' WITHOUT any specific configuration", | ||
); | ||
linters.rubocop = { | ||
isDependency: false, | ||
name: "rubocop", | ||
}; | ||
} | ||
} | ||
|
||
return linters; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Introspector } from "../../../types.ts"; | ||
import { introspect as introspectVersion } from "./version.ts"; | ||
import { introspect as introspectLinters, Linters } from "./linters.ts"; | ||
|
||
/** | ||
* Introspected information about a project with Ruby | ||
*/ | ||
export default interface RubyProject { | ||
/** | ||
* Ruby version | ||
*/ | ||
version?: string; | ||
/** | ||
* Which linter the project uses, if any | ||
*/ | ||
linters: Linters; | ||
} | ||
|
||
export const introspector: Introspector<RubyProject | undefined> = { | ||
detect: async (context) => { | ||
return await context.files.includes("**/*.rb"); | ||
}, | ||
introspect: async (context) => { | ||
const logger = context.getLogger("ruby"); | ||
|
||
// Version | ||
logger.debug("detecting version"); | ||
const version = await introspectVersion(context); | ||
if (version === undefined) { | ||
logger.debug("didn't detect the version"); | ||
return undefined; | ||
} | ||
logger.debug(`detected version ${version}`); | ||
|
||
// Linters and Formatters | ||
const linters = await introspectLinters(context); | ||
|
||
return { | ||
version: version, | ||
linters: linters, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { IntrospectFn } from "../../../types.ts"; | ||
import { hasRubyDependency } from "./dependencies.ts"; | ||
|
||
export interface Rubocop { | ||
name: "rubocop"; | ||
isDependency: boolean; | ||
} | ||
|
||
export const introspect: IntrospectFn<Rubocop | null> = async (context) => { | ||
const isDependency = await hasRubyDependency(context, "rubocop"); | ||
// Search for any of the following files: | ||
// .rubocop.yml | ||
// Reference: https://docs.rubocop.org/rubocop/configuration.html#config-file-locations | ||
const hasRubocopConfig = await context.files.includes( | ||
"**/.rubocop.yml", | ||
); | ||
|
||
if (hasRubocopConfig) { | ||
return { | ||
name: "rubocop", | ||
isDependency: isDependency, | ||
}; | ||
} else if (isDependency) { | ||
return { | ||
name: "rubocop", | ||
isDependency: true, | ||
}; | ||
} | ||
|
||
return null; | ||
}; |
Oops, something went wrong.