|
| 1 | +# Copyright (c) 2025 ETH Zurich and University of Bologna. |
| 2 | +# Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +# Author: Philippe Sauter <[email protected]> |
| 6 | + |
| 7 | +name: 'OSEDA Command Action' |
| 8 | +description: 'Sets up OSEDA environment and runs commands in a Docker container' |
| 9 | + |
| 10 | +inputs: |
| 11 | + cmd: |
| 12 | + description: 'Command to run in the OSEDA container' |
| 13 | + required: true |
| 14 | + image_file_name: |
| 15 | + description: 'Name of the artifact to download (default: oseda-image)' |
| 16 | + required: false |
| 17 | + default: 'oseda-image' |
| 18 | + service_name: |
| 19 | + description: 'Name of the Docker service (default: from ./docker-compose.yml)' |
| 20 | + required: false |
| 21 | + default: '' |
| 22 | + |
| 23 | +runs: |
| 24 | + using: 'composite' |
| 25 | + steps: |
| 26 | + - name: Set up Docker environment |
| 27 | + shell: bash |
| 28 | + run: | |
| 29 | + echo "UID=$(id -u)" >> $GITHUB_ENV |
| 30 | + echo "GID=$(id -g)" >> $GITHUB_ENV |
| 31 | +
|
| 32 | + - name: Get image name from docker-compose |
| 33 | + id: get-image |
| 34 | + shell: bash |
| 35 | + run: | |
| 36 | + IMAGE=$(docker compose config | awk '/image:/{print $2}' | head -n 1) |
| 37 | + if [ -z "$IMAGE" ]; then |
| 38 | + echo "ERROR: No image found in docker-compose.yml" |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | + echo "IMAGE_NAME=$IMAGE" >> $GITHUB_ENV |
| 42 | +
|
| 43 | + - name: Download Docker image from cache |
| 44 | + continue-on-error: true |
| 45 | + uses: actions/cache/restore@v4 |
| 46 | + with: |
| 47 | + key: oseda-${{ env.IMAGE_NAME }} |
| 48 | + path: /tmp/oseda.tar.gz |
| 49 | + |
| 50 | + - name: Load or pull Docker image |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + if [ -f "/tmp/oseda.tar.gz" ]; then |
| 54 | + docker import /tmp/oseda.tar.gz |
| 55 | + echo "Loaded image $IMAGE_NAME from artifacts/cache" |
| 56 | + else |
| 57 | + docker compose pull |
| 58 | + fi |
| 59 | +
|
| 60 | + - name: Determine service name if not provided |
| 61 | + shell: bash |
| 62 | + run: | |
| 63 | + if [ -z "${{ inputs.service_name }}" ]; then |
| 64 | + SERVICE_NAME=$(docker compose config --services | head -n 1) |
| 65 | + echo "service_name=$SERVICE_NAME" >> $GITHUB_ENV |
| 66 | + else |
| 67 | + echo "service_name=${{ inputs.service_name }}" >> $GITHUB_ENV |
| 68 | + fi |
| 69 | +
|
| 70 | + - name: Run commands in OSEDA container |
| 71 | + shell: bash |
| 72 | + run: | |
| 73 | + docker compose up -d |
| 74 | + docker compose exec ${{ env.service_name }} bash -c "source ~/.bashrc; ${{ inputs.cmd }}" | tee result.log |
| 75 | + echo "result_log=$(pwd)/result.log" >> $GITHUB_ENV |
0 commit comments