From afa5a72e3b8878160dee4480d631fc17b65bd267 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Mon, 22 Jul 2024 21:48:04 +0200 Subject: [PATCH] ci-staging: put everything in a docker image --- .../sil-kit-ci/build-sil-kit/action.yml | 102 ++++++++++-------- .../sil-kit-ci/impl-execute/action.yml | 66 ++++++++---- .../actions/sil-kit-ci/impl-setup/action.yml | 29 +++-- .github/workflows/call-build.yml | 4 +- .github/workflows/manual-build-linux.yml | 2 +- .github/workflows/manual-build-windows.yml | 7 ++ 6 files changed, 128 insertions(+), 82 deletions(-) diff --git a/.github/actions/sil-kit-ci/build-sil-kit/action.yml b/.github/actions/sil-kit-ci/build-sil-kit/action.yml index 880d2bc0..2411de63 100644 --- a/.github/actions/sil-kit-ci/build-sil-kit/action.yml +++ b/.github/actions/sil-kit-ci/build-sil-kit/action.yml @@ -8,7 +8,7 @@ inputs: description: The preset name from CMakePresets.json required: true - linux-docker-image: + docker-image: description: Docker image used under Linux required: true @@ -65,7 +65,7 @@ runs: - uses: ./.github/actions/sil-kit-ci/impl-setup id: setup with: - linux-docker-image: ${{ inputs.linux-docker-image }} + docker-image: ${{ inputs.docker-image }} c-compiler: ${{ inputs.c-compiler }} cxx-compiler: ${{ inputs.cxx-compiler }} msvc-arch: ${{ inputs.msvc-arch }} @@ -95,50 +95,64 @@ runs: - name: configure cmake project uses: ./.github/actions/sil-kit-ci/impl-execute with: - linux-docker-image: ${{ inputs.linux-docker-image }} + docker-image: ${{ docker-image }} work-dir: ${{ env.work-dir }} relative-working-dir: src/sil-kit - command: > - cmake - -B "${WORK_DIR}/bld/sil-kit" - --preset "${{ inputs.preset-name }}" - ${{ steps.setup.outputs.cmake-configure-args }} - ${{ inputs.cmake-configure-args }} - -D CPACK_PACKAGE_DIRECTORY="${WORK_DIR}/pkg/sil-kit" - - - name: build cmake project - uses: ./.github/actions/sil-kit-ci/impl-execute - with: - linux-docker-image: ${{ inputs.linux-docker-image }} - work-dir: ${{ env.work-dir }} - relative-working-dir: bld/sil-kit - command: > - cmake - --build . - --parallel - ${{ inputs.cmake-build-args }} - - - name: test cmake project - uses: ./.github/actions/sil-kit-ci/impl-execute - with: - linux-docker-image: ${{ inputs.linux-docker-image }} - work-dir: ${{ env.work-dir }} - relative-working-dir: bld/sil-kit - command: > - ctest - ${{ inputs.ctest-args }} - - - name: package cmake project - uses: ./.github/actions/sil-kit-ci/impl-execute - with: - linux-docker-image: ${{ inputs.linux-docker-image }} - work-dir: ${{ env.work-dir }} - relative-working-dir: bld/sil-kit - command: > - cmake - --build . - --target package - ${{ inputs.cmake-package-args }} + command: | + cmake \ + -B "${CI_TEMP_DIR}/bld/sil-kit" \ + --preset "${{ inputs.preset-name }}" \ + ${{ steps.setup.outputs.cmake-configure-args }} \ + ${{ inputs.cmake-configure-args }} \ + -D CPACK_PACKAGE_DIRECTORY="${CI_WORK_DIR}/pkg/sil-kit" + + cmake \ + --build "${CI_TEMP_DIR}/bld/sil-kit" \ + --parallel \ + ${{ inputs.cmake-build-args }} + + ctest \ + --test-dir "${CI_TEMP_DIR}/bld/sil-kit" \ + ${{ inputs.ctest-args }} + + cmake \ + --build "${CI_TEMP_DIR}/bld/sil-kit" \ + --target package \ + ${{ inputs.cmake-package-args }} + + # - name: build cmake project + # uses: ./.github/actions/sil-kit-ci/impl-execute + # with: + # docker-image: ${{ inputs.docker-image }} + # work-dir: ${{ env.work-dir }} + # relative-working-dir: bld/sil-kit + # command: > + # cmake + # --build . + # --parallel + # ${{ inputs.cmake-build-args }} + + # - name: test cmake project + # uses: ./.github/actions/sil-kit-ci/impl-execute + # with: + # docker-image: ${{ inputs.docker-image }} + # work-dir: ${{ env.work-dir }} + # relative-working-dir: bld/sil-kit + # command: > + # ctest + # ${{ inputs.ctest-args }} + + # - name: package cmake project + # uses: ./.github/actions/sil-kit-ci/impl-execute + # with: + # docker-image: ${{ inputs.docker-image }} + # work-dir: ${{ env.work-dir }} + # relative-working-dir: bld/sil-kit + # command: > + # cmake + # --build . + # --target package + # ${{ inputs.cmake-package-args }} - name: upload package as artifact if: ${{ inputs.upload-artifacts == 'true' }} diff --git a/.github/actions/sil-kit-ci/impl-execute/action.yml b/.github/actions/sil-kit-ci/impl-execute/action.yml index 6a8e26c2..2a1369db 100644 --- a/.github/actions/sil-kit-ci/impl-execute/action.yml +++ b/.github/actions/sil-kit-ci/impl-execute/action.yml @@ -6,8 +6,7 @@ description: > Access to files in the `work-dir` must use the `WORK_DIR` environment variable in the command. This is required to provide transparent support for execution of the command inside of a docker container. - On Linux runners, the command is executed in a docker container using the `linux-docker-image`. - On Windows runners, the command is executed on the runner itself. + The command is executed in a docker container using the input `docker-image`. inputs: @@ -22,9 +21,9 @@ inputs: description: > Relative path to the initial working directory inside the `work-directory` (can be empty) - linux-docker-image: + docker-image: required: false - description: Docker image used under Linux. + description: Docker image used to run the command. command: required: true @@ -34,35 +33,62 @@ runs: using: composite steps: - - shell: bash - env: - STRING: ${{ inputs.command }} - run: | - # check if inputs.command contains a newline + # - shell: bash + # env: + # STRING: ${{ inputs.command }} + # run: | + # # check if inputs.command contains a newline - # remove trailing newlines and spaces before the check - STRING="${STRING%%[[:space:]]}" + # # remove trailing newlines and spaces before the check + # STRING="${STRING%%[[:space:]]}" - if [[ "${STRING}" == *$'\n'* ]] ; then - echo "::error title=invalid command::must not contain newline characters" - exit 1 - fi + # if [[ "${STRING}" == *$'\n'* ]] ; then + # echo "::error title=invalid command::must not contain newline characters" + # exit 1 + # fi - name: (linux) execute command if: runner.os == 'Linux' shell: bash run: | - WORK_DIR="/w" + IMPL_EXECUTE_CI_DIR="${{ github.workspace }}/impl-execute/ci" + + mkdir -p "${IMPL_EXECUTE_CI_DIR}" + cat <<<"${INPUTS_COMMAND}" > "${IMPL_EXECUTE_CI_DIR}/command.sh" + + CI_WORK_DIR="/w" + CI_TEMP_DIR="/tmp" + docker run \ + -v "${IMPL_EXECUTE_CI_DIR}:/ci" \ -v "${{ inputs.work-dir }}:/w" \ -w "/w/${{ inputs.relative-working-dir }}" \ - "${{ inputs.linux-docker-image }}" \ - ${{ inputs.command }} + -e "CI_WORK_DIR=${CI_WORK_DIR}" + -e "CI_TEMP_DIR=${CI_TEMP_DIR}" + "${{ inputs.docker-image }}" \ + "/ci/command.sh" - name: (windows) execute command if: runner.os == 'Windows' shell: powershell working-directory: ${{ inputs.work-dir }}/${{ inputs.relative-working-dir }} run: | - $WORK_DIR = "${{ inputs.work-dir }}" - ${{ inputs.command }} + $IMPL_EXECUTE_CI_DIR = "${{ github.workspace }}/impl-execute/ci" + + $null = New-Item -Path "${IMPL_EXECUTE_CI_DIR}" -Type Directory -Force + $env:INPUTS_COMMAND | Out-File "${IMPL_EXECUTE_CI_DIR}/command.ps1" + + CI_WORK_DIR="C:/w" + CI_TEMP_DIR="C:/Windows/Temp" + + docker run \ + -v "${IMPL_EXECUTE_CI_DIR}:C:/ci" \ + -v "${{ inputs.work-dir }}:C:/w" \ + -w "C:\w\${{ inputs.relative-working-dir }}" \ + -e "CI_WORK_DIR=${CI_WORK_DIR}" + -e "CI_TEMP_DIR=${CI_TEMP_DIR}" + "${{ inputs.docker-image }}" \ + C:/ci/command.ps1 + +# $WORK_DIR = "${{ inputs.work-dir }}" +# ${{ inputs.command }} diff --git a/.github/actions/sil-kit-ci/impl-setup/action.yml b/.github/actions/sil-kit-ci/impl-setup/action.yml index 6f58b792..783a815c 100644 --- a/.github/actions/sil-kit-ci/impl-setup/action.yml +++ b/.github/actions/sil-kit-ci/impl-setup/action.yml @@ -4,7 +4,7 @@ description: Setup the environment for the other CI actions. inputs: - linux-docker-image: + docker-image: description: Docker image used under Linux required: true @@ -77,19 +77,18 @@ runs: # setup: prepare build environment - - if: runner.os == 'Linux' - shell: bash + - shell: bash run: | # pull docker image for building via cmake - docker pull "${{ inputs.linux-docker-image }}" - - - if: runner.os == 'Windows' - shell: powershell - run: .github/actions/sil-kit-ci/impl-setup/Install-RequiredVisualStudioComponents -InstallToolset ${{ inputs.msvc-toolset }} - - - name: (windows) setup msvc environment - if: runner.os == 'Windows' - uses: ilammy/msvc-dev-cmd@v1.13.0 - with: - arch: ${{ inputs.msvc-arch }} - toolset: ${{ inputs.msvc-toolset }} + docker pull "${{ inputs.docker-image }}" + + # - if: runner.os == 'Windows' + # shell: powershell + # run: .github/actions/sil-kit-ci/impl-setup/Install-RequiredVisualStudioComponents -InstallToolset ${{ inputs.msvc-toolset }} + + # - name: (windows) setup msvc environment + # if: runner.os == 'Windows' + # uses: ilammy/msvc-dev-cmd@v1.13.0 + # with: + # arch: ${{ inputs.msvc-arch }} + # toolset: ${{ inputs.msvc-toolset }} diff --git a/.github/workflows/call-build.yml b/.github/workflows/call-build.yml index 950c38ae..44a3ff79 100644 --- a/.github/workflows/call-build.yml +++ b/.github/workflows/call-build.yml @@ -27,7 +27,7 @@ on: required: false type: string - linux-docker-image: + docker-image: required: false type: string @@ -85,7 +85,7 @@ jobs: upload-artifacts: ${{ inputs.upload-artifacts }} retention-days: ${{ inputs.retention-days }} package-name: ${{ inputs.package-name }} - linux-docker-image: ${{ inputs.linux-docker-image || 'ghcr.io/mariusbgm/sil-kit-ci-ubuntu-18.04:main' }} + docker-image: ${{ inputs.docker-image }} c-compiler: ${{ inputs.c-compiler }} cxx-compiler: ${{ inputs.cxx-compiler }} msvc-arch: ${{ inputs.msvc-arch || 'x64' }} diff --git a/.github/workflows/manual-build-linux.yml b/.github/workflows/manual-build-linux.yml index 24001c0c..efca8e94 100644 --- a/.github/workflows/manual-build-linux.yml +++ b/.github/workflows/manual-build-linux.yml @@ -69,7 +69,7 @@ jobs: # https://github.com/orgs/community/discussions/67182#discussioncomment-8617964 retention-days: '${{ fromJSON(inputs.retention-days) }}' package-name: SilKit-Linux-Manual - linux-docker-image: ${{ inputs.docker-image }} + docker-image: ${{ inputs.docker-image }} c-compiler: ${{ inputs.c-compiler }} cxx-compiler: ${{ inputs.cxx-compiler }} cmake-configure-args: ${{ inputs.cmake-configure-args }} diff --git a/.github/workflows/manual-build-windows.yml b/.github/workflows/manual-build-windows.yml index bfaadef9..90a0a40f 100644 --- a/.github/workflows/manual-build-windows.yml +++ b/.github/workflows/manual-build-windows.yml @@ -11,6 +11,12 @@ on: type: string default: ci + docker-image: + description: Docker image + required: true + type: string + default: ghcr.io/vdanieledwards/sil-kit-ci-docker:ci-windows-2022-x86.x64 + runs-on: description: Runner type required: true @@ -69,6 +75,7 @@ jobs: # https://github.com/orgs/community/discussions/67182#discussioncomment-8617964 retention-days: '${{ fromJSON(inputs.retention-days) }}' package-name: SilKit-Windows-Manual + docker-image: ${{ inputs.docker-image }} msvc-arch: ${{ inputs.msvc-arch }} msvc-toolset: '${{ inputs.msvc-toolset }}' cmake-configure-args: ${{ inputs.cmake-configure-args }}