|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + |
| 6 | +jobs: |
| 7 | + build-and-test: |
| 8 | + name: Run on ${{ matrix.os }} with SOFA ${{ matrix.sofa_branch }} |
| 9 | + runs-on: ${{ matrix.os }} |
| 10 | + strategy: |
| 11 | + fail-fast: false |
| 12 | + matrix: |
| 13 | + os: [ubuntu-22.04, macos-14, windows-2022] |
| 14 | + sofa_branch: [master] |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Setup SOFA and environment |
| 18 | + id: sofa |
| 19 | + uses: sofa-framework/sofa-setup-action@v5 |
| 20 | + with: |
| 21 | + sofa_root: ${{ github.workspace }}/sofa |
| 22 | + sofa_version: ${{ matrix.sofa_branch }} |
| 23 | + sofa_scope: 'standard' |
| 24 | + - name: Checkout source code |
| 25 | + uses: actions/checkout@v2 |
| 26 | + with: |
| 27 | + path: ${{ env.WORKSPACE_SRC_PATH }} |
| 28 | + |
| 29 | + - name: Build and install |
| 30 | + id: build-install |
| 31 | + shell: bash |
| 32 | + run: | |
| 33 | + if [[ "$RUNNER_OS" == "Windows" ]]; then |
| 34 | + cmd //c "${{ steps.sofa.outputs.vs_vsdevcmd }} \ |
| 35 | + && cd /d $WORKSPACE_BUILD_PATH \ |
| 36 | + && cmake \ |
| 37 | + -GNinja \ |
| 38 | + -DCMAKE_PREFIX_PATH="$SOFA_ROOT/lib/cmake" \ |
| 39 | + -DCMAKE_BUILD_TYPE=Release \ |
| 40 | + -DCMAKE_INSTALL_PREFIX="$WORKSPACE_INSTALL_PATH" \ |
| 41 | + ../src \ |
| 42 | + && ninja install" |
| 43 | + else |
| 44 | + cd "$WORKSPACE_BUILD_PATH" |
| 45 | + ccache -z |
| 46 | + cmake \ |
| 47 | + -GNinja \ |
| 48 | + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ |
| 49 | + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ |
| 50 | + -DCMAKE_PREFIX_PATH=$SOFA_ROOT/lib/cmake \ |
| 51 | + -DCMAKE_BUILD_TYPE=Release \ |
| 52 | + -DCMAKE_INSTALL_PREFIX="$WORKSPACE_INSTALL_PATH" \ |
| 53 | + ../src |
| 54 | + ninja install |
| 55 | + echo ${CCACHE_BASEDIR} |
| 56 | + ccache -s |
| 57 | + fi |
| 58 | + |
| 59 | + - name: Sanitize artifact name |
| 60 | + id: sanitize |
| 61 | + # This step removes special characters from the artifact name to ensure compatibility with upload-artifact |
| 62 | + # Characters removed: " : < > | * ? \r \n \ / |
| 63 | + # Spaces are replaced with underscores |
| 64 | + # This sanitization prevents errors in artifact creation and retrieval |
| 65 | + shell: pwsh |
| 66 | + run: | |
| 67 | + $originalName = "CollisionAlgorithm_${{ steps.sofa.outputs.run_branch }}_for-SOFA-${{ steps.sofa.outputs.sofa_version }}_${{ runner.os }}" |
| 68 | + $artifact_name = $originalName -replace '[":;<>|*?\r\n\\/]', '' -replace ' ', '_' |
| 69 | + echo "artifact_name=$artifact_name" >> $env:GITHUB_OUTPUT |
| 70 | + |
| 71 | + - name: Create artifact |
| 72 | + id: create-artifact |
| 73 | + |
| 74 | + with: |
| 75 | + name: ${{ steps.sanitize.outputs.artifact_name }} |
| 76 | + path: ${{ env.WORKSPACE_INSTALL_PATH }} |
| 77 | + |
| 78 | + - name: Install artifact |
| 79 | + id: install-artifact |
| 80 | + |
| 81 | + with: |
| 82 | + name: ${{ steps.sanitize.outputs.artifact_name }} |
| 83 | + path: ${{ env.WORKSPACE_ARTIFACT_PATH }} |
| 84 | + |
| 85 | + - name: Set env vars for tests |
| 86 | + shell: bash |
| 87 | + run: | |
| 88 | + # Set env vars for tests |
| 89 | + if [[ "$RUNNER_OS" == "Windows" ]]; then |
| 90 | + echo "$WORKSPACE_ARTIFACT_PATH/lib" >> $GITHUB_PATH |
| 91 | + echo "$WORKSPACE_ARTIFACT_PATH/bin" >> $GITHUB_PATH |
| 92 | + echo "$SOFA_ROOT/plugins/SofaPython3/bin" >> $GITHUB_PATH |
| 93 | + echo "SOFA_PLUGIN_PATH=$WORKSPACE_ARTIFACT_PATH/bin" | tee -a $GITHUB_ENV |
| 94 | + else |
| 95 | + echo "SOFA_PLUGIN_PATH=$WORKSPACE_ARTIFACT_PATH/lib" | tee -a $GITHUB_ENV |
| 96 | + fi |
| 97 | +
|
| 98 | + if [[ "$RUNNER_OS" == "macOS" ]]; then |
| 99 | + echo "DYLD_LIBRARY_PATH=$WORKSPACE_ARTIFACT_PATH/lib:$SOFA_ROOT/lib:$SOFA_ROOT/plugins/SofaPython3/lib:$DYLD_LIBRARY_PATH" | tee -a $GITHUB_ENV |
| 100 | + fi |
| 101 | +
|
| 102 | + if [[ "$RUNNER_OS" == "Linux" ]]; then |
| 103 | + echo "LD_LIBRARY_PATH=$WORKSPACE_ARTIFACT_PATH/lib:$SOFA_ROOT/lib:$SOFA_ROOT/plugins/SofaPython3/lib:$LD_LIBRARY_PATH" | tee -a $GITHUB_ENV |
| 104 | + fi |
| 105 | +
|
| 106 | + deploy: |
| 107 | + name: Deploy artifacts |
| 108 | + if: always() && startsWith(github.ref, 'refs/heads/main') # we are on a branch (not a PR) |
| 109 | + needs: [build-and-test] |
| 110 | + runs-on: ubuntu-latest |
| 111 | + continue-on-error: true |
| 112 | + steps: |
| 113 | + - name: Get artifacts |
| 114 | + |
| 115 | + with: |
| 116 | + path: artifacts |
| 117 | + |
| 118 | + - name: Zip artifacts |
| 119 | + shell: bash |
| 120 | + run: | |
| 121 | + cd $GITHUB_WORKSPACE/artifacts |
| 122 | + for artifact in *; do |
| 123 | + zip $artifact.zip -r $artifact/* |
| 124 | + done |
| 125 | + - name: Upload release |
| 126 | + uses: softprops/action-gh-release@v1 |
| 127 | + with: |
| 128 | + name: ${{ github.ref_name }} |
| 129 | + tag_name: release-${{ github.ref_name }} |
| 130 | + fail_on_unmatched_files: true |
| 131 | + files: | |
| 132 | + artifacts/CollisionAlgorithm_*_Linux.zip |
| 133 | + artifacts/CollisionAlgorithm_*_Windows.zip |
| 134 | + artifacts/CollisionAlgorithm_*_macOS.zip |
| 135 | +
|
0 commit comments