|
| 1 | +name: 'Docker Skiko Run' |
| 2 | +description: 'Build Docker image locally if needed and run commands inside it' |
| 3 | + |
| 4 | +inputs: |
| 5 | + image_name: |
| 6 | + description: 'Image name (e.g., linux-compat)' |
| 7 | + required: true |
| 8 | + command: |
| 9 | + description: 'Command to run inside the container' |
| 10 | + required: true |
| 11 | + working_directory: |
| 12 | + description: 'Working directory relative to project root (e.g., samples/SkiaAndroidSample)' |
| 13 | + required: false |
| 14 | + default: '.' |
| 15 | + virtual-display: |
| 16 | + description: 'Enable virtual display for UI testing (enables e2e UI interaction tests with real windows)' |
| 17 | + required: false |
| 18 | + default: 'false' |
| 19 | + base_ref: |
| 20 | + description: 'Base ref/sha for change detection (defaults to auto-detect)' |
| 21 | + required: false |
| 22 | + default: '' |
| 23 | + |
| 24 | +runs: |
| 25 | + using: 'composite' |
| 26 | + steps: |
| 27 | + - name: 'Detect Docker changes' |
| 28 | + id: filter |
| 29 | + uses: dorny/paths-filter@v3 |
| 30 | + with: |
| 31 | + base: ${{ inputs.base_ref || github.event.pull_request.base.sha || github.event.before || 'master' }} |
| 32 | + filters: | |
| 33 | + docker_changed: |
| 34 | + - '.github/actions/docker-skiko-publish/**' |
| 35 | + - '.github/workflows/docker-publish.yml' |
| 36 | + - 'skiko/docker/${{ inputs.image_name }}/**' |
| 37 | +
|
| 38 | + - name: 'Set Variables' |
| 39 | + id: vars |
| 40 | + shell: bash |
| 41 | + run: | |
| 42 | + IMAGE_NAMESPACE="${GITHUB_REPOSITORY,,}" |
| 43 | + echo "image_namespace=${IMAGE_NAMESPACE}" >> $GITHUB_OUTPUT |
| 44 | + |
| 45 | + # Determine which tag to use |
| 46 | + # github.base_ref is set for PRs regardless of event type (pull_request or workflow_call) |
| 47 | + if [[ -n "${{ github.base_ref }}" && "${{ steps.filter.outputs.docker_changed }}" != "true" ]]; then |
| 48 | + # For PRs without docker changes, use base branch tag (pre-built image) |
| 49 | + TAG="${{ github.base_ref }}" |
| 50 | + else |
| 51 | + # For PRs with docker changes or non-PRs, use current branch tag |
| 52 | + TAG="${GITHUB_REF_NAME}" |
| 53 | + fi |
| 54 | + TAG="${TAG//\//-}" |
| 55 | + |
| 56 | + # Try to pull image from GHCR |
| 57 | + # This checks both if the image exists in the registry and loads it into the local daemon |
| 58 | + if docker pull "ghcr.io/${IMAGE_NAMESPACE}/${{ inputs.image_name }}:${TAG}" >/dev/null 2>&1; then |
| 59 | + IMAGE_EXISTS="true" |
| 60 | + else |
| 61 | + IMAGE_EXISTS="false" |
| 62 | + fi |
| 63 | + |
| 64 | + echo "tag=${TAG}" >> $GITHUB_OUTPUT |
| 65 | + echo "image_exists=${IMAGE_EXISTS}" >> $GITHUB_OUTPUT |
| 66 | +
|
| 67 | + - name: 'Build Docker image locally (if needed)' |
| 68 | + if: steps.filter.outputs.docker_changed == 'true' || steps.vars.outputs.image_exists == 'false' |
| 69 | + uses: ./.github/actions/docker-skiko-publish |
| 70 | + with: |
| 71 | + image_name: ${{ inputs.image_name }} |
| 72 | + tag: ${{ steps.vars.outputs.tag }} |
| 73 | + load: true |
| 74 | + should_publish: false |
| 75 | + |
| 76 | + - name: 'Prepare command' |
| 77 | + id: cmd |
| 78 | + shell: bash |
| 79 | + run: | |
| 80 | + CMD="${{ inputs.command }}" |
| 81 | + if [[ "${{ inputs.virtual-display }}" == "true" ]]; then |
| 82 | + CMD="Xvfb :1 -screen 0 1920x1080x24 -extension RANDR +extension GLX & export DISPLAY=:1.0 && ${CMD}" |
| 83 | + fi |
| 84 | + { |
| 85 | + echo "command<<EOF" |
| 86 | + echo "${CMD}" |
| 87 | + echo "EOF" |
| 88 | + } >> $GITHUB_OUTPUT |
| 89 | +
|
| 90 | + - name: 'Run command in container' |
| 91 | + shell: bash |
| 92 | + run: | |
| 93 | + docker run --rm \ |
| 94 | + -v "${{ github.workspace }}":/workspace \ |
| 95 | + -v "${HOME}/.gradle":/gradle-cache \ |
| 96 | + -e GRADLE_USER_HOME=/gradle-cache \ |
| 97 | + -w /workspace/${{ inputs.working_directory }} \ |
| 98 | + "ghcr.io/${{ steps.vars.outputs.image_namespace }}/${{ inputs.image_name }}:${{ steps.vars.outputs.tag }}" \ |
| 99 | + bash -c '${{ steps.cmd.outputs.command }}' |
0 commit comments