diff --git a/hooks/command b/hooks/command index 480f9fe..8cc6180 100755 --- a/hooks/command +++ b/hooks/command @@ -10,7 +10,7 @@ install_reporter() { printf -- "--- :codeclimate: Installing %s cc-test-reporter\\n" "${version}" curl --location --silent --output ./cc-test-reporter \ - "https://codeclimate.com/downloads/test-reporter/test-reporter-${version}-linux-amd64" && \ + "https://codeclimate.com/downloads/test-reporter/test-reporter-${version}-linux-${arch}" && \ chmod +x ./cc-test-reporter # add current working directory to path so cc-test-reporter is accessible PATH=${PATH}:$(pwd) @@ -104,6 +104,20 @@ report=${BUILDKITE_PLUGIN_CODECLIMATE_TEST_REPORTER_REPORT:-true} formatted_file_prefix=${BUILDKITE_PLUGIN_CODECLIMATE_TEST_REPORTER_FILE_PREFIX:-"codeclimate"} version=${BUILDKITE_PLUGIN_CODECLIMATE_TEST_REPORTER_VERSION:-"latest"} +march="$(uname -m)" +case $march in + x86_64) + arch="amd64" + ;; + aarch64) + arch="arm64" + ;; + *) + echo "Unsupported architecture: ${march}" + exit 1 + ;; +esac + install_reporter download_artifacts format_files diff --git a/tests/command.bats b/tests/command.bats index 376efa3..191ee3a 100755 --- a/tests/command.bats +++ b/tests/command.bats @@ -5,11 +5,12 @@ load '/usr/local/lib/bats/load.bash' # Uncomment the following line to debug stub failures # export BUILDKITE_AGENT_STUB_DEBUG=/dev/tty -@test "Installs the latest reporter binary" { +@test "Installs the latest reporter binary amd64" { export BUILDKITE_PLUGIN_CODECLIMATE_TEST_REPORTER_DOWNLOAD="false" export BUILDKITE_PLUGIN_CODECLIMATE_TEST_REPORTER_FORMAT="false" export BUILDKITE_PLUGIN_CODECLIMATE_TEST_REPORTER_REPORT="false" + stub uname "-m : echo 'x86_64'" stub curl "--location --silent --output ./cc-test-reporter \"https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64\" : echo 'Binary downloaded'" stub chmod "+x ./cc-test-reporter : echo 'Binary made executable'" stub cc-test-reporter "-v : echo 'Code Climate Test Reporter version'" @@ -22,11 +23,51 @@ load '/usr/local/lib/bats/load.bash' assert_output --partial "Binary made executable" assert_output --partial "Code Climate Test Reporter version" + unstub uname unstub curl unstub chmod unstub cc-test-reporter } +@test "Installs the latest reporter binary arm64" { + export BUILDKITE_PLUGIN_CODECLIMATE_TEST_REPORTER_DOWNLOAD="false" + export BUILDKITE_PLUGIN_CODECLIMATE_TEST_REPORTER_FORMAT="false" + export BUILDKITE_PLUGIN_CODECLIMATE_TEST_REPORTER_REPORT="false" + + stub uname "-m : echo 'aarch64'" + stub curl "--location --silent --output ./cc-test-reporter \"https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-arm64\" : echo 'Binary downloaded'" + stub chmod "+x ./cc-test-reporter : echo 'Binary made executable'" + stub cc-test-reporter "-v : echo 'Code Climate Test Reporter version'" + + run "$PWD/hooks/command" + + assert_success + assert_output --partial "--- :codeclimate: Installing latest cc-test-reporter" + assert_output --partial "Binary downloaded" + assert_output --partial "Binary made executable" + assert_output --partial "Code Climate Test Reporter version" + + unstub uname + unstub curl + unstub chmod + unstub cc-test-reporter +} + +@test "Installs the latest reporter binary unsupported architecture" { + export BUILDKITE_PLUGIN_CODECLIMATE_TEST_REPORTER_DOWNLOAD="false" + export BUILDKITE_PLUGIN_CODECLIMATE_TEST_REPORTER_FORMAT="false" + export BUILDKITE_PLUGIN_CODECLIMATE_TEST_REPORTER_REPORT="false" + + stub uname "-m : echo 'riscv64'" + + run "$PWD/hooks/command" + + assert_failure + assert_output --partial "Unsupported architecture: riscv64" + + unstub uname +} + @test "Downloads artifacts" { export BUILDKITE_PLUGIN_CODECLIMATE_TEST_REPORTER_INSTALL="false" export BUILDKITE_PLUGIN_CODECLIMATE_TEST_REPORTER_FORMAT="false"