|
| 1 | +name: Build Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - 'releases/**' |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + - 'releases/**' |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + name: Build Docker image |
| 16 | + runs-on: ubuntu-latest |
| 17 | + timeout-minutes: 60 |
| 18 | + steps: |
| 19 | + - name: Check out the repo |
| 20 | + uses: actions/checkout@v5 |
| 21 | + |
| 22 | + - name: Extract metadata (tags, labels) for Docker |
| 23 | + id: meta |
| 24 | + uses: docker/metadata-action@v5 |
| 25 | + with: |
| 26 | + # Use GitHub Container Registry (ghcr) so the image can be pushed from the workflow |
| 27 | + images: ghcr.io/OpenModelica/crossbuild |
| 28 | + |
| 29 | + - name: Log in to GitHub Container Registry |
| 30 | + uses: docker/login-action@v3 |
| 31 | + with: |
| 32 | + registry: ghcr.io |
| 33 | + username: ${{ github.actor }} |
| 34 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + |
| 36 | + - name: Build and push Docker image |
| 37 | + id: build-image |
| 38 | + uses: docker/build-push-action@v6 |
| 39 | + with: |
| 40 | + context: . |
| 41 | + file: ./Dockerfile |
| 42 | + push: true |
| 43 | + tags: ${{ steps.meta.outputs.tags }} |
| 44 | + |
| 45 | + outputs: |
| 46 | + image: ${{ steps.meta.outputs.tags }} |
| 47 | + |
| 48 | + test-compile: |
| 49 | + name: Test Docker image across toolchains |
| 50 | + needs: build |
| 51 | + runs-on: ubuntu-latest |
| 52 | + strategy: |
| 53 | + fail-fast: false |
| 54 | + matrix: |
| 55 | + include: |
| 56 | + - toolchain: i686-linux-gnu |
| 57 | + fmi_platform_tuple: linux32 |
| 58 | + lib_extension: so |
| 59 | + - toolchain: x86_64-linux-gnu |
| 60 | + fmi_platform_tuple: linux64 |
| 61 | + lib_extension: so |
| 62 | + - toolchain: i686-w64-mingw32 |
| 63 | + fmi_platform_tuple: win32 |
| 64 | + lib_extension: dll |
| 65 | + - toolchain: x86_64-w64-mingw32 |
| 66 | + fmi_platform_tuple: win64 |
| 67 | + lib_extension: dll |
| 68 | + timeout-minutes: 15 |
| 69 | + steps: |
| 70 | + - name: Check out the repo |
| 71 | + uses: actions/checkout@v5 |
| 72 | + |
| 73 | + - name: Log in to GitHub Container Registry |
| 74 | + uses: docker/login-action@v3 |
| 75 | + with: |
| 76 | + registry: ghcr.io |
| 77 | + username: ${{ github.actor }} |
| 78 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 79 | + |
| 80 | + - name: Pull image pushed by build job |
| 81 | + shell: bash |
| 82 | + run: | |
| 83 | + docker pull "${{ needs.build.outputs.image }}" |
| 84 | +
|
| 85 | + - name: Test cross-compilation for matrix toolchain |
| 86 | + shell: bash |
| 87 | + env: |
| 88 | + TOOLCHAIN: ${{ matrix.toolchain }} |
| 89 | + FMI_PLATFORM_TUPLE: ${{ matrix.fmi_platform_tuple }} |
| 90 | + LIB_EXTENSION: ${{ matrix.lib_extension }} |
| 91 | + run: | |
| 92 | + docker run --rm \ |
| 93 | + -v "${{ github.workspace }}":/work \ |
| 94 | + -w /work \ |
| 95 | + "${{ needs.build.outputs.image }}" \ |
| 96 | + bash -lc "\ |
| 97 | + cmake -S test/resources/FMU_Interaction1/sources \ |
| 98 | + -B test/resources/FMU_Interaction1/sources/build_${TOOLCHAIN} \ |
| 99 | + -DFMI_INTERFACE_HEADER_FILES_DIRECTORY=/work/test/resources/fmi \ |
| 100 | + -DCMAKE_TOOLCHAIN_FILE=/opt/cmake/toolchain/${TOOLCHAIN}.cmake && \ |
| 101 | + cmake --build test/resources/FMU_Interaction1/sources/build_${TOOLCHAIN} --target install && \ |
| 102 | + test -f test/resources/FMU_Interaction1/binaries/${FMI_PLATFORM_TUPLE}/Interaction1.${LIB_EXTENSION} && \ |
| 103 | + cmake --build test/resources/FMU_Interaction1/sources/build_${TOOLCHAIN} --target create_fmu" |
| 104 | +
|
| 105 | + - name: Upload Interaction1.fmu |
| 106 | + uses: actions/upload-artifact@v5 |
| 107 | + with: |
| 108 | + name: Interaction1-${{ matrix.toolchain }} |
| 109 | + path: test/resources/Interaction1.fmu |
| 110 | + if-no-files-found: error |
| 111 | + |
| 112 | + test-import: |
| 113 | + name: Test FMU import across systems |
| 114 | + needs: test-compile |
| 115 | + runs-on: ${{ matrix.os }} |
| 116 | + strategy: |
| 117 | + fail-fast: false |
| 118 | + matrix: |
| 119 | + include: |
| 120 | + - os: ubuntu-latest |
| 121 | + fmu_artifact: Interaction1-x86_64-linux-gnu |
| 122 | + - os: windows-latest |
| 123 | + fmu_artifact: Interaction1-x86_64-w64-mingw32 |
| 124 | + |
| 125 | + timeout-minutes: 30 |
| 126 | + steps: |
| 127 | + - name: Download Interaction1.fmu |
| 128 | + uses: actions/download-artifact@v5 |
| 129 | + with: |
| 130 | + name: ${{ matrix.fmu_artifact }} |
| 131 | + |
| 132 | + - name: Install OMSimulator |
| 133 | + uses: OpenModelica/[email protected] |
| 134 | + with: |
| 135 | + version: '1' |
| 136 | + packages: | |
| 137 | + 'omc' |
| 138 | + 'omsimulator' |
| 139 | +
|
| 140 | + - name: Simulate 64-bit Linux FMU |
| 141 | + if: runner.os == 'Linux' |
| 142 | + shell: bash |
| 143 | + run: OMSimulator Interaction1.fmu |
| 144 | + |
| 145 | + - name: Simulate 64-bit Windows FMU |
| 146 | + if: runner.os == 'Windows' |
| 147 | + run: OMSimulator.exe Interaction1.fmu |
0 commit comments