Skip to content

Commit

Permalink
ci-staging: put everything in a docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
VDanielEdwards committed Jul 22, 2024
1 parent 418936f commit afa5a72
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 82 deletions.
102 changes: 58 additions & 44 deletions .github/actions/sil-kit-ci/build-sil-kit/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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' }}
Expand Down
66 changes: 46 additions & 20 deletions .github/actions/sil-kit-ci/impl-execute/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
Expand All @@ -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 }}
29 changes: 14 additions & 15 deletions .github/actions/sil-kit-ci/impl-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 }}
4 changes: 2 additions & 2 deletions .github/workflows/call-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ on:
required: false
type: string

linux-docker-image:
docker-image:
required: false
type: string

Expand Down Expand Up @@ -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' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/manual-build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/manual-build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down

0 comments on commit afa5a72

Please sign in to comment.