Ruby Pipeline
A ready-to-use GitLab CI Pipeline and Jobs for Ruby projects.
๐ Usage
Quick start:
import { GitLab } from "https://deno.land/x/ruby_pipeline/mod.ts";
const { pipeline } = GitLab;
pipeline.write(); // Write the pipeline to the file .gitlab-ci.yml
Or, if you want to use the predefined jobs:
import { GitlabCI } from "https://deno.land/x/fluent_gitlab_ci@v0.3.2/mod.ts";
import { GitLab } from "https://deno.land/x/ruby_pipeline/mod.ts";
const { herokuDeploy, rails, rspec, rubocop } = GitLab;
const gitlabci = new GitlabCI()
.image("ruby:latest")
.services(["mysql:latest", "redis:latest", "postgres:latest"])
.variables({
POSTGRES_DB: "database_name",
})
.cache(["vendor/ruby"])
.beforeScript(
`
ruby -v
bundle config set --local deployment true
bundle install -j $(nproc)
`
)
.addJob("rubocop", rubocop)
.addJob("rails", rails)
.addJob("rspec", rspec)
.addJob("heroku_deploy", herokuDeploy);
pipeline.write(); // Write the pipeline to the file .gitlab-ci.yml
It will generate the following .gitlab-ci.yml
file:
# Do not edit this file directly. It is generated by Fluent GitLab CI
image: ruby:latest
services:
- mysql:latest
- redis:latest
- postgres:latest
variables:
POSTGRES_DB: database_name
cache:
paths:
- vendor/ruby
before_script:
- ruby -v
- bundle config set --local deployment true
- bundle install -j $(nproc)
rubocop:
script:
- rubocop
rails:
variables:
DATABASE_URL: postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB
script:
- rails db:migrate
- rails db:seed
- rails test
rspec:
script:
- rspec spec
heroku_deploy:
stage: deploy
environment: production
script:
- gem install dpl
- dpl --provider=heroku --app=$HEROKU_APP_NAME --api-key=$HEROKU_PRODUCTION_KEY
๐งช Advanced Usage
This package also provides a ready-to-use pipeline for Dagger, just run the following command on your Ruby project:
dagger run deno run -A https://deno.land/x/ruby_pipeline/ci.ts
Or, if you want to use the predefined jobs:
import Client, { connect } from "@dagger.io/dagger";
import { Dagger } from "https://deno.land/x/ruby_pipeline/mod.ts";
const { rubocop, rails, rspec, herokuDeploy } = Dagger;
function pipeline(src = ".") {
connect(async (client: Client) => {
await rubocop(client, src);
await rails(client, src);
await rspec(client, src);
await herokuDeploy(client, src);
});
}
pipeline();