|
| 1 | +name: 'Compile Dependency on Target - Reusable Workflow' |
| 2 | + |
| 3 | +description: | |
| 4 | + Compiles Dependency on given target, os, and arch |
| 5 | +
|
| 6 | +on: |
| 7 | + workflow_call: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: 'dependency version' |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + target: |
| 14 | + description: 'dependency OS target variant' |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + os: |
| 18 | + description: 'platform OS (e.g., linux)' |
| 19 | + required: true |
| 20 | + type: string |
| 21 | + arch: |
| 22 | + description: 'platform architecture (e.g., amd64)' |
| 23 | + required: true |
| 24 | + type: string |
| 25 | + shouldCompile: |
| 26 | + description: 'whether to compile the dependency' |
| 27 | + required: true |
| 28 | + type: boolean |
| 29 | + shouldTest: |
| 30 | + description: 'whether to test the dependency after compilation' |
| 31 | + required: true |
| 32 | + type: boolean |
| 33 | + uploadArtifactName: |
| 34 | + description: 'name of the artifact to upload' |
| 35 | + required: true |
| 36 | + type: string |
| 37 | + |
| 38 | +jobs: |
| 39 | + compile: |
| 40 | + # Speed up compilation by using runners that match os and arch when they are set, otherwise fall back to emulation. |
| 41 | + runs-on: ${{ (inputs.os == 'linux' && inputs.arch == 'arm64') && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }} |
| 42 | + |
| 43 | + steps: |
| 44 | + - name: Check out code |
| 45 | + uses: actions/checkout@v6 |
| 46 | + |
| 47 | + - name: Enable experimental features for Docker daemon and CLI |
| 48 | + run: | |
| 49 | + echo '{"experimental": true}' | sudo tee /etc/docker/daemon.json |
| 50 | + sudo systemctl restart docker |
| 51 | + mkdir -p ~/.docker |
| 52 | + echo '{"experimental": "enabled"}' | sudo tee ~/.docker/config.json |
| 53 | +
|
| 54 | + - name: Set up QEMU |
| 55 | + uses: docker/setup-qemu-action@v4 |
| 56 | + |
| 57 | + - name: Set up Docker Buildx |
| 58 | + uses: docker/setup-buildx-action@v4 |
| 59 | + |
| 60 | + - name: Setup before compilation |
| 61 | + id: compile-setup |
| 62 | + run: | |
| 63 | + echo "outputdir=$(mktemp -d)" >> "$GITHUB_OUTPUT" |
| 64 | +
|
| 65 | + - name: docker build |
| 66 | + id: docker-build |
| 67 | + env: |
| 68 | + SKIP_LOGIN: true |
| 69 | + if: ${{ inputs.shouldCompile == true || inputs.shouldCompile == 'true' }} |
| 70 | + uses: actions-hub/docker/cli@master |
| 71 | + with: |
| 72 | + args: "build ${{ (inputs.os != '' && inputs.arch != '') && format('--platform {0}/{1}', inputs.os, inputs.arch) || '' }} -t compilation -f dependency/actions/compile/${{ inputs.target }}.Dockerfile dependency/actions/compile" |
| 73 | + |
| 74 | + - name: docker run |
| 75 | + id: docker-run |
| 76 | + uses: actions-hub/docker/cli@master |
| 77 | + env: |
| 78 | + SKIP_LOGIN: true |
| 79 | + if: ${{ inputs.shouldCompile == true || inputs.shouldCompile == 'true' }} |
| 80 | + with: |
| 81 | + args: "run ${{ (inputs.os != '' && inputs.arch != '') && format('--platform {0}/{1}', inputs.os, inputs.arch) || '' }} -v ${{ steps.compile-setup.outputs.outputdir }}:/home compilation --outputDir /home --target ${{ inputs.target }} --version ${{ inputs.version }} ${{ inputs.os != '' && format('--os {0}', inputs.os) || '' }} ${{ inputs.arch != '' && format('--arch {0}', inputs.arch) || '' }}" |
| 82 | + |
| 83 | + - name: Print contents of output dir |
| 84 | + shell: bash |
| 85 | + run: ls -lah ${{ steps.compile-setup.outputs.outputdir }} |
| 86 | + |
| 87 | + - name: Test Dependency |
| 88 | + working-directory: dependency |
| 89 | + if: ${{ (inputs.shouldCompile == true || inputs.shouldCompile == 'true') && (inputs.shouldTest == true || inputs.shouldTest == 'true') }} |
| 90 | + run: | |
| 91 | + #!/usr/bin/env bash |
| 92 | + set -euo pipefail |
| 93 | + shopt -s inherit_errexit |
| 94 | +
|
| 95 | + make test \ |
| 96 | + version="${{ inputs.version }}" \ |
| 97 | + tarballPath="${{ steps.compile-setup.outputs.outputdir }}/*.tgz" \ |
| 98 | + os="${{ inputs.os }}" \ |
| 99 | + arch="${{ inputs.arch }}" |
| 100 | +
|
| 101 | + - name: Upload compiled artifact |
| 102 | + uses: actions/upload-artifact@v6 |
| 103 | + if: ${{ inputs.shouldCompile == true || inputs.shouldCompile == 'true' }} |
| 104 | + with: |
| 105 | + name: '${{ inputs.uploadArtifactName }}' |
| 106 | + path: '${{ steps.compile-setup.outputs.outputdir }}/*' |
0 commit comments