action.yml raw

   1  name: 'Run in Docker with environment'
   2  description: 'Run a command in a Docker container, while passing explicitly set environment variables into the container.'
   3  inputs:
   4    dockerfile:
   5      description: 'A Dockerfile that defines an image'
   6      required: true
   7    tag:
   8      description: 'A tag of an image'
   9      required: true
  10    command:
  11      description: 'A command to run in a container'
  12      required: false
  13      default: ./ci/ci.sh
  14  runs:
  15    using: "composite"
  16    steps:
  17      - uses: docker/setup-buildx-action@v3
  18  
  19      - uses: docker/build-push-action@v5
  20        id: main_builder
  21        continue-on-error: true
  22        with:
  23          context: .
  24          file: ${{ inputs.dockerfile }}
  25          tags: ${{ inputs.tag }}
  26          load: true
  27          cache-from: type=gha
  28  
  29      - uses: docker/build-push-action@v5
  30        id: retry_builder
  31        if: steps.main_builder.outcome == 'failure'
  32        with:
  33          context: .
  34          file: ${{ inputs.dockerfile }}
  35          tags: ${{ inputs.tag }}
  36          load: true
  37          cache-from: type=gha
  38  
  39      - # Workaround for https://github.com/google/sanitizers/issues/1614 .
  40        # The underlying issue has been fixed in clang 18.1.3.
  41        run: sudo sysctl -w vm.mmap_rnd_bits=28
  42        shell: bash
  43  
  44      - # Tell Docker to pass environment variables in `env` into the container.
  45        run: >
  46          docker run \
  47            $(echo '${{ toJSON(env) }}' | jq -r 'keys[] | "--env \(.) "') \
  48            --volume ${{ github.workspace }}:${{ github.workspace }} \
  49            --workdir ${{ github.workspace }} \
  50            ${{ inputs.tag }} bash -c "
  51              git config --global --add safe.directory ${{ github.workspace }}
  52              ${{ inputs.command }}
  53            "
  54        shell: bash
  55