[ci] new logic for ci workflow to use macOS only on demand or for releases #228
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| tags: | |
| - 'v*' #release tags in format of e.g: 'v25.12.00' | |
| pull_request: | |
| types: [opened, synchronize, reopened, labeled] | |
| workflow_dispatch: | |
| inputs: | |
| full_build: | |
| description: "Run full build (including macOS)" | |
| required: false | |
| default: false | |
| type: boolean | |
| jobs: | |
| prepare: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| os_list: ${{ steps.set.outputs.os_list }} | |
| steps: | |
| - id: set | |
| run: | | |
| if [[ "${{ github.event_name }}" == "pull_request" ]] || | |
| [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" != refs/tags/v* ]] || | |
| [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ inputs.full_build }}" != "true" ]]; then | |
| echo 'os_list=["ubuntu-22.04","windows-2022"]' >> $GITHUB_OUTPUT | |
| else | |
| echo 'os_list=["ubuntu-22.04","windows-2022","macos-14"]' >> $GITHUB_OUTPUT | |
| fi | |
| - name: Debug | |
| run: echo '${{ steps.set.outputs.os_list }}' | |
| build-and-test: | |
| needs: prepare | |
| name: Run on ${{ matrix.os }} with SOFA ${{ matrix.sofa_branch }} | |
| if: > | |
| github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v') || | |
| ( | |
| github.event_name == 'pull_request' && | |
| ( | |
| contains(github.event.pull_request.labels.*.name, 'pr: run ci') && | |
| ( | |
| github.event.action != 'labeled' || | |
| github.event.label.name == 'pr: run ci' | |
| ) | |
| ) | |
| ) | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: ${{ fromJSON(needs.prepare.outputs.os_list) }} | |
| sofa_branch: [master] | |
| steps: | |
| ####################### Setup SOFA ####################### | |
| - name: Setup SOFA and environment | |
| id: sofa | |
| uses: sofa-framework/sofa-setup-action@v5 | |
| with: | |
| sofa_root: ${{ github.workspace }}/sofa | |
| sofa_version: ${{ matrix.sofa_branch }} | |
| sofa_scope: 'full' | |
| ################# Checkout current repository ############## | |
| - name: Checkout CollisionAlgorithm | |
| uses: actions/checkout@v4 | |
| with: | |
| path: ${{ env.WORKSPACE_SRC_PATH }} | |
| ################ Build and install current plugin ############## | |
| - name: Build and install CollisionAlgorithm | |
| id: build-install | |
| shell: bash | |
| run: | | |
| if [[ "$RUNNER_OS" == "Windows" ]]; then | |
| cmd //c "${{ steps.sofa.outputs.vs_vsdevcmd }} \ | |
| && cd /d %GITHUB_WORKSPACE%/build \ | |
| && cmake \ | |
| -GNinja \ | |
| -DCMAKE_PREFIX_PATH="$SOFA_ROOT/lib/cmake" \ | |
| -DCMAKE_BUILD_TYPE=Release \ | |
| -DCMAKE_INSTALL_PREFIX="$WORKSPACE_INSTALL_PATH" \ | |
| -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=%WORKSPACE_BUILD_PATH% \ | |
| ../src \ | |
| && ninja install" | |
| else | |
| cd "$WORKSPACE_BUILD_PATH" | |
| ccache -z | |
| cmake \ | |
| -GNinja \ | |
| -DCMAKE_C_COMPILER_LAUNCHER=ccache \ | |
| -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ | |
| -DCMAKE_PREFIX_PATH=$SOFA_ROOT/lib/cmake \ | |
| -DCMAKE_BUILD_TYPE=Release \ | |
| -DCMAKE_INSTALL_PREFIX="$WORKSPACE_INSTALL_PATH" \ | |
| -DCMAKE_LIBRARY_OUTPUT_DIRECTORY="$WORKSPACE_BUILD_PATH/lib" \ | |
| ../src | |
| ninja install | |
| echo ${CCACHE_BASEDIR} | |
| ccache -s | |
| fi | |
| - name: Checkout ConstraintGeometry | |
| uses: actions/checkout@v2 | |
| with: | |
| repository: InfinyTech3D/ConstraintGeometry | |
| path: downstream/ConstraintGeometry | |
| - name: Build ConstraintGeometry | |
| shell: bash | |
| run: | | |
| mkdir -p downstream/ConstraintGeometry/build | |
| if [[ "$RUNNER_OS" == "Windows" ]]; then | |
| cmd //c "${{ steps.sofa.outputs.vs_vsdevcmd }} \ | |
| && cd /d %GITHUB_WORKSPACE%/downstream/ConstraintGeometry/build \ | |
| && cmake \ | |
| -GNinja \ | |
| -DCMAKE_PREFIX_PATH=$SOFA_ROOT/lib/cmake;%WORKSPACE_INSTALL_PATH%/lib/cmake \ | |
| -DCMAKE_BUILD_TYPE=Release \ | |
| -DCMAKE_INSTALL_PREFIX=%GITHUB_WORKSPACE%/downstream/ConstraintGeometry/install \ | |
| -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=%WORKSPACE_BUILD_PATH% \ | |
| .. \ | |
| && ninja install" | |
| else | |
| cd downstream/ConstraintGeometry/build | |
| cmake \ | |
| -GNinja \ | |
| -DCMAKE_PREFIX_PATH="$SOFA_ROOT/lib/cmake;$WORKSPACE_INSTALL_PATH/lib/cmake" \ | |
| -DCMAKE_BUILD_TYPE=Release \ | |
| -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/downstream/ConstraintGeometry/install \ | |
| -DCMAKE_LIBRARY_OUTPUT_DIRECTORY="$WORKSPACE_BUILD_PATH/lib" \ | |
| .. | |
| ninja install | |
| fi | |
| ################### Artifact naming ############## | |
| - name: Sanitize artifact name | |
| id: sanitize | |
| # This step removes special characters from the artifact name to ensure compatibility with upload-artifact | |
| # Characters removed: " : < > | * ? \r \n \ / | |
| # Spaces are replaced with underscores | |
| # This sanitization prevents errors in artifact creation and retrieval | |
| shell: pwsh | |
| run: | | |
| $originalName = "CollisionAlgorithm_${{ steps.sofa.outputs.run_branch }}_for-SOFA-${{ steps.sofa.outputs.sofa_version }}_${{ runner.os }}" | |
| $artifact_name = $originalName -replace '[":;<>|*?\r\n\\/]', '' -replace ' ', '_' | |
| echo "artifact_name=$artifact_name" >> $env:GITHUB_OUTPUT | |
| ################### Create and upload artifact ############## | |
| - name: Create artifact | |
| id: create-artifact | |
| uses: actions/upload-artifact@v4.4.0 | |
| with: | |
| name: ${{ steps.sanitize.outputs.artifact_name }} | |
| path: ${{ env.WORKSPACE_INSTALL_PATH }} | |
| - name: Install artifact | |
| id: install-artifact | |
| uses: actions/download-artifact@v4.1.7 | |
| with: | |
| name: ${{ steps.sanitize.outputs.artifact_name }} | |
| path: ${{ env.WORKSPACE_ARTIFACT_PATH }} | |
| ################### Tests ############## | |
| - name: Launch test | |
| id: tests | |
| uses: sofa-framework/sofa-test-action@v1.0 | |
| with: | |
| sofa_root: ${{ github.workspace }}/sofa | |
| sofa_version: ${{ steps.sofa.outputs.sofa_version }} | |
| src_dir: ${{ env.WORKSPACE_SRC_PATH }} | |
| build_dir: ${{ env.WORKSPACE_BUILD_PATH }} | |
| python_exe: ${{ steps.sofa.outputs.python_exe }} | |
| output_dir: ${{ github.workspace }}/tests-results_dir | |
| nb_parallel_threads: '4' | |
| ################### Create plugin artifacts ############## | |
| deploy: | |
| name: Deploy artifacts | |
| if: always() && startsWith(github.ref, 'refs/tags/v') | |
| needs: [build-and-test] | |
| runs-on: ubuntu-latest | |
| continue-on-error: true | |
| steps: | |
| - name: Get artifacts | |
| uses: actions/download-artifact@v4.1.7 | |
| with: | |
| path: artifacts | |
| - name: Zip artifacts | |
| shell: bash | |
| run: | | |
| cd $GITHUB_WORKSPACE/artifacts | |
| for artifact in *; do | |
| zip $artifact.zip -r $artifact/* | |
| done | |
| - name: Upload release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| name: ${{ github.ref_name }} | |
| tag_name: release-${{ github.ref_name }} | |
| fail_on_unmatched_files: true | |
| files: | | |
| artifacts/CollisionAlgorithm_*_Linux.zip | |
| artifacts/CollisionAlgorithm_*_Windows.zip | |
| artifacts/CollisionAlgorithm_*_macOS.zip |