Skip to content

Commit 5aaa89f

Browse files
committed
Automatically install libxml2-dev libxslt-dev on TruffleRuby if needed
* This is a special case, because TruffleRuby needs an extra system dependency that other Rubies do not, and GitHub runners do not have these packages installed by default, while TravisCI has them.
1 parent 3460195 commit 5aaa89f

File tree

5 files changed

+74
-4
lines changed

5 files changed

+74
-4
lines changed

.github/workflows/test.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@ jobs:
142142
bundler-cache: true
143143
- run: bundle exec rails --version
144144

145+
testTruffleRubyNokogiri:
146+
name: "Test installing a Gemfile with nokogiri on TruffleRuby"
147+
runs-on: ubuntu-latest
148+
env:
149+
BUNDLE_GEMFILE: gemfiles/nokogiri.gemfile
150+
steps:
151+
- uses: actions/checkout@v2
152+
- uses: ./
153+
with:
154+
ruby-version: truffleruby-head
155+
bundler-cache: true
156+
- run: bundle list | grep nokogiri
157+
145158
lint:
146159
runs-on: ubuntu-20.04
147160
steps:

bundler.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ function readBundledWithFromGemfileLock(lockFile) {
3838
return null
3939
}
4040

41+
async function afterLockFile(lockFile, platform, engine) {
42+
if (engine === 'truffleruby' && platform.startsWith('ubuntu-')) {
43+
const contents = fs.readFileSync(lockFile, 'utf8')
44+
if (contents.includes('nokogiri')) {
45+
await common.measure('Installing libxml2-dev libxslt-dev, required to install nokogiri on TruffleRuby', async () =>
46+
exec.exec('sudo', ['apt-get', '-yqq', 'install', 'libxml2-dev', 'libxslt-dev'], { silent: true }))
47+
}
48+
}
49+
}
50+
4151
export async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefix, engine, rubyVersion) {
4252
let bundlerVersion = bundlerVersionInput
4353

@@ -112,6 +122,8 @@ export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVer
112122
await exec.exec('bundle', ['lock'], envOptions)
113123
}
114124

125+
await afterLockFile(lockFile, platform, engine)
126+
115127
// cache key
116128
const paths = [cachePath]
117129
const baseKey = await computeBaseKey(platform, engine, rubyVersion, lockFile)

common.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ export function partition(string, separator) {
1919
return [string.slice(0, i), string.slice(i + separator.length, string.length)]
2020
}
2121

22+
let inGroup = false
23+
2224
export async function measure(name, block) {
23-
return await core.group(name, async () => {
25+
const body = async () => {
2426
const start = performance.now()
2527
try {
2628
return await block()
@@ -29,7 +31,20 @@ export async function measure(name, block) {
2931
const duration = (end - start) / 1000.0
3032
console.log(`Took ${duration.toFixed(2).padStart(6)} seconds`)
3133
}
32-
})
34+
}
35+
36+
if (inGroup) {
37+
// Nested groups are not yet supported on GitHub Actions
38+
console.log(`> ${name}`)
39+
return await body()
40+
} else {
41+
inGroup = true
42+
try {
43+
return await core.group(name, body)
44+
} finally {
45+
inGroup = false
46+
}
47+
}
3348
}
3449

3550
export function isHeadVersion(rubyVersion) {

dist/index.js

Lines changed: 29 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gemfiles/nokogiri.gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source "https://rubygems.org"
2+
3+
gem "nokogiri"

0 commit comments

Comments
 (0)