Skip to content

Commit 6f765f8

Browse files
committed
#1: add first ci
1 parent b81457d commit 6f765f8

File tree

2 files changed

+162
-4
lines changed

2 files changed

+162
-4
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Template workflow (Github Workflows). VT example.
2+
3+
# Build and test a project in all available setup configurations provided by DARMA-taking/workflows.
4+
# See also: Azure Pipelines version at ./azure/pipelines/build-and-test.yml
5+
6+
name: PR tests
7+
8+
on:
9+
push:
10+
branches:
11+
- '*' # master
12+
pull_request:
13+
branches:
14+
- '*'
15+
16+
env:
17+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
CI_REPO: DARMA-tasking/workflows
19+
CI_BRANCH: 2-implement-common-docker-containers # master
20+
21+
jobs:
22+
get-matrix:
23+
name: Get matrix
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Get matrix
27+
id: get-matrix
28+
run: |
29+
wget https://raw.githubusercontent.com/${{ env.CI_REPO }}/refs/heads/${{ env.CI_BRANCH }}/ci/shared/matrix/github.json
30+
matrix=$(cat github.json | jq '.matrix')
31+
echo "runner=$(echo $matrix)" >> $GITHUB_OUTPUT
32+
outputs:
33+
matrix: ${{ steps.get-matrix.outputs.runner }}
34+
35+
run:
36+
name: Run ${{ matrix.runner.name }}
37+
runs-on: ${{ matrix.runner.runs-on }}
38+
needs: get-matrix
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
runner: ${{ fromJson(needs.get-matrix.outputs.matrix ) }}
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v4
46+
47+
- name: Display configuration
48+
run: |
49+
echo "Environment=${{ matrix.runner.name }}"
50+
echo "Runner=${{ matrix.runner.runs-on }}"
51+
if [ "${{ matrix.runner.image }}" != "" ]
52+
then
53+
echo "> With Docker Image=${{ matrix.runner.image }}"
54+
else
55+
echo "> With Runner Setup=${{ matrix.runner.setup }}"
56+
fi
57+
58+
- name: Set up dependencies
59+
run: |
60+
if [[ "${{ matrix.runner.image }}" == "" ]]; then
61+
echo "::group::Setup in runner"
62+
echo "Set setup permissions..."
63+
sudo mkdir -p /opt
64+
sudo chown $(whoami) /opt
65+
wget -O setup.sh https://raw.githubusercontent.com/${{ env.CI_REPO }}/refs/heads/${{ env.CI_BRANCH }}/ci/shared/scripts/setup-${{ matrix.runner.setup }}.sh
66+
chmod +x setup.sh
67+
export WF_SETUP_ID=${{ matrix.runner.setup }}
68+
./setup.sh
69+
echo "::endgroup::"
70+
elif [[ "${{ matrix.runner.image }}" != "" ]]; then
71+
echo "::group::Pull Docker image"
72+
docker image pull ${{ matrix.runner.image }}
73+
echo "::endgroup::"
74+
fi
75+
76+
77+
# - name: Run (example)
78+
# run: |
79+
# CMD="uname -a"
80+
# if [[ "${{ matrix.runner.image }}" == "" ]]
81+
# then
82+
# $CMD
83+
# else
84+
# docker run ${{ matrix.runner.image }} $CMD
85+
# fi
86+
87+
# - name: Extract timestamps for caching
88+
# run: |
89+
# mkdir -p /opt/scripts
90+
# cd /opt/scripts
91+
# wget https://raw.githubusercontent.com/${{ env.CI_REPO }}/refs/heads/${{ env.CI_BRANCH }}/ci/shared/scripts/runner/set-variable.sh && chmod +x set-variable.sh
92+
# wget https://raw.githubusercontent.com/${{ env.CI_REPO }}/refs/heads/${{ env.CI_BRANCH }}/ci/shared/scripts/runner/set-timestamps.sh && chmod +x set-timestamps.sh
93+
# ./set-timestamps.sh
94+
95+
- name: Setup build cache (vt)
96+
run: |
97+
echo "TODO: implement cache usage if required by your project"
98+
99+
- name: PR tests env
100+
run: |
101+
echo 'TODO...'
102+
echo '1. Load environment variables from a matrix file (env set per env id) into .env'
103+
echo '2. Load .env file to build `export $(cat .env | egrep -v "(^#.*|^$)" | xargs) && ./build.sh`'
104+
105+
- name: PR tests
106+
run: |
107+
FOO_SRC_DIR=${{ github.workspace }}
108+
FOO_BUILD_DIR=/opt/foo/build
109+
if [[ "${{ matrix.runner.image }}" != "" ]]; then
110+
FOO_SRC_DIR=opt/foo/src
111+
fi
112+
CMD='
113+
cd $FOO_SRC_DIR; \
114+
chmod +x build.sh; \
115+
\
116+
FOO_BUILD_DIR='${FOO_BUILD_DIR}' \
117+
FOO_COVERAGE_ENABLED=ON \
118+
FOO_RUN_TESTS=ON \
119+
build.sh;'
120+
121+
echo "Running ${CMD}"
122+
123+
if [[ "${{ matrix.runner.image }}" == "" ]]; then
124+
bash -c "$CMD";
125+
else
126+
docker run \
127+
--name test-container \
128+
-w $FOO_SRC_DIR \
129+
-v ${{ github.workspace }}:/opt/foo/src \
130+
-v /opt/foo/build:/opt/foo/build \
131+
-v /opt/foo/output:/opt/foo/output \
132+
-e CI="1" \
133+
-e CMAKE_CXX_STANDARD="17" \
134+
-e CMAKE_BUILD_TYPE="Release" \
135+
${{ matrix.runner.image }} \
136+
bash -c "$CMD"
137+
exit $(docker container inspect --format '{{.State.ExitCode}}' test-container)
138+
fi
139+
140+
# - name: Build and test
141+
# TODO: Build an test step.
142+
# > Option 1: Docker image (Environment Setup="docker") WIP
143+
# - pull the docker image
144+
# - build & Test using `docker exec [container] build_and_test.sh` for example or by using an inner build_and_test docker image
145+
# - (TODO: copy artifacts using a volume)
146+
147+
# > Option 2: Current runner (Environment Setup="local") (Future for some macos)
148+
# - setup dependencies here directly
149+
# (Here a work needs to be done to determine how to get the dependencies script. It might be shared by the workflows repo and put in matrix)
150+
# - build & Test using build_and_test.sh
151+
152+
# - name: Upload artifacts
153+
154+
# - name: Report test results
155+
# note: (as in vt-tv or LBAF)
156+
157+
# - name: Report coverage

build.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
# Description: This script builds foo project
3+
# Description: This script builds foo project and optionnaly run tests and coverage
44

55
set -e
66

@@ -35,7 +35,8 @@ PARENT_DIR="$(dirname "$CURRENT_DIR")"
3535

3636
CC="${CC:-$(which gcc || echo '')}"
3737
CXX="${CXX:-$(which g++ || echo '')}"
38-
FOO_DIR="${FOO_DIR:-$CURRENT_DIR}"
38+
GCOV="${GCOV:-$(which gcov || echo '')}"
39+
FOO_SRC_DIR="${FOO_SRC_DIR:-$CURRENT_DIR}"
3940
FOO_BUILD_DIR="${FOO_BUILD_DIR:-$CURRENT_DIR/build}"
4041
FOO_OUTPUT_DIR="${FOO_OUTPUT_DIR:-$CURRENT_DIR/output}"
4142
# >> Build settings
@@ -50,7 +51,7 @@ FOO_WERROR_ENABLED=$(on_off ${FOO_WERROR_ENABLED:-OFF})
5051
# >> Run tests settings
5152
FOO_RUN_TESTS=$(on_off ${FOO_RUN_TESTS:-OFF})
5253
FOO_RUN_TESTS_FILTER=${FOO_RUN_TESTS_FILTER:-""}
53-
FOO_COVERAGE_REPORT=${FOO_COVERAGE_REPORT:-""}
54+
FOO_COVERAGE_REPORT=${FOO_COVERAGE_REPORT:-"${FOO_OUTPUT_DIR}/cov.html"}
5455

5556
# >> CLI args support
5657

@@ -177,7 +178,7 @@ if [[ "${FOO_BUILD}" == "ON" ]]; then
177178
-DFOO_TESTS_ENABLED=${FOO_TESTS_ENABLED} \
178179
-DFOO_COVERAGE_ENABLED=${FOO_COVERAGE_ENABLED} \
179180
\
180-
"${FOO_DIR}"
181+
"${FOO_SRC_DIR}"
181182

182183
time cmake --build . --parallel -j "${FOO_CMAKE_JOBS}"
183184

0 commit comments

Comments
 (0)