Skip to content

Commit bfa29f4

Browse files
committed
Add CI on CSparseSolvers
1 parent 6049c38 commit bfa29f4

1 file changed

Lines changed: 164 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
8+
jobs:
9+
build-and-test:
10+
name: Run on ${{ matrix.os }} with SOFA ${{ matrix.sofa_branch }}
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
os: [ubuntu-22.04, macos-14, windows-2022]
16+
sofa_branch: [master]
17+
18+
steps:
19+
20+
- name: Setup SOFA and environment
21+
id: sofa
22+
uses: sofa-framework/sofa-setup-action@v5
23+
with:
24+
sofa_root: ${{ github.workspace }}/sofa
25+
sofa_version: ${{ matrix.sofa_branch }}
26+
sofa_scope: 'standard'
27+
sofa_with_sofapython3: 'true'
28+
29+
- name: Checkout source code
30+
uses: actions/checkout@v2
31+
with:
32+
path: ${{ env.WORKSPACE_SRC_PATH }}
33+
34+
- name: Build and install
35+
id: build-and-install
36+
shell: bash
37+
run: |
38+
cmake_options="-GNinja \
39+
-DCMAKE_BUILD_TYPE=Release \
40+
-DCMAKE_INSTALL_PREFIX="$WORKSPACE_INSTALL_PATH" \
41+
-DCMAKE_PREFIX_PATH="$SOFA_ROOT/lib/cmake" \
42+
-DSOFA_ALLOW_FETCH_DEPENDENCIES=ON \
43+
"
44+
if [ -e "$(command -v ccache)" ]; then
45+
cmake_options="$cmake_options -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache"
46+
fi
47+
cmake_options="$(echo $cmake_options)" # prettify
48+
49+
if [[ "$RUNNER_OS" == "Windows" ]]; then
50+
cmd //c "${{ steps.sofa.outputs.vs_vsdevcmd }} \
51+
&& cd /d $WORKSPACE_BUILD_PATH \
52+
&& cmake $cmake_options ../src \
53+
&& ninja install"
54+
else
55+
cd "$WORKSPACE_BUILD_PATH"
56+
ccache -z
57+
cmake $cmake_options ../src
58+
ninja install
59+
echo ${CCACHE_BASEDIR}
60+
ccache -s
61+
fi
62+
63+
- name: Sanitize artifact name
64+
id: sanitize
65+
# This step removes special characters from the artifact name to ensure compatibility with upload-artifact
66+
# Characters removed: " : < > | * ? \r \n \ /
67+
# Spaces are replaced with underscores
68+
# This sanitization prevents errors in artifact creation and retrieval
69+
shell: pwsh
70+
run: |
71+
$originalName = "CSparseSolvers_${{ steps.sofa.outputs.run_branch }}_for-SOFA-${{ steps.sofa.outputs.sofa_version }}_${{ runner.os }}"
72+
$artifact_name = $originalName -replace '[":;<>|*?\r\n\\/]', '' -replace ' ', '_'
73+
echo "artifact_name=$artifact_name" >> $env:GITHUB_OUTPUT
74+
75+
- name: Create artifact
76+
id: create-artifact
77+
uses: actions/upload-artifact@v4.4.0
78+
with:
79+
name: ${{ steps.sanitize.outputs.artifact_name }}
80+
path: ${{ env.WORKSPACE_INSTALL_PATH }}
81+
82+
- name: Install artifact
83+
id: install-artifact
84+
uses: actions/download-artifact@v4.1.7
85+
with:
86+
name: ${{ steps.sanitize.outputs.artifact_name }}
87+
path: ${{ env.WORKSPACE_ARTIFACT_PATH }}
88+
89+
90+
- name: Set env vars for tests
91+
shell: bash
92+
run: |
93+
# Set env vars for tests
94+
if [[ "$RUNNER_OS" == "Windows" ]]; then
95+
echo "$WORKSPACE_ARTIFACT_PATH/lib" >> $GITHUB_PATH
96+
echo "$WORKSPACE_ARTIFACT_PATH/bin" >> $GITHUB_PATH
97+
echo "$SOFA_ROOT/plugins/SofaPython3/bin" >> $GITHUB_PATH
98+
echo "SOFA_PLUGIN_PATH=$WORKSPACE_ARTIFACT_PATH/bin" | tee -a $GITHUB_ENV
99+
else
100+
echo "SOFA_PLUGIN_PATH=$WORKSPACE_ARTIFACT_PATH/lib" | tee -a $GITHUB_ENV
101+
fi
102+
103+
if [[ "$RUNNER_OS" == "macOS" ]]; then
104+
echo "DYLD_LIBRARY_PATH=$WORKSPACE_ARTIFACT_PATH/lib:$SOFA_ROOT/lib:$SOFA_ROOT/plugins/SofaPython3/lib:$DYLD_LIBRARY_PATH" | tee -a $GITHUB_ENV
105+
fi
106+
107+
if [[ "$RUNNER_OS" == "Linux" ]]; then
108+
echo "LD_LIBRARY_PATH=$WORKSPACE_ARTIFACT_PATH/lib:$SOFA_ROOT/lib:$SOFA_ROOT/plugins/SofaPython3/lib:$LD_LIBRARY_PATH" | tee -a $GITHUB_ENV
109+
fi
110+
111+
- name: Notify dashboard
112+
if: always() && startsWith(github.repository, 'sofa-framework') && startsWith(github.ref, 'refs/heads/master') # we are not on a fork and on master
113+
env:
114+
DASH_AUTH: ${{ secrets.PLUGIN_DASH }}
115+
shell: bash
116+
run: |
117+
build_status=$([ '${{ steps.build-and-install.outcome }}' == 'success' ] && \
118+
echo 'true' || echo 'false')
119+
120+
binary_status=$([ '${{ steps.create-artifact.outcome }}' == 'success' ] && \
121+
[ '${{ steps.install-artifact.outcome }}' == 'success' ] && \
122+
[ '${{ steps.sanitize.outcome }}' == 'success' ] && \
123+
echo 'true' || echo 'false')
124+
125+
126+
curl -X POST -H "X-API-KEY: $DASH_AUTH" -H "Content-Type: application/json" -d \
127+
"{\"id\":\"$(echo "${{ github.repository }}" | awk -F/ '{ print $2 }')\",\
128+
\"github_ref\":\"${{ github.sha }}\",\
129+
\"url\":\"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\",\
130+
\"build\":$build_status,\
131+
\"tests\":$test_status,\
132+
\"binary\":$binary_status}"\
133+
https://sofa-framework.org:5000/api/v1/plugins
134+
135+
deploy:
136+
name: Deploy artifacts
137+
if: always() && startsWith(github.ref, 'refs/heads/') # we are on a branch (not a PR)
138+
needs: [build-and-test]
139+
runs-on: ubuntu-latest
140+
continue-on-error: true
141+
steps:
142+
- name: Get artifacts
143+
uses: actions/download-artifact@v4.1.7
144+
with:
145+
path: artifacts
146+
147+
- name: Zip artifacts
148+
shell: bash
149+
run: |
150+
cd $GITHUB_WORKSPACE/artifacts
151+
for artifact in *; do
152+
zip $artifact.zip -r $artifact/*
153+
done
154+
- name: Upload release
155+
uses: softprops/action-gh-release@v1
156+
with:
157+
name: ${{ github.ref_name }}
158+
tag_name: release-${{ github.ref_name }}
159+
fail_on_unmatched_files: false
160+
target_commitish: ${{ github.ref_name }}
161+
files: |
162+
artifacts/CSparseSolvers_*_Linux.zip
163+
artifacts/CSparseSolvers_*_Windows.zip
164+
artifacts/CSparseSolvers_*_macOS.zip

0 commit comments

Comments
 (0)