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

Add Elm language support #934

Merged
merged 67 commits into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
8d864ed
Add script/elm.rb
Jan 20, 2017
bf9d28d
Add elm to build processes.
Jan 20, 2017
c8456af
Add elm_spec.rb
Jan 20, 2017
889e7aa
Switch to using elm-use so we get elm-format as well.
Feb 6, 2017
e55e6b5
Validate elm-format before running tests.
Feb 8, 2017
e9d6f6d
Specify elm-use version bounds
Mar 2, 2017
59f0e85
Use NodeJs base class
Mar 2, 2017
bbd0617
Add .nvmrc to set default Node version
Mar 2, 2017
dcb800b
Fully qualify NodeJs
Mar 2, 2017
acc4839
Don't use .nvmrc
Mar 2, 2017
419515f
Add require node_js
Mar 2, 2017
4a51a94
Use echo: true instead of sh.echo
Mar 2, 2017
9f3c387
Shorten to just NodeJs
Mar 2, 2017
0a653d9
Fix requires
Mar 3, 2017
0e692ef
Update cache slug and fix test.
Mar 3, 2017
ca0e387
Install Node 6.10.0 by default.
Mar 3, 2017
d0dfc51
Put install_sysconfcpus behind a fold
Mar 3, 2017
22bc82a
Use double quotes for string interpolation
Mar 3, 2017
8478100
Upgrade to elm-use 1.1.1
Mar 3, 2017
b633a43
Configure default Node version.
Mar 24, 2017
7d44452
Use explicit default versions.
Jul 10, 2017
acd348f
Bump elm-test version to latest.
Feb 1, 2018
df042a8
Fix tests.
Feb 1, 2018
6556aa8
Merge branch 'master' into add-elm
Feb 1, 2018
b6697ff
Put Elm installation behind a fold
Feb 7, 2018
9e913d1
Fail fast on elm-format --validate
Feb 7, 2018
1b79807
Move install_sysconfcpus to setup
Feb 7, 2018
fd9ac9d
Merge branch 'master' into add-elm
Feb 9, 2018
71ace6a
Fix test.
Mar 31, 2018
1dd9541
Merge branch 'master' into add-elm
Mar 31, 2018
2ce9146
Merge branch 'master' into add-elm
Apr 17, 2018
fe072aa
Merge branch 'master' into add-elm
carlad Jul 27, 2018
b988cdc
Merge branch 'master' into add-elm
joepvd Jul 30, 2018
be4c9d0
Merge branch 'master' into add-elm
carlad Jul 30, 2018
577858f
Added banner stating community maintainers
Jul 31, 2018
41062dc
Merge branch 'master' into add-elm
Jul 31, 2018
777015b
Merge branch 'master' into add-elm
Aug 9, 2018
3a00078
Merge branch 'master' into add-elm
Aug 29, 2018
8ed6eb5
Merge pull request #1 from Kurren123/add-elm
Aug 30, 2018
b8f82df
Merge branch 'master' into add-elm
Aug 30, 2018
2f9fdc8
Merge branch 'master' into add-elm
Aug 30, 2018
1911751
Merge branch 'master' into add-elm
BanzaiMan Oct 25, 2018
9331c82
Merge branch 'master' into add-elm
carlad Nov 6, 2018
f069edf
Add methods to extract different version numbers.
Sep 3, 2018
9f43237
Account for Elm 0.19+ having only one binary.
Sep 3, 2018
70fe4ed
Cache ~/.elm
Sep 3, 2018
912e647
Only cache tests/ in Elm 0.19+
Sep 3, 2018
0f82be3
Rename config variables to :elm and :elm_test
Sep 3, 2018
0c84815
Bump default node version to 8.9.1
Sep 3, 2018
bc69eee
Default to Elm 0.19
Sep 3, 2018
ccdb739
elm-test now requires Node 6+
Nov 7, 2018
ea1a0e1
Print elm-format version number.
Nov 7, 2018
583dd23
Clarify comment
Nov 7, 2018
e2e610f
Replace `elm-use` with @elm-#{version} convention.
Nov 7, 2018
a00fe69
Merge branch 'master' into add-elm
Nov 7, 2018
74f7059
Have Elm default to current Node LTS
Nov 7, 2018
8a7d251
Remove unnecessary 'when' clause
Nov 7, 2018
4ea672b
Merge branch 'master' into add-elm
carlad Nov 8, 2018
5774d5e
Merge branch 'master' into add-elm
carlad Nov 8, 2018
3dc1e08
Merge branch 'master' into add-elm
meatballhat Nov 9, 2018
8a7fa8e
Merge branch 'master' into add-elm
Nov 11, 2018
4f47671
Merge branch 'master' into add-elm
Nov 20, 2018
2944552
vers2int -> travis_vers2int
Nov 20, 2018
f53ea8a
Use npm_install_global over npm_install
Nov 20, 2018
17d4a12
Add a blank line after announce
Nov 20, 2018
e386ff2
Add some colored echo statements
Nov 20, 2018
96e46d2
Move echoes inside sh.fold
Nov 20, 2018
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
1 change: 1 addition & 0 deletions lib/travis/build/addons/deploy/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Script
VERSIONED_RUNTIMES = %i(
d
dart
elm
elixir
ghc
go
Expand Down
1 change: 1 addition & 0 deletions lib/travis/build/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
require 'travis/build/script/julia'
require 'travis/build/script/nix'
require 'travis/build/script/node_js'
require 'travis/build/script/elm'
require 'travis/build/script/objective_c'
require 'travis/build/script/perl'
require 'travis/build/script/perl6'
Expand Down
183 changes: 183 additions & 0 deletions lib/travis/build/script/elm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
module Travis
module Build
class Script
class Elm < NodeJs
# Default NodeJS version to install
DEFAULT_NODE_VERSION = '10.13.0'

DEFAULTS = {
elm: '0.19.0',
elm_test: '0.19.0',
elm_format: '0.19.0'

This comment was marked as spam.

This comment was marked as spam.

}

ELM_TEST_REQUIRED_NODE_VERSION = '6.0.0'

def export
super
sh.export 'TRAVIS_ELM_VERSION', elm_version, echo: false
sh.export 'TRAVIS_ELM_TEST_VERSION', elm_test_version, echo: false
sh.export 'TRAVIS_ELM_FORMAT_VERSION', elm_format_version, echo: false
end

def configure
super

config[:node_js] ||= DEFAULT_NODE_VERSION
end

def announce
super
sh.cmd 'elm --version', echo: true
sh.cmd 'elm-test --version', echo: true

# elm-format doesn't have --version,
# but the first line of `elm-format --help` prints the version
sh.cmd 'elm-format --help | head -n 1', echo: true
rtfeldman marked this conversation as resolved.
Show resolved Hide resolved
end

def setup
super

sh.echo 'Elm for Travis-CI is not officially supported, ' \
'but is community maintained.', ansi: :green
sh.echo 'Please file any issues using the following link',
ansi: :green
sh.echo ' https://github.com/travis-ci/travis-ci/issues' \
'/new?labels=community:elm', ansi: :green
sh.echo 'and mention \`@avh4\`, \`@lukewestby\`, \`@stoeffel\` and \`@rtfeldman\`' \
' in the issue', ansi: :green


sh.if '! -d sysconfcpus/bin' do
install_sysconfcpus
end

sh.fold 'install.elm' do
install_elm
rtfeldman marked this conversation as resolved.
Show resolved Hide resolved
install_elm_test
install_elm_format
end
end

def script
sh.cmd 'elm-format --validate . && elm-test'
end

def setup_cache
if data.cache?(:elm)
sh.fold 'cache.elm' do
# Cache the ~/.elm directory.

This comment was marked as spam.

This comment was marked as spam.

directory_cache.add '$HOME/.cache/elm', '$HOME/.elm'

directory_cache.add '$HOME/.cache/elm-stuff', 'elm-stuff'

if elm_major_version == 0 && elm_minor_version <= 18
# In Elm 0.18, some put their tests in ./test instead of ./tests
directory_cache.add '$HOME/.cache/elm-test-stuff', 'test/elm-stuff'
end

# In Elm 0.18+, all tests live in tests/ by default
# (whereas previously tests/ was allowed, but so was test/)
directory_cache.add '$HOME/.cache/elm-tests-stuff', 'tests/elm-stuff'

# we build sysconfcpus from source, so cache the result
directory_cache.add '$HOME/.cache/sysconfcpus-cache', 'sysconfcpus'
end
end
end

def cache_slug
super << '-elm-' << elm_version
end

private

def elm_version
config[:elm].to_s
end

def elm_version_number(index)
elm_version.split(".")[index]
end

def elm_major_version
elm_version_number 0
end

def elm_minor_version
elm_version_number 1
end

def elm_patch_version
elm_version_number 2
end

def elm_test_version
config[:elm_test].to_s
end

def elm_format_version
config[:elm_format].to_s
end

def install_elm
BanzaiMan marked this conversation as resolved.
Show resolved Hide resolved
npm_install "-g elm@elm-#{elm_version}"

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


convert_binary_to_sysconfcpus 'elm'

# Beginning with Elm 0.19, there's one `elm` binary and that's it.
# In that case, there won't be any files to convert here!
if elm_major_version == 0 && elm_minor_version <= 18
convert_binary_to_sysconfcpus 'elm-make'
convert_binary_to_sysconfcpus 'elm-package'
convert_binary_to_sysconfcpus 'elm-format'
end
end

def install_elm_format
npm_install "-g elm-format@elm-#{elm_format_version}"

convert_binary_to_sysconfcpus 'elm-format'
end

def install_elm_test
sh.if "$(vers2int $(echo `node --version` | tr -d 'v')) -lt $(vers2int #{ELM_TEST_REQUIRED_NODE_VERSION})" do
rtfeldman marked this conversation as resolved.
Show resolved Hide resolved
sh.echo "Node.js version $(node --version) does not meet requirement for elm-test." \
" Please use Node.js #{ELM_TEST_REQUIRED_NODE_VERSION} or later.", ansi: :red
end
sh.else do
sh.if "-z \"$(command -v elm-test)\"" do
npm_install "-g elm-test@#{elm_test_version}"

convert_binary_to_sysconfcpus 'elm-test'
end
end
end

def convert_binary_to_sysconfcpus(binary_name)
# Wrap the binary in a call to sysconfcpus -n 2
# to work around https://github.com/travis-ci/travis-ci/issues/6656
sh.mv "$(npm config get prefix)/bin/#{binary_name}", "$(npm config get prefix)/bin/#{binary_name}-old"

# Use printf instead of echo here.
# see https://github.com/rtfeldman/node-elm-compiler/pull/50
sh.cmd ('printf "#\041/bin/bash\n\necho \"Running ' + binary_name + ' with sysconfcpus -n 2\"\n\n$TRAVIS_BUILD_DIR/sysconfcpus/bin/sysconfcpus -n 2 ' + binary_name + '-old \"\$@\"" > $(npm config get prefix)/bin/' + binary_name)
sh.chmod '+x', "$(npm config get prefix)/bin/#{binary_name}"
end

def install_sysconfcpus
BanzaiMan marked this conversation as resolved.
Show resolved Hide resolved
sh.fold 'sysconfcpus' do
# this is a prerequisite for the convert_binary_to_sysconfcpus method
# which provides an epic build time improvement - see https://github.com/elm-lang/elm-compiler/issues/1473#issuecomment-245704142
sh.cmd 'git clone https://github.com/obmarg/libsysconfcpus.git', retry: true
rtfeldman marked this conversation as resolved.
Show resolved Hide resolved
sh.cd 'libsysconfcpus'
sh.cmd './configure --prefix=$TRAVIS_BUILD_DIR/sysconfcpus'
BanzaiMan marked this conversation as resolved.
Show resolved Hide resolved
sh.cmd 'make && make install'
sh.cd '..'
end
end
end
end
end
end
44 changes: 44 additions & 0 deletions spec/build/script/elm_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'spec_helper'

describe Travis::Build::Script::Elm, :sexp do
let(:data) { payload_for(:push, :elm) }
let(:script) { described_class.new(data) }
subject { script.sexp }
it { store_example }

it_behaves_like 'compiled script' do
let(:code) { ['TRAVIS_LANGUAGE=elm'] }
let(:cmds) { ['elm-test'] }
end

it_behaves_like 'a build script sexp'

it 'sets TRAVIS_ELM_VERSION' do
should include_sexp [:export, ['TRAVIS_ELM_VERSION', Travis::Build::Script::Elm::DEFAULTS[:elm]]]
end

it 'sets TRAVIS_ELM_TEST_VERSION' do
should include_sexp [:export, ['TRAVIS_ELM_TEST_VERSION', Travis::Build::Script::Elm::DEFAULTS[:elm_test]]]
end

it 'sets TRAVIS_ELM_FORMAT_VERSION' do
should include_sexp [:export, ['TRAVIS_ELM_FORMAT_VERSION', Travis::Build::Script::Elm::DEFAULTS[:elm_format]]]
end

it 'announces elm version' do
should include_sexp [:cmd, 'elm --version', echo: true]
should include_sexp [:cmd, 'elm-test --version', echo: true]
should include_sexp [:cmd, 'elm-format --help | head -n 1', echo: true]
end

describe 'script' do
it 'runs `elm-test` and `elm-format`' do
should include_sexp [:cmd, 'elm-format --validate . && elm-test', echo: true, timing: true]
end
end

describe '#cache_slug' do
subject { described_class.new(data).cache_slug }
it { is_expected.to eq("cache-#{CACHE_SLUG_EXTRAS}--node--elm-#{Travis::Build::Script::Elm::DEFAULTS[:elm]}") }
end
end