Skip to content

Commit fc741ae

Browse files
committed
Adding CI for linting, testing and security checks
1 parent aa5b406 commit fc741ae

File tree

3 files changed

+201
-0
lines changed

3 files changed

+201
-0
lines changed

.github/workflows/ci-simple.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CI Simple
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
branches:
10+
- main
11+
- master
12+
13+
jobs:
14+
test-and-lint:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Ruby
21+
uses: ruby/setup-ruby@v1
22+
with:
23+
ruby-version: '3.3'
24+
bundler-version: '2.4'
25+
bundler-cache: true
26+
27+
- name: Install dependencies
28+
run: bundle install
29+
30+
- name: Run tests
31+
run: bundle exec rake test
32+
33+
- name: Run RuboCop
34+
run: bundle exec rake rubocop
35+
36+
- name: Build gem
37+
run: bundle exec rake build

.github/workflows/ci.yml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
# Cancel previous workflows on previous push
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
12+
cancel-in-progress: true
13+
14+
# Global environment variables
15+
env:
16+
RUBY_VERSION: '3.3'
17+
BUNDLER_VERSION: '2.7'
18+
19+
jobs:
20+
test:
21+
runs-on: ubuntu-latest
22+
strategy:
23+
matrix:
24+
ruby-version: ['3.2', '3.3', '3.4']
25+
bundler-version: ${{ env.BUNDLER_VERSION }}
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
- name: Set up Ruby
32+
uses: ruby/setup-ruby@v1
33+
with:
34+
ruby-version: ${{ matrix.ruby-version }}
35+
bundler-version: ${{ matrix.bundler-version }}
36+
bundler-cache: true
37+
38+
- name: Install dependencies
39+
run: |
40+
bundle install
41+
42+
- name: Build gem
43+
run: |
44+
bundle exec rake build
45+
46+
- name: Run tests
47+
run: |
48+
bundle exec rake test
49+
50+
lint:
51+
runs-on: ubuntu-latest
52+
steps:
53+
- name: Checkout repository
54+
uses: actions/checkout@v4
55+
56+
- name: Set up Ruby
57+
uses: ruby/setup-ruby@v1
58+
with:
59+
ruby-version: ${{ env.RUBY_VERSION }}
60+
bundler-version: ${{ env.BUNDLER_VERSION }}
61+
bundler-cache: true
62+
63+
- name: Install dependencies
64+
run: |
65+
bundle install
66+
67+
- name: Run RuboCop with auto-correct
68+
run: |
69+
bundle exec rake rubocop:autocorrect
70+
71+
# TODO: Uncomment this when we have a way a fix for all RuboCop violations
72+
# - name: Check for RuboCop violations
73+
# run: |
74+
# bundle exec rubocop --fail-level W
75+
76+
- name: Ensure no changes to git-tracked files
77+
run: git --no-pager diff --exit-code
78+
79+
security:
80+
runs-on: ubuntu-latest
81+
steps:
82+
- name: Checkout repository
83+
uses: actions/checkout@v4
84+
85+
- name: Set up Ruby
86+
uses: ruby/setup-ruby@v1
87+
with:
88+
ruby-version: ${{ env.RUBY_VERSION }}
89+
bundler-version: ${{ env.BUNDLER_VERSION }}
90+
bundler-cache: true
91+
92+
- name: Install dependencies
93+
run: |
94+
bundle install
95+
96+
- name: Run bundle audit
97+
run: |
98+
bundle exec bundle audit check --update
99+
100+
gem-publish:
101+
runs-on: ubuntu-latest
102+
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
103+
needs: [test, lint, security]
104+
steps:
105+
- name: Checkout repository
106+
uses: actions/checkout@v4
107+
with:
108+
fetch-depth: 0
109+
110+
- name: Set up Ruby
111+
uses: ruby/setup-ruby@v1
112+
with:
113+
ruby-version: ${{ env.RUBY_VERSION }}
114+
bundler-version: ${{ env.BUNDLER_VERSION }}
115+
bundler-cache: true
116+
117+
- name: Install dependencies
118+
run: |
119+
bundle install
120+
121+
- name: Build gem
122+
run: |
123+
bundle exec rake build
124+
125+
# TODO: Uncomment this when we are ready to publish to RubyGems
126+
# - name: Publish to RubyGems
127+
# run: |
128+
# gem push pkg/*.gem
129+
# env:
130+
# RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}

.github/workflows/setup-ruby.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Setup Ruby Environment
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
ruby-version:
7+
description: 'Ruby version to use'
8+
required: false
9+
default: '3.3'
10+
type: string
11+
bundler-version:
12+
description: 'Bundler version to use'
13+
required: false
14+
default: '2.4'
15+
type: string
16+
outputs:
17+
ruby-version:
18+
description: 'The Ruby version that was set up'
19+
value: ${{ steps.setup-ruby.outputs.ruby-version }}
20+
21+
jobs:
22+
setup:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Set up Ruby
26+
id: setup-ruby
27+
uses: ruby/setup-ruby@v1
28+
with:
29+
ruby-version: ${{ inputs.ruby-version }}
30+
bundler-version: ${{ inputs.bundler-version }}
31+
bundler-cache: true
32+
33+
- name: Install dependencies
34+
run: bundle install

0 commit comments

Comments
 (0)