Skip to content

Commit 65757c4

Browse files
authored
CI improvements (#525)
* Lock Bundler to v2.3.26 This is the last version that supports Ruby 2.4 and 2.5. * Remove fix to use rake-compiler-dock on Windows for libiconv The original author states that the code I removed is for using virtualbox on Windows to compile the gem. I read up on this and while rake-compiler-dock still supports using docker-machine to compile gems, the project has been discontinued in favor of Docker Desktop, which nowadays only works with Docker in WSL2. * Bump openssl to v1.1.1s 1.1.1d gives an error when compiling against i686-w64-mingw32. Upgrading it seems to work. * Define task to compile native extensions * Skip dead connection test on Windows * Extend pipeline to test gem on Windows * Package gems on CI before Windows tests * Ensure test container uses Ruby version defined in CI matrix * Test against Ruby 2.4 * Publish test results to CircleCI * Rename artifact for gems * Restore cross-compiled code from final gem file * Store precompiled gem into workspace instead of cache this seems to be the more appropriate type of data store according to the CircleCI documentation. * Fix order for compiling ports * Disable progress bar for Invoke-WebRequest * Add `/ALLUSERS` option to RubyInstaller Looks like a new option that has been introduced in the most recent 2.7 version and explains the timeout we see with the Ruby installation on CircleCI. https://github.com/oneclick/rubyinstaller2/wiki/FAQ#user-content-install-mode Older versions seem to ignore the parameter and run the installation as usual.
1 parent c8111e6 commit 65757c4

File tree

13 files changed

+211
-89
lines changed

13 files changed

+211
-89
lines changed

.circleci/config.yml

Lines changed: 127 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ version: 2.1
22

33
orbs:
44
win: circleci/[email protected]
5+
ruby: circleci/[email protected]
56

67
jobs:
78
test_linux:
89
parameters:
910
ruby_version:
1011
description: 'version tag for the cimg/ruby container'
1112
type: string
12-
13+
1314
machine:
1415
image: ubuntu-2004:current
1516

@@ -19,11 +20,13 @@ jobs:
1920

2021
- run:
2122
name: start docker-compose build environment
22-
command: |
23+
command: |
2324
sudo ./test/bin/setup_volume_permissions.sh
2425
docker-compose up -d
2526
echo "Waiting for containers to start..."
2627
sleep 10
28+
environment:
29+
RUBY_VERSION: << parameters.ruby_version >>
2730

2831
- run:
2932
name: install sql prereqs
@@ -58,7 +61,10 @@ jobs:
5861
- run:
5962
name: test gem
6063
command: |
61-
docker exec cimg_ruby bash -c 'bundle exec rake test'
64+
docker exec cimg_ruby bash -c 'bundle exec rake test'
65+
66+
- store_test_results:
67+
path: test/reports
6268

6369
test_windows:
6470
parameters:
@@ -84,6 +90,8 @@ jobs:
8490
- run:
8591
name: download and install ruby devkit
8692
command: |
93+
$ProgressPreference='SilentlyContinue'
94+
8795
$uri = 'https://api.github.com/repos/oneclick/rubyinstaller2/tags?per_page=200'
8896
$releases = ((Invoke-WebRequest $uri) | ConvertFrom-Json).name | select-string -Pattern '<< parameters.ruby_version >>'
8997
$target_release = (($releases | Sort-Object -Descending)[0] | Out-String).Trim()
@@ -93,7 +101,9 @@ jobs:
93101
94102
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
95103
Invoke-WebRequest -UseBasicParsing -uri $download_uri -OutFile ruby-setup.exe
96-
.\ruby-setup.exe /VERYSILENT /NORESTART /DIR=C:/Ruby<< parameters.ruby_version >>-x64
104+
105+
echo "Download finished, starting installation of $target_version"
106+
.\ruby-setup.exe /VERYSILENT /NORESTART /ALLUSERS /DIR=C:/Ruby<< parameters.ruby_version >>-x64
97107
98108
- run:
99109
name: ruby diagnostics
@@ -108,11 +118,10 @@ jobs:
108118
rm .\ruby-setup.exe
109119
110120
- run:
111-
name: update build env
121+
name: install bundler
112122
command: |
113123
$Env:PATH = "C:\\Ruby<< parameters.ruby_version >>-x64\\bin;$Env:PATH"
114-
ridk install 2
115-
gem install bundler
124+
gem install bundler -v 2.3.26
116125
117126
- checkout
118127

@@ -127,57 +136,143 @@ jobs:
127136
name: bundle install gems
128137
command: |
129138
$Env:PATH = "C:\\Ruby<< parameters.ruby_version >>-x64\\bin;$Env:PATH"
130-
bundle install
139+
bundle install --path vendor/bundle
131140
132141
- save_cache:
133142
name: save gem cache
134143
paths:
135144
- ./vendor/bundle
136145
key: v1-bundle-<< parameters.ruby_version >>-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }}
137146

147+
- attach_workspace:
148+
at: artifacts
149+
138150
- run:
139-
name: build openssl
140-
no_output_timeout: 30m
151+
name: install native gem and restore cross-compiled code from gem
141152
command: |
142153
$Env:PATH = "C:\\Ruby<< parameters.ruby_version >>-x64\\bin;$Env:PATH"
143-
bundle exec rake ports:openssl
154+
$rubyArchitecture = (ruby -e 'puts RUBY_PLATFORM').Trim()
155+
$gemVersion = (Get-Content VERSION).Trim()
156+
157+
gem install --local --install-dir=./tmp "artifacts/gems/tiny_tds-$gemVersion-$rubyArchitecture.gem"
158+
159+
# Restore precompiled code
160+
$source = (Resolve-Path ".\tmp\gems\tiny_tds-$gemVersion-$rubyArchitecture\lib\tiny_tds").Path
161+
$destination = (Resolve-Path ".\lib\tiny_tds").Path
162+
Get-ChildItem $source -Recurse -Exclude "*.rb" | Copy-Item -Destination {Join-Path $destination $_.FullName.Substring($source.length)}
163+
164+
# Restore ports
165+
Copy-Item -Path ".\tmp\gems\tiny_tds-$gemVersion-$rubyArchitecture\ports" -Destination "." -Recurse
166+
167+
- restore_cache:
168+
name: restore mssql installation file
169+
key: downloads-{{ checksum "test/bin/install-mssql.ps1" }}
144170

145171
- run:
146-
name: build libiconv
147-
no_output_timeout: 30m
172+
name: setup mssql
148173
command: |
149-
$Env:PATH = "C:\\Ruby<< parameters.ruby_version >>-x64\\bin;$Env:PATH"
150-
bundle exec rake ports:libiconv
174+
.\test\bin\install-mssql.ps1
175+
176+
- save_cache:
177+
name: save downloads cache
178+
paths:
179+
- C:\Downloads
180+
key: downloads-{{ checksum "test/bin/install-mssql.ps1" }}
151181

152182
- run:
153-
name: build freetds
154-
no_output_timeout: 30m
183+
name: install toxiproxy-server
155184
command: |
156-
$Env:PATH = "C:\\Ruby<< parameters.ruby_version >>-x64\\bin;$Env:PATH"
157-
bundle exec rake ports:freetds
185+
choco install toxiproxy-server --version=2.5.0 -y
186+
Start-Process toxiproxy-server
158187
159188
- run:
160-
name: build gem
161-
no_output_timeout: 30m
189+
name: test gem
162190
command: |
163191
$Env:PATH = "C:\\Ruby<< parameters.ruby_version >>-x64\\bin;$Env:PATH"
164-
bundle exec rake ports
192+
bundle exec rake test
193+
environment:
194+
TOXIPROXY_HOST: "localhost"
195+
196+
- store_test_results:
197+
path: test/reports
198+
199+
cross_compile_gem:
200+
machine:
201+
image: ubuntu-2004:current
202+
203+
steps:
204+
- ruby/install:
205+
version: '2.7'
206+
- checkout
207+
- restore_cache:
208+
name: restore gem cache
209+
keys:
210+
- v1-bundle-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }}
211+
- v1-bundle-{{ .Branch }}-
212+
- v1-bundle-
213+
214+
- run:
215+
name: bundle install gems
216+
command: |
217+
bundle install --path vendor/bundle
218+
219+
- save_cache:
220+
name: save gem cache
221+
paths:
222+
- ./vendor/bundle
223+
key: v1-bundle-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }}
224+
225+
- run:
226+
name: Write used versions for ports into file
227+
command: |
228+
bundle exec rake ports:version_file
229+
230+
- restore_cache:
231+
name: restore ports cache
232+
keys:
233+
- ports-{{ checksum ".ports_versions" }}
234+
- ports-
235+
236+
- run:
237+
name: Build gems
238+
command: |
239+
bundle exec rake gem
240+
bundle exec rake gem:native
241+
242+
- run:
243+
name: Move gems into separate directory before caching
244+
command: |
245+
mkdir -p artifacts/gems
246+
mv pkg/*.gem artifacts/gems
247+
248+
- store_artifacts:
249+
path: artifacts/gems
250+
251+
- save_cache:
252+
name: save ports cache
253+
paths:
254+
- ./ports
255+
key: ports-{{ checksum ".ports_versions" }}
256+
257+
- persist_to_workspace:
258+
name: save gems into workspace
259+
root: artifacts
260+
paths:
261+
- gems
165262

166263
workflows:
167264
test_supported_ruby_versions:
168265
jobs:
169-
- test_linux:
170-
matrix:
266+
- cross_compile_gem
267+
- test_windows:
268+
requires:
269+
- cross_compile_gem
270+
matrix: &ruby_versions
171271
parameters:
172272
ruby_version:
273+
- '2.4'
173274
- '2.5'
174275
- '2.6'
175276
- '2.7'
176-
177-
- test_windows:
178-
matrix:
179-
parameters:
180-
ruby_version:
181-
- '2.5'
182-
- '2.6'
183-
- '2.7'
277+
- test_linux:
278+
matrix: *ruby_versions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ misc
1818
/exe/*
1919
/ports/*
2020
!/ports/patches/
21+
test/reports
22+
.ports_versions

Gemfile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,2 @@
11
source 'https://rubygems.org'
22
gemspec
3-
4-
group :development do
5-
end
6-
7-
group :test do
8-
gem 'minitest'
9-
end

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ For the convenience of Windows users, TinyTDS ships pre-compiled gems for suppor
407407
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:
408408

409409
```
410-
$ rake gem:windows
410+
$ rake gem:native
411411
```
412412

413413
The compiled gems will exist in `./pkg` directory.

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ GEM_PLATFORM_HOSTS = {
1010
'x86-mingw32' => 'i686-w64-mingw32',
1111
'x64-mingw32' => 'x86_64-w64-mingw32'
1212
}
13+
RUBY_CC_VERSION="2.7.0:2.6.0:2.5.0:2.4.0".freeze
1314

1415
# Add our project specific files to clean for a rebuild
1516
CLEAN.include FileList["{ext,lib}/**/*.{so,#{RbConfig::CONFIG['DLEXT']},o}"],

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ services:
2121
network_mode: "host"
2222

2323
cimgruby:
24-
image: cimg/ruby:2.7.0
24+
image: "cimg/ruby:${RUBY_VERSION:-2.7}"
2525
container_name: cimg_ruby
2626
environment:
2727
TESTOPTS: '-v'

ext/tiny_tds/extconsts.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
ICONV_VERSION = ENV['TINYTDS_ICONV_VERSION'] || "1.15"
33
ICONV_SOURCE_URI = "http://ftp.gnu.org/pub/gnu/libiconv/libiconv-#{ICONV_VERSION}.tar.gz"
44

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

88
FREETDS_VERSION = ENV['TINYTDS_FREETDS_VERSION'] || "1.1.24"

tasks/native_gem.rake

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
# encoding: UTF-8
22

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

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

10-
# and finally build the native gem
11-
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`"'
12-
13-
RakeCompilerDock.sh build.join(' && ')
10+
GEM_PLATFORM_HOSTS.keys.each do |plat|
11+
RakeCompilerDock.sh "bundle --local && RUBY_CC_VERSION=#{RUBY_CC_VERSION} rake native:#{plat} gem", platform: plat
12+
end
1413
end

0 commit comments

Comments
 (0)