Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI improvements #525

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 127 additions & 32 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ version: 2.1

orbs:
win: circleci/windows@4.1
ruby: circleci/ruby@2.0.0

jobs:
test_linux:
parameters:
ruby_version:
description: 'version tag for the cimg/ruby container'
type: string

machine:
image: ubuntu-2004:current

Expand All @@ -19,11 +20,13 @@ jobs:

- run:
name: start docker-compose build environment
command: |
command: |
sudo ./test/bin/setup_volume_permissions.sh
docker-compose up -d
echo "Waiting for containers to start..."
sleep 10
environment:
RUBY_VERSION: << parameters.ruby_version >>

- run:
name: install sql prereqs
Expand Down Expand Up @@ -58,7 +61,10 @@ jobs:
- run:
name: test gem
command: |
docker exec cimg_ruby bash -c 'bundle exec rake test'
docker exec cimg_ruby bash -c 'bundle exec rake test'

- store_test_results:
path: test/reports

test_windows:
parameters:
Expand All @@ -84,6 +90,8 @@ jobs:
- run:
name: download and install ruby devkit
command: |
$ProgressPreference='SilentlyContinue'

$uri = 'https://api.github.com/repos/oneclick/rubyinstaller2/tags?per_page=200'
$releases = ((Invoke-WebRequest $uri) | ConvertFrom-Json).name | select-string -Pattern '<< parameters.ruby_version >>'
$target_release = (($releases | Sort-Object -Descending)[0] | Out-String).Trim()
Expand All @@ -93,7 +101,9 @@ jobs:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -UseBasicParsing -uri $download_uri -OutFile ruby-setup.exe
.\ruby-setup.exe /VERYSILENT /NORESTART /DIR=C:/Ruby<< parameters.ruby_version >>-x64

echo "Download finished, starting installation of $target_version"
.\ruby-setup.exe /VERYSILENT /NORESTART /ALLUSERS /DIR=C:/Ruby<< parameters.ruby_version >>-x64

- run:
name: ruby diagnostics
Expand All @@ -108,11 +118,10 @@ jobs:
rm .\ruby-setup.exe

- run:
name: update build env
name: install bundler
command: |
$Env:PATH = "C:\\Ruby<< parameters.ruby_version >>-x64\\bin;$Env:PATH"
ridk install 2
gem install bundler
gem install bundler -v 2.3.26

- checkout

Expand All @@ -127,57 +136,143 @@ jobs:
name: bundle install gems
command: |
$Env:PATH = "C:\\Ruby<< parameters.ruby_version >>-x64\\bin;$Env:PATH"
bundle install
bundle install --path vendor/bundle

- save_cache:
name: save gem cache
paths:
- ./vendor/bundle
key: v1-bundle-<< parameters.ruby_version >>-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }}

- attach_workspace:
at: artifacts

- run:
name: build openssl
no_output_timeout: 30m
name: install native gem and restore cross-compiled code from gem
command: |
$Env:PATH = "C:\\Ruby<< parameters.ruby_version >>-x64\\bin;$Env:PATH"
bundle exec rake ports:openssl
$rubyArchitecture = (ruby -e 'puts RUBY_PLATFORM').Trim()
$gemVersion = (Get-Content VERSION).Trim()

gem install --local --install-dir=./tmp "artifacts/gems/tiny_tds-$gemVersion-$rubyArchitecture.gem"

# Restore precompiled code
$source = (Resolve-Path ".\tmp\gems\tiny_tds-$gemVersion-$rubyArchitecture\lib\tiny_tds").Path
$destination = (Resolve-Path ".\lib\tiny_tds").Path
Get-ChildItem $source -Recurse -Exclude "*.rb" | Copy-Item -Destination {Join-Path $destination $_.FullName.Substring($source.length)}

# Restore ports
Copy-Item -Path ".\tmp\gems\tiny_tds-$gemVersion-$rubyArchitecture\ports" -Destination "." -Recurse

- restore_cache:
name: restore mssql installation file
key: downloads-{{ checksum "test/bin/install-mssql.ps1" }}
Comment on lines +167 to +169
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify the benefit of caching this installation script? It's just another source file in the repo, so it should already be available on disk in the job step.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't cache the PowerShell script, but the C:/Downloads folder where I download the MSSQL installation file into. As the URL is hardcoded into this script, I thought it was fine to use the script for the checksum.

Potential side-effect is that if you change something in the script, it'll re-download the installation file. But it was also continue to use the cache even if Microsoft updates the SQL installation file on their side. I wouldn't say it's too important that the CI uses the latest version and rather take the 2 minute speed-up from caching the file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't cache the PowerShell script, but the C:/Downloads folder where I download the MSSQL installation file into

Oh yeah... duh.


- run:
name: build libiconv
no_output_timeout: 30m
name: setup mssql
command: |
$Env:PATH = "C:\\Ruby<< parameters.ruby_version >>-x64\\bin;$Env:PATH"
bundle exec rake ports:libiconv
.\test\bin\install-mssql.ps1

- save_cache:
name: save downloads cache
paths:
- C:\Downloads
key: downloads-{{ checksum "test/bin/install-mssql.ps1" }}

- run:
name: build freetds
no_output_timeout: 30m
name: install toxiproxy-server
command: |
$Env:PATH = "C:\\Ruby<< parameters.ruby_version >>-x64\\bin;$Env:PATH"
bundle exec rake ports:freetds
choco install toxiproxy-server --version=2.5.0 -y
Start-Process toxiproxy-server

- run:
name: build gem
no_output_timeout: 30m
name: test gem
command: |
$Env:PATH = "C:\\Ruby<< parameters.ruby_version >>-x64\\bin;$Env:PATH"
bundle exec rake ports
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, oops

bundle exec rake test
environment:
TOXIPROXY_HOST: "localhost"

- store_test_results:
path: test/reports

cross_compile_gem:
machine:
image: ubuntu-2004:current

steps:
- ruby/install:
version: '2.7'
- checkout
- restore_cache:
name: restore gem cache
keys:
- v1-bundle-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }}
- v1-bundle-{{ .Branch }}-
- v1-bundle-

- run:
name: bundle install gems
command: |
bundle install --path vendor/bundle

- save_cache:
name: save gem cache
paths:
- ./vendor/bundle
key: v1-bundle-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }}

- run:
name: Write used versions for ports into file
command: |
bundle exec rake ports:version_file

- restore_cache:
name: restore ports cache
keys:
- ports-{{ checksum ".ports_versions" }}
- ports-

- run:
name: Build gems
command: |
bundle exec rake gem
bundle exec rake gem:native

- run:
name: Move gems into separate directory before caching
command: |
mkdir -p artifacts/gems
mv pkg/*.gem artifacts/gems

- store_artifacts:
path: artifacts/gems

- save_cache:
name: save ports cache
paths:
- ./ports
key: ports-{{ checksum ".ports_versions" }}

- persist_to_workspace:
name: save gems into workspace
root: artifacts
paths:
- gems

workflows:
test_supported_ruby_versions:
jobs:
- test_linux:
matrix:
- cross_compile_gem
- test_windows:
requires:
- cross_compile_gem
matrix: &ruby_versions
parameters:
ruby_version:
- '2.4'
- '2.5'
- '2.6'
- '2.7'

- test_windows:
matrix:
parameters:
ruby_version:
- '2.5'
- '2.6'
- '2.7'
- test_linux:
matrix: *ruby_versions
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ misc
/exe/*
/ports/*
!/ports/patches/
test/reports
.ports_versions
7 changes: 0 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
source 'https://rubygems.org'
gemspec

group :development do
end

group :test do
gem 'minitest'
end
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ For the convenience of Windows users, TinyTDS ships pre-compiled gems for suppor
Run the following rake task to compile the gems for Windows. This will check the availability of [Docker](https://www.docker.com/) (and boot2docker on Windows or OS-X) and will give some advice for download and installation. When docker is running, it will download the docker image (once-only) and start the build:

```
$ rake gem:windows
$ rake gem:native
```

The compiled gems will exist in `./pkg` directory.
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ GEM_PLATFORM_HOSTS = {
'x86-mingw32' => 'i686-w64-mingw32',
'x64-mingw32' => 'x86_64-w64-mingw32'
}
RUBY_CC_VERSION="2.7.0:2.6.0:2.5.0:2.4.0".freeze

# Add our project specific files to clean for a rebuild
CLEAN.include FileList["{ext,lib}/**/*.{so,#{RbConfig::CONFIG['DLEXT']},o}"],
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
network_mode: "host"

cimgruby:
image: cimg/ruby:2.7.0
image: "cimg/ruby:${RUBY_VERSION:-2.7}"
container_name: cimg_ruby
environment:
TESTOPTS: '-v'
Expand Down
2 changes: 1 addition & 1 deletion ext/tiny_tds/extconsts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ICONV_VERSION = ENV['TINYTDS_ICONV_VERSION'] || "1.15"
ICONV_SOURCE_URI = "http://ftp.gnu.org/pub/gnu/libiconv/libiconv-#{ICONV_VERSION}.tar.gz"

OPENSSL_VERSION = ENV['TINYTDS_OPENSSL_VERSION'] || '1.1.1d'
OPENSSL_VERSION = ENV['TINYTDS_OPENSSL_VERSION'] || '1.1.1s'
OPENSSL_SOURCE_URI = "https://www.openssl.org/source/openssl-#{OPENSSL_VERSION}.tar.gz"

FREETDS_VERSION = ENV['TINYTDS_FREETDS_VERSION'] || "1.1.24"
Expand Down
13 changes: 6 additions & 7 deletions tasks/native_gem.rake
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# encoding: UTF-8

desc 'Build the windows binary gems per rake-compiler-dock'
task 'gem:windows' => ['ports:cross'] do
desc 'Build the native binary gems using rake-compiler-dock'
task 'gem:native' => ['ports:cross'] do
require 'rake_compiler_dock'

# make sure to install our bundle
build = ['bundle']
sh "bundle package --all" # Avoid repeated downloads of gems by using gem files from the host.

# and finally build the native gem
build << 'rake cross native gem RUBY_CC_VERSION=2.7.0:2.6.0:2.5.0:2.4.0 CFLAGS="-Wall" MAKE="make -j`nproc`"'

RakeCompilerDock.sh build.join(' && ')
GEM_PLATFORM_HOSTS.keys.each do |plat|
RakeCompilerDock.sh "bundle --local && RUBY_CC_VERSION=#{RUBY_CC_VERSION} rake native:#{plat} gem", platform: plat
end
end
Loading