Skip to content

Commit

Permalink
Update CI pipeline, add Depfu configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
otherguy committed Apr 22, 2024
1 parent 097f3fb commit 69409df
Show file tree
Hide file tree
Showing 19 changed files with 374 additions and 190 deletions.
212 changes: 157 additions & 55 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,174 @@
---
version: 2

base_job: &base_job
steps:
- checkout
version: 2.1

- restore_cache:
keys:
- v1-dependencies-{{ checksum "Gemfile.lock" }}
# Used Orbs (https://circleci.com/docs/2.0/using-orbs/)
orbs:
ruby: circleci/[email protected]
sonarcloud: sonarsource/[email protected]

- run:
name: install dependencies
command: |
gem install bundler --version '~> 2.0'
bundle config set path vendor/bundle
bundle install --jobs=4 --retry=3
# Pipeline parameters
parameters:
# The main branch of the repository (e.g. main)
main-branch:
type: string
default: main
default-ruby:
type: string
default: "3.3"

- run:
name: install image processsing dependencies
command: |
sudo apt-get update
sudo apt install imagemagick libvips
# Define common YAML anchors
x-common-auth: &common-auth
auth:
username: ${DOCKERHUB_USER}
password: ${DOCKERHUB_PASSWORD}

- save_cache:
paths:
- ./vendor/bundle
key: v1-dependencies-{{ checksum "Gemfile.lock" }}

- run:
name: run tests
command: |
bundle exec rspec --format progress \
--format RspecJunitFormatter \
--out test-results/rspec.xml
# Define executors
executors:
docker: # Docker using the Base Convenience Image
docker:
- image: cimg/base:stable
<<: *common-auth
macos: # macos executor running Xcode
macos:
xcode: 15.3.0 # Xcode 15.3 (15E204a), macOS Sonoma14.3.1

- run:
name: run appraisals
command: |
bundle exec appraisal install --jobs 4 --retry 3
bundle exec appraisal rspec
jobs:

- store_test_results:
path: test-results
# Lint job
lint:
docker:
- image: cimg/base:stable
<<: *common-auth
resource_class: small
steps:
# Check out code
- checkout
# Install requested Ruby version
- ruby/install:
version: "<< pipeline.parameters.default-ruby >>"
# Install dependencies using bundler
- ruby/install-deps:
pre-install-steps:
- run: bundle config set jobs $(nproc)
key: gems-v{{ .Environment.CACHE_VERSION }}
# Run Rubocop
- run:
name: Run Rubocop
command: |
bash -c "bundle exec rubocop --format=json --out=rubocop-result.json; [[ \$? -ne 2 ]]"
- store_artifacts:
path: rubocop-result.json
destination: rubocop-result.json
- persist_to_workspace:
root: .
paths:
- rubocop-result.json

################################################################################
# Test job
test:
parameters:
# The OS to run the jobs on
os:
type: string
default: docker
# The OS to run the jobs on
ruby-version:
type: string
default: "3.3"
executor: << parameters.os >>
steps:
# Install dependencies based on the OS
- when:
condition:
equal: [ "docker", "<< parameters.os >>" ]
steps:
- run: sudo apt-get update && sudo apt-get -y --no-install-recommends install imagemagick libvips
- when:
condition:
equal: [ "macos", "<< parameters.os >>" ]
steps:
- run: brew install imagemagick libvips
# Check out code
- checkout
# Install requested Ruby version
- ruby/install:
version: "<< parameters.ruby-version >>"
# Install dependencies using bundler
- ruby/install-deps:
pre-install-steps:
- run: bundle config set jobs $(nproc)
key: gems-v{{ .Environment.CACHE_VERSION }}
# Run RSpec tests
- run:
name: Run tests
command: |
bundle exec rspec spec
# Run appraisals
- run:
name: Run appraisals
command: |
bundle exec appraisal install --jobs=$(nproc) --retry 3
bundle exec appraisal rspec
# Store test results
- store_test_results:
path: rspec/rspec.xml
# Persist test results to workspace for default Ruby
- when:
condition:
and:
- equal: [ "docker", "<< parameters.os >>" ]
- equal: [ "<< pipeline.parameters.default-ruby >>", "<< parameters.ruby-version >>" ]
steps:
- persist_to_workspace:
root: .
paths:
- rspec
- coverage

jobs:
ruby-2.5:
<<: *base_job
docker:
- image: circleci/ruby:2.5
ruby-2.6:
<<: *base_job
# Sonarcloud job
sonarcloud:
docker:
- image: circleci/ruby:2.6
ruby-2.7:
<<: *base_job
environment:
UPLOAD_COVERAGE: 1
docker:
- image: circleci/ruby:2.7
- image: cimg/openjdk:21.0-node
<<: *common-auth
resource_class: small
steps:
- checkout
- attach_workspace:
at: .
- run:
name: Replace Version
command: |
if [ -n "${CIRCLE_TAG}" ] && [ ! -z "${CIRCLE_TAG}" ] ; then
export APP_VERSION="${CIRCLE_TAG}"
elif [ -n "${CIRCLE_BRANCH}" ] && [ ! -z "${CIRCLE_BRANCH}" ] ; then
export APP_VERSION="${CIRCLE_BRANCH}"
else
export APP_VERSION="${CIRCLE_SHA1:0:7}"
fi
echo "Setting version to ${APP_VERSION}"
sed -i -e "s\\sonar.projectVersion=.*$\\sonar.projectVersion=${APP_VERSION}\\g" sonar-project.properties
- sonarcloud/scan


################################################################################

workflows:
version: 2
multiple-rubies:
jobs:
- ruby-2.5
- ruby-2.6
- ruby-2.7
- lint:
context:
- DockerHub
- test:
context:
- DockerHub
matrix:
parameters:
os: ["docker", "macos"]
ruby-version: ["2.5", "2.6", "2.7", "3.0", "3.1", "3.2", "3.3"]
- sonarcloud:
context:
- DockerHub
requires:
- lint
- test
21 changes: 21 additions & 0 deletions .depfu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
update_strategy: security

bundler:
update_strategy: grouped
update_out_of_spec: false
reasonably_up_to_date: true
automerge_method: squash
engine_update_strategy: minor
commit_message: ⬆️ Update {{dependency}} to version {{version}}
commit_message_grouped: ⬆️ Update {{update_type}} {{project_type}} dependencies ({{date}})
labels:
- dependencies
- depfu
security_labels:
- 🚨 security
auto_assign: otherguy
auto_review_team_assign: platform
grouped_update_schedule: biweekly
grouped_update_start_date: '2022-01-05' # First wednesday of the year
grouped_update_time: '6:00'
14 changes: 7 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@

# Rubocop
.rubocop-*
rubocop-result.json

# rspec failure tracking
spec/examples.txt

# Dotenv
.env.*.local

# CircleCI / RSpec JUnit formatter
test-results
# RSpec
rspec/
spec/examples.txt

# Appraisals
gemfiles/*.gemfile.lock

# Examples
examples/output

.ruby-version
5 changes: 5 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
--require spec_helper
--color
--format documentation
--format RspecJunitFormatter
--out rspec/rspec.xml
--format RspecSonarqubeFormatter
--out rspec/test-report.xml
2 changes: 1 addition & 1 deletion Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ end

# Latest in Faraday 1.x series
appraise "faraday-1-x" do
gem "faraday", "~> 1.0"
gem "faraday", "~> 1"
end
4 changes: 0 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@

source "https://rubygems.org"
gemspec

group :development do
gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git", ref: "5868643"
end
Loading

0 comments on commit 69409df

Please sign in to comment.