Skip to content

Commit c6f4d73

Browse files
committed
Enable custom installation scripts during CI
1 parent 6aef89f commit c6f4d73

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99
### Added
10+
- Environment variable to run a custom initialization script during CI testing: `CUSTOM_INIT_SCRIPT`
1011

1112
### Changed
1213

@@ -22,7 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2223
## [1.1.0] - 2020-12-02
2324
### Added
2425
- `ensure_arduino_installation.rb` now ensures the existence of the library directory as well
25-
- Environment variables to escalate unit tests or examples not being found during CI testing
26+
- Environment variables to escalate unit tests or examples not being found during CI testing - `EXPECT_EXAMPLES` and `EXPECT_UNITTESTS`
2627

2728
### Changed
2829
- Conserve CI testing minutes by grouping CI into fewer runs

REFERENCE.md

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ This allows a file (or glob) pattern to be executed in your tests directory, cre
3939
This allows a file (or glob) pattern to be executed in your tests directory, creating a blacklist of files to skip. E.g. `--testfile-reject=test_animal_*.cpp` would match `test_animal_cat.cpp` and `test_animal_dog.cpp` (skipping those) and test only `test_plant_rose.cpp`, `test_plant_daisy.cpp`, etc.
4040

4141

42+
### `CUSTOM_INIT_SCRIPT` environment variable
43+
44+
If set, testing will execute (using `/bin/sh`) the script referred to by this variable -- relative to the current working directory. This enables use cases like the GitHub action to install custom library versions (i.e. a version of a library that is different than what the library manager would automatically install by name) prior to CI test runs.
45+
46+
4247
### `EXPECT_UNITTESTS` environment variable
4348

4449
If set, testing will fail if no unit test files are detected (or if the directory does not exist). This is to avoid communicating a passing status in cases where a commit may have accidentally moved or deleted the test files.

exe/arduino_ci.rb

+33-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
require 'optparse'
66

77
WIDTH = 80
8-
VAR_EXPECT_EXAMPLES = "EXPECT_EXAMPLES".freeze
9-
VAR_EXPECT_UNITTESTS = "EXPECT_UNITTESTS".freeze
8+
VAR_CUSTOM_INIT_SCRIPT = "CUSTOM_INIT_SCRIPT".freeze
9+
VAR_EXPECT_EXAMPLES = "EXPECT_EXAMPLES".freeze
10+
VAR_EXPECT_UNITTESTS = "EXPECT_UNITTESTS".freeze
1011

1112
@failure_count = 0
1213
@passfail = proc { |result| result ? "✓" : "✗" }
@@ -51,6 +52,8 @@ def self.parse(options)
5152
puts opts
5253
puts
5354
puts "Additionally, the following environment variables control the script:"
55+
puts " - #{VAR_CUSTOM_INIT_SCRIPT} - if set, this script will be run from the Arduino/libraries directory"
56+
puts " prior to any automated library installation or testing (e.g. to install unoffical libraries)"
5457
puts " - #{VAR_EXPECT_EXAMPLES} - if set, testing will fail if no example sketches are present"
5558
puts " - #{VAR_EXPECT_UNITTESTS} - if set, testing will fail if no unit tests are present"
5659
exit
@@ -68,7 +71,7 @@ def self.parse(options)
6871
# terminate after printing any debug info. TODO: capture debug info
6972
def terminate(final = nil)
7073
puts "Failures: #{@failure_count}"
71-
unless @failure_count.zero? || final
74+
unless @failure_count.zero? || final || @backend.nil?
7275
puts "Last message: #{@backend.last_msg}"
7376
puts "========== Stdout:"
7477
puts @backend.last_out
@@ -277,6 +280,30 @@ def get_annotated_compilers(config, cpp_library)
277280
compilers
278281
end
279282

283+
# Handle existence or nonexistence of custom initialization script -- run it if you have it
284+
#
285+
# This feature is to drive GitHub actions / docker image installation where the container is
286+
# in a clean-slate state but needs some way to have custom library versions injected into it.
287+
# In this case, the user provided script would fetch a git repo or some other method
288+
def perform_custom_initialization(_config)
289+
script_path = ENV[VAR_CUSTOM_INIT_SCRIPT]
290+
inform("Environment variable #{VAR_CUSTOM_INIT_SCRIPT}") { "'#{script_path}'" }
291+
return if script_path.nil?
292+
return if script_path.empty?
293+
294+
script_pathname = Pathname.getwd + script_path
295+
assure("Script at #{VAR_CUSTOM_INIT_SCRIPT} exists") { script_pathname.exist? }
296+
297+
assure_multiline("Running #{script_pathname} with sh in libraries working dir") do
298+
Dir.chdir(@backend.lib_dir) do
299+
IO.popen(["/bin/sh", script_pathname.to_s], err: [:child, :out]) do |io|
300+
io.each_line { |line| puts " #{line}" }
301+
end
302+
end
303+
end
304+
end
305+
306+
# Unit test procedure
280307
def perform_unit_tests(cpp_library, file_config)
281308
if @cli_options[:skip_unittests]
282309
inform("Skipping unit tests") { "as requested via command line" }
@@ -394,6 +421,9 @@ def perform_example_compilation_tests(cpp_library, config)
394421
@backend = ArduinoCI::ArduinoInstallation.autolocate!
395422
inform("Located arduino-cli binary") { @backend.binary_path.to_s }
396423

424+
# run any library init scripts from the library itself.
425+
perform_custom_initialization(config)
426+
397427
# initialize library under test
398428
cpp_library_path = Pathname.new(".")
399429
cpp_library = assure("Installing library under test") do

0 commit comments

Comments
 (0)