Skip to content

Commit d845fde

Browse files
authored
update build and test pipeline (#55)
* update build and test pipeline - now includes macos * maybe macos fix * fix? * use sstream
1 parent 5bbe0fe commit d845fde

File tree

6 files changed

+37
-24
lines changed

6 files changed

+37
-24
lines changed

.github/workflows/cmake-clang-gcc.yaml

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CMake on Linux (GCC and Clang)
1+
name: CMake (Linux + macOS, GCC and Clang)
22

33
on:
44
push:
@@ -7,40 +7,50 @@ on:
77
branches: [ "main" ]
88

99
jobs:
10-
test:
11-
runs-on: ubuntu-latest
12-
10+
build-and-test:
1311
strategy:
1412
fail-fast: false
1513
matrix:
16-
build_type: [Release]
14+
os: [ubuntu-latest, macos-latest]
15+
build_type: [Debug, Release]
1716
c_compiler: [gcc, clang]
1817
include:
19-
- c_compiler: gcc
18+
# Linux (GCC + Clang)
19+
- os: ubuntu-latest
20+
c_compiler: gcc
2021
cpp_compiler: g++
21-
- c_compiler: clang
22+
- os: ubuntu-latest
23+
c_compiler: clang
24+
cpp_compiler: clang++
25+
# macOS (Clang only)
26+
- os: macos-latest
27+
c_compiler: clang
2228
cpp_compiler: clang++
29+
exclude:
30+
# Don’t try gcc on macOS (not preinstalled)
31+
- os: macos-latest
32+
c_compiler: gcc
33+
34+
runs-on: ${{ matrix.os }}
2335

2436
steps:
2537
- uses: actions/checkout@v4
2638

27-
- name: Set reusable strings
28-
id: strings
29-
shell: bash
30-
run: echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
39+
- name: Set build dir
40+
id: vars
41+
run: echo "BUILD_DIR=${{ github.workspace }}/build-${{ matrix.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}" >> $GITHUB_ENV
3142

3243
- name: Configure CMake
3344
run: >
34-
cmake -B ${{ steps.strings.outputs.build-output-dir }}
45+
cmake -B $BUILD_DIR
3546
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
3647
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
3748
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
3849
-S ${{ github.workspace }}
3950
4051
- name: Build
41-
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
52+
run: cmake --build $BUILD_DIR --config ${{ matrix.build_type }}
4253

4354
- name: Test
44-
working-directory: ${{ steps.strings.outputs.build-output-dir }}
55+
working-directory: ${{ env.BUILD_DIR }}
4556
run: ctest --build-config ${{ matrix.build_type }}
46-

src/errors.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#pragma once
22

3+
#include <format>
34
#include <stdexcept>
45

56
// Main error class
67
class TaskrError : public std::runtime_error {
78
public:
8-
explicit TaskrError(const std::string &msg) : std::runtime_error("TaskrError: " + msg) {}
9+
explicit TaskrError(const std::string &msg) : std::runtime_error(std::format("TaskrError: {}", msg)) {}
910
};
1011

1112
// CLI errors
@@ -17,16 +18,17 @@ class ArgError : public TaskrError {
1718
// Configuration errors
1819
class MultiConfigError : public TaskrError {
1920
public:
20-
explicit MultiConfigError(const std::string &msg) : TaskrError("Multiple configurations found: " + msg) {}
21+
explicit MultiConfigError(const std::string &msg)
22+
: TaskrError(std::format("Multiple configurations found: {}", msg)) {}
2123
};
2224

2325
class FileNotFoundError : public TaskrError {
2426
public:
25-
explicit FileNotFoundError(const std::string &msg) : TaskrError("File not found: " + msg) {}
27+
explicit FileNotFoundError(const std::string &msg) : TaskrError(std::format("File not found: {}", msg)) {}
2628
};
2729

2830
// Parser Errors
2931
class ParseError : public TaskrError {
3032
public:
31-
explicit ParseError(const std::string &msg) : TaskrError("Parse error: " + msg) {}
33+
explicit ParseError(const std::string &msg) : TaskrError(std::format("Parse error: {}", msg)) {}
3234
};

src/executor.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "config.h"
44
#include "errors.hpp"
55
#include <algorithm>
6+
#include <format>
67
#include <unordered_set>
78
#include <vector>
89

@@ -21,7 +22,7 @@ class TaskrExecutor {
2122

2223
const Task *task = find_task(config, taskName);
2324
if (!task) {
24-
throw TaskrError("Task not found: " + taskName);
25+
throw TaskrError(std::format("Task not found: {}", taskName));
2526
}
2627

2728
visited.insert(task->name);

src/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "executor.hpp"
33
#include "parser.hpp"
44
#include "util.hpp"
5+
#include <format>
56
#include <fstream>
67
#include <iostream>
78
#include <ostream>
@@ -124,7 +125,7 @@ int main(int argc, char *argv[]) {
124125
};
125126

126127
if (config.environments.find(envName) == config.environments.end()) {
127-
throw TaskrError("No environment '" + envName + "' found in config");
128+
throw TaskrError(std::format("No environment '{}' found in config", envName));
128129
}
129130

130131
std::ifstream file(config.environments.at(envName).file);
@@ -144,7 +145,7 @@ int main(int argc, char *argv[]) {
144145
auto it = std::find(definedTasksAndAliases.begin(), definedTasksAndAliases.end(), taskName);
145146

146147
if (it == definedTasksAndAliases.end()) {
147-
throw TaskrError("Task or alias '" + taskName + "' not found");
148+
throw TaskrError(std::format("Task or alias '{}' not found", taskName));
148149
}
149150

150151
executor.execute(config, taskName);

src/parser.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "config.h"
44
#include "errors.hpp"
55
#include "util.hpp"
6-
#include <cstdlib>
76
#include <regex>
87
#include <string>
98
#include <unordered_map>

src/util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "errors.hpp"
44
#include <algorithm>
55
#include <filesystem>
6-
#include <string>
6+
#include <sstream>
77
#include <vector>
88

99
namespace fs = std::filesystem;

0 commit comments

Comments
 (0)