-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (65 loc) · 3.18 KB
/
basic_workflow.yml
File metadata and controls
68 lines (65 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# The name showed in the GitHub Actions tab.
name: Basic workflow
# When the workflow should run. You can have multiple events.
on: # Events can be related to repository, time, manual trigger, other.
#push: # You can limit the event to changes in specific files using "paths".
# branches: [ master ] # You use regex like release/*.
workflow_dispatch: # Manual trigger with no option.
# The jobs of the workflow, that runs in parallel by default.
jobs:
# The ID of the 1st job. Here to find all library/ sub-directories.
discover:
# The name of the job showed in GitHub Actions tab.
name: Discover Libraries
# The OS to run the job on.
runs-on: ubuntu-latest # Images removed often: 20.04 already unavailable.
# This job creates an output other jobs can use.
outputs:
# Here, "patterns" is the name of the variable that stores the job output.
patterns: ${{ steps.matrix.outputs.patterns }} # Value from step "matrix".
# Each job has a sequence of sequential steps.
steps:
# Execute an official GitHub action stored in the homonymous repository.
- name: "Checkout code"
uses: actions/checkout@v4 # Check out the code, so usually done first.
# Finally find all the library sub-directories.
- name: "Build the strategy matrix"
id: matrix
# What will be done:
# - from GoF/behavioral/, find directories called "library";
# - from their paths, removes the prefix "GoF/behavioral/";
# - ... then also the suffix "library" (so keep only the pattern name);
# - create a json array like ["pattern1", "pattern2", ...].
# Finally, make that json the output of this job.
run: | # Pipe is used when multiple lines to run.
patterns=$(find GoF/behavioral/ -maxdepth 2 -name "library" -type d | sed 's|GoF/behavioral/||' | sed 's|/library||' | jq -R -s -c 'split("\n")[:-1]')
echo "patterns=$patterns" >> $GITHUB_OUTPUT
# Second job.
build:
# Execute it after the "discover" job, not in parallel as by default.
needs: discover
runs-on: ubuntu-latest
# Strategy allows to define different configurations to run in parallel.
strategy:
# Here the matrix of configurations is the array coming from previosu job.
matrix:
# ${{ }} GitHub expression; ${ } shell expresion.
pattern: ${{ fromJson(needs.discover.outputs.patterns) }}
steps:
# Example of step without name or id (they are not mandatory).
- uses: actions/checkout@v4
- name: Install GTest from source
run: |
git clone https://github.com/google/googletest.git
cd googletest
mkdir build && cd build
cmake .. -DBUILD_GMOCK=ON
make -j$(nproc)
sudo make install
# The steps that do the work. New shell, so no need to "cd ..".
- name: Create build directory
run: mkdir -p GoF/behavioral/${{ matrix.pattern }}/library/build/
- name: Configure CMake
run: cmake -S GoF/behavioral/${{ matrix.pattern }}/library/ -B GoF/behavioral/${{ matrix.pattern }}/library/build/
- name: Build project
run: cmake --build GoF/behavioral/${{ matrix.pattern }}/library/build/