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

Simplify ci. #39

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
83 changes: 12 additions & 71 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,84 +10,25 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
# The versions should contain (at least) the lowest requirement
# and a version that is more up to date.
toit-version: [ v2.0.0-alpha.120, latest ]
include:
- toit-version: v2.0.0-alpha.120
version-name: old
- toit-version: latest
version-name: new

name: CI - ${{ matrix.os }} - ${{ matrix.version-name }}

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3

- name: Setup constants
shell: bash
run: |
TOIT_VERSION=v2.0.0-alpha.120
echo "TOIT_VERSION=$TOIT_VERSION" >> $GITHUB_ENV
export DOWNLOAD_DIR="${{ github.workspace }}/downloads"
echo "DOWNLOAD_DIR=$DOWNLOAD_DIR" >> $GITHUB_ENV
if [[ "$RUNNER_OS" = "Linux" ]]; then
TOIT_FILE=toit-linux.tar.gz
echo "TOIT_EXEC=$DOWNLOAD_DIR/toit/bin/toit.run" >> $GITHUB_ENV
echo "TPKG_EXEC=$DOWNLOAD_DIR/toit/bin/toit.pkg" >> $GITHUB_ENV
elif [[ "$RUNNER_OS" = "macOS" ]]; then
TOIT_FILE=toit-macos.tar.gz
echo "TOIT_EXEC=$DOWNLOAD_DIR/toit/bin/toit.run" >> $GITHUB_ENV
echo "TPKG_EXEC=$DOWNLOAD_DIR/toit/bin/toit.pkg" >> $GITHUB_ENV
elif [[ "$RUNNER_OS" = "Windows" ]]; then
TOIT_FILE=toit-windows.tar.gz
echo "TOIT_EXEC=$DOWNLOAD_DIR/toit/bin/toit.run.exe" >> $GITHUB_ENV
echo "TPKG_EXEC=$DOWNLOAD_DIR/toit/bin/toit.pkg.exe" >> $GITHUB_ENV
else
echo "UNSUPPORTED RUNNER: $RUNNER_OS"
exit 1
fi

if [[ $TOIT_VERSION = latest ]]; then
echo "TOIT_URL=https://github.com/toitlang/toit/releases/latest/download/$TOIT_FILE" >> $GITHUB_ENV
else
echo "TOIT_URL=https://github.com/toitlang/toit/releases/download/$TOIT_VERSION/$TOIT_FILE" >> $GITHUB_ENV
fi

# Fetch the dependencies. Different for each platform.
- name: Install dependencies - Linux
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install ninja-build
ninja --version
cmake --version
- name: Install dependencies - macOS
if: runner.os == 'macOS'
run: |
brew install ninja
ninja --version
cmake --version
- name: Install dependencies - Windows
if: runner.os == 'Windows'
run: |
choco install ninja
ninja --version
cmake --version

- uses: suisei-cn/[email protected]
name: Download Toit
- uses: toitlang/action-setup@v1
with:
url: ${{ env.TOIT_URL }}
target: ${{ env.DOWNLOAD_DIR }}

- name: Extract Toit
shell: bash
run: |
cd "$DOWNLOAD_DIR"
tar x -f *.tar.gz

- name: Run cmake
shell: bash
run: |
make rebuild-cmake
cmake "-DTOIT_EXEC=$TOIT_EXEC" "-DTPKG_EXEC=$TPKG_EXEC" build

- name: Install packages
run: |
make install-pkgs
toit-version: ${{ matrix.toit-version }}

- name: Test
run: |
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

cmake_minimum_required(VERSION 3.23)

project(cli)
project(cli NONE)

enable_testing()
add_subdirectory(tests)
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ build/CMakeCache.txt:
$(MAKE) rebuild-cmake

install-pkgs: rebuild-cmake
(cd build && ninja install-pkgs)
cmake --build build --target install-pkgs

test: install-pkgs rebuild-cmake
(cd build && ninja check)
cmake --build build --target check

# We rebuild the cmake file all the time.
# We use "glob" in the cmakefile, and wouldn't otherwise notice if a new
# file (for example a test) was added or removed.
# It takes <1s on Linux to run cmake, so it doesn't hurt to run it frequently.
rebuild-cmake:
mkdir -p build
(cd build && cmake .. -G Ninja)
# We need to set a build type, otherwise cmake won't run nicely on Windows.
# The build-type is otherwise unused.
cmake -B build -DCMAKE_BUILD_TYPE=Debug

.PHONY: all test rebuild-cmake install-pkgs
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: cli
description: Tools, like an argument parser, to create command-line applications.
environment:
sdk: ^2.0.0-alpha.100
sdk: ^2.0.0-alpha.120
dependencies:
fs:
url: github.com/toitlang/pkg-fs
Expand Down
8 changes: 4 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# Use of this source code is governed by a Zero-Clause BSD license that can
# be found in the tests/LICENSE file.

file(GLOB TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*_test.toit" "*_test_slow.toit")
file(GLOB TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*_test.toit" "*-test.toit" "*_test_slow.toit" "*-test-slow.toit")

set(TOIT_EXEC "toit.run" CACHE FILEPATH "The executable used to run the tests")
set(TPKG_EXEC "toit.pkg" CACHE FILEPATH "The executable used to install the packages")
set(TOIT_EXEC "toit.run${CMAKE_EXECUTABLE_SUFFIX}" CACHE FILEPATH "The executable used to run the tests")
set(TPKG_EXEC "toit.pkg${CMAKE_EXECUTABLE_SUFFIX}" CACHE FILEPATH "The executable used to install the packages")
set(TEST_TIMEOUT 40 CACHE STRING "The maximal amount of time each test is allowed to run")
set(SLOW_TEST_TIMEOUT 200 CACHE STRING "The maximal amount of time each slow test is allowed to run")

Expand All @@ -21,7 +21,7 @@ ProcessorCount(NUM_CPU)

add_custom_target(
check
COMMAND ${CMAKE_CTEST_COMMAND} -j${NUM_CPU} -T test --output-on-failure
COMMAND ${CMAKE_CTEST_COMMAND} -j${NUM_CPU} -T test --output-on-failure -C Debug
USES_TERMINAL
)

Expand Down