generated from DARMA-tasking/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (159 loc) · 6.08 KB
/
build-and-test.yml
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
name: PR tests
on:
push:
branches:
- '*' # master
pull_request:
branches:
- '*'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WF_REPO: DARMA-tasking/workflows
WF_BRANCH: master
jobs:
get-matrix:
name: Get matrix
runs-on: ubuntu-latest
steps:
# Note: Filtering the test environments
# A jq query can be used to filter the matrix of test environments
# - All (default): `matrix=$(cat github.json | jq '.matrix')`
# - CLang only: `matrix=$(cat github.json | jq '.matrix | map(select(.label | contains("clang")))')`
# - gcc>=11: `matrix=$(cat github.json | jq '.matrix | map(select(.name | test("gcc-[1-9][1-9]+")))')`
# - gcc>=11|clang>=14 `matrix=$(cat github.json | jq '.matrix | map(select(.name | test("gcc-[1-9][1-9]+-|clang-[1-9][2-9]+")))')`
- name: Get matrix
id: get-matrix
run: |
wget https://raw.githubusercontent.com/${{ env.WF_REPO }}/refs/heads/${{ env.WF_BRANCH }}/ci/shared/matrix/github.json
matrix=$(cat github.json | jq '.matrix')
echo "runner=$(echo $matrix)" >> $GITHUB_OUTPUT
outputs:
matrix: ${{ steps.get-matrix.outputs.runner }}
run:
name: Run ${{ matrix.runner.name }}
runs-on: ${{ matrix.runner.runs-on }}
needs: get-matrix
env:
TS_YEAR: ~
TS_MONTH: ~
TS_DAY: ~
TS: ~
BUILD_DIR: /opt/foo/build
OUTPUT_DIR: /opt/foo/output
CCACHE_DIR: /opt/foo/build/ccache
COVERAGE_ENABLED: ${{ matrix.runner.name == 'wf-amd64-ubuntu-22.04-gcc-12-cpp' && 1 || 0 }}
JUNIT_REPORT_PATH: /opt/foo/output/junit.xml
strategy:
fail-fast: false
matrix:
runner: ${{ fromJson(needs.get-matrix.outputs.matrix ) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Display configuration
run: |
echo "Environment=${{ matrix.runner.name }}"
echo "Runner=${{ matrix.runner.runs-on }}"
if [ "${{ matrix.runner.image }}" != "" ]
then
echo "> With Docker Image=${{ matrix.runner.image }}"
else
echo "> With Runner Setup=${{ matrix.runner.setup }}"
fi
- name: Set up dependencies
run: |
if [[ "${{ matrix.runner.image }}" == "" ]]; then
echo "::group::Setup in runner"
echo "Set setup permissions..."
sudo mkdir -p /opt
sudo chown $(whoami) /opt
wget -O setup.sh https://raw.githubusercontent.com/${{ env.WF_REPO }}/refs/heads/${{ env.WF_BRANCH }}/ci/shared/scripts/setup-${{ matrix.runner.setup }}.sh
chmod +x setup.sh
export WF_SETUP_ID=${{ matrix.runner.setup }}
./setup.sh
echo "::endgroup::"
elif [ "${{ matrix.runner.image }}" != "" ]; then
echo "::group::Pull Docker image"
docker image pull ${{ matrix.runner.image }}
echo "::endgroup::"
fi
- name: Display System Information
run: |
CMD="uname -a"
if [[ "${{ matrix.runner.image }}" == "" ]]
then
echo "Runner System Information:"
$CMD
else
echo "Docker System Information:"
docker run ${{ matrix.runner.image }} $CMD
fi
- name: Build timestamp for caching
continue-on-error: true
run: |
echo "TS_YEAR=$(date -u +%Y)" >> $GITHUB_ENV
echo "TS_MONTH=$(date -u +%m)" >> $GITHUB_ENV
echo "TS_DAY=$(date -u +%d)" >> $GITHUB_ENV
echo "TS=$(date -u +%H%M%S)" >> $GITHUB_ENV
- name: Update cache
continue-on-error: true
uses: actions/cache@v3
env:
cache_name: ${{ matrix.runner.name }}
with:
path: ${{ env.CCACHE_DIR }}
key: ${{ runner.os }}-${{ env.cache_name }}-${{ env.TS_YEAR }}-${{ env.TS_MONTH }}-${{ env.TS_DAY }}-${{ env.TS }}
restore-keys: |
${{ runner.os }}-${{ env.cache_name }}-${{ env.TS_YEAR }}-${{ env.TS_MONTH }}-${{ env.TS_DAY }}-
${{ runner.os }}-${{ env.cache_name }}-${{ env.TS_YEAR }}-${{ env.TS_MONTH }}-
${{ runner.os }}-${{ env.cache_name }}-${{ env.TS_YEAR }}-
${{ runner.os }}-${{ env.cache_name }}-
- name: PR tests
run: |
WORKSPACE=${{ github.workspace }}
if [[ "${{ matrix.runner.image }}" != "" ]]; then
WORKSPACE=/workspace
fi
CMD='
cd '${WORKSPACE}'; \
ls -l; \
chmod +x ./build.sh; \
\
FOO_COVERAGE_ENABLED="${{ env.COVERAGE_ENABLED }}" \
FOO_TEST_REPORT="${{ env.JUNIT_REPORT_PATH }}" \
./build.sh'
echo "Running ${CMD}"
if [[ "${{ matrix.runner.image }}" == "" ]]; then
bash -c "export $(cat .env | sed '/^[[:blank:]]*#/d;s/#.*//' | xargs) && $CMD";
else
docker run \
--name test-container \
--env-file .env \
-w $WORKSPACE \
-v ${{ github.workspace }}:/workspace \
-v ${{ env.BUILD_DIR }}:/opt/foo/build \
-v ${{ env.OUTPUT_DIR }}:/opt/foo/output \
-e CI="1" \
-e https_proxy="" \
-e http_proxy="" \
${{ matrix.runner.image }} \
bash -c "$CMD"
exit $(docker container inspect --format '{{.State.ExitCode}}' test-container)
fi
if [ -f "$FOO_TEST_REPORT" ]; then
echo "JUNIT_REPORT_PATH=${FOO_TEST_REPORT}" >> "$GITHUB_OUTPUT"
fi
- name: Unit tests
if: (success() || failure()) && ${{ env.JUNIT_REPORT_PATH != '' }}
uses: phoenix-actions/test-reporting@v15
with:
name: Tests report
path: ${{ env.JUNIT_REPORT_PATH }}
reporter: java-junit
output-to: step-summary
- name: Upload artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: foo-output-${{ matrix.runner.name }}
path: ${{ env.OUTPUT_DIR }}