Skip to content

Commit e48aab6

Browse files
authored
Merge pull request #5 from hugtalbot/202505_add_ci
Add CI on CSparseSolvers
2 parents 6049c38 + d94768d commit e48aab6

1 file changed

Lines changed: 141 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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+
- name: Notify dashboard
90+
if: always() && startsWith(github.repository, 'sofa-framework') && startsWith(github.ref, 'refs/heads/master') # we are not on a fork and on master
91+
env:
92+
DASH_AUTH: ${{ secrets.PLUGIN_DASH }}
93+
shell: bash
94+
run: |
95+
build_status=$([ '${{ steps.build-and-install.outcome }}' == 'success' ] && \
96+
echo 'true' || echo 'false')
97+
98+
binary_status=$([ '${{ steps.create-artifact.outcome }}' == 'success' ] && \
99+
[ '${{ steps.install-artifact.outcome }}' == 'success' ] && \
100+
[ '${{ steps.sanitize.outcome }}' == 'success' ] && \
101+
echo 'true' || echo 'false')
102+
103+
104+
curl -X POST -H "X-API-KEY: $DASH_AUTH" -H "Content-Type: application/json" -d \
105+
"{\"id\":\"$(echo "${{ github.repository }}" | awk -F/ '{ print $2 }')\",\
106+
\"github_ref\":\"${{ github.sha }}\",\
107+
\"url\":\"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\",\
108+
\"build\":$build_status,\
109+
\"binary\":$binary_status}"\
110+
https://sofa-framework.org:5000/api/v1/plugins
111+
112+
deploy:
113+
name: Deploy artifacts
114+
if: always() && startsWith(github.ref, 'refs/heads/') # we are on a branch (not a PR)
115+
needs: [build-and-test]
116+
runs-on: ubuntu-latest
117+
continue-on-error: true
118+
steps:
119+
- name: Get artifacts
120+
uses: actions/download-artifact@v4.1.7
121+
with:
122+
path: artifacts
123+
124+
- name: Zip artifacts
125+
shell: bash
126+
run: |
127+
cd $GITHUB_WORKSPACE/artifacts
128+
for artifact in *; do
129+
zip $artifact.zip -r $artifact/*
130+
done
131+
- name: Upload release
132+
uses: softprops/action-gh-release@v1
133+
with:
134+
name: ${{ github.ref_name }}
135+
tag_name: release-${{ github.ref_name }}
136+
fail_on_unmatched_files: false
137+
target_commitish: ${{ github.ref_name }}
138+
files: |
139+
artifacts/CSparseSolvers_*_Linux.zip
140+
artifacts/CSparseSolvers_*_Windows.zip
141+
artifacts/CSparseSolvers_*_macOS.zip

0 commit comments

Comments
 (0)