|
| 1 | +# https://help.github.com/en/categories/automating-your-workflow-with-github-actions |
| 2 | + |
| 3 | +name: "Build Turbo compile images" |
| 4 | + |
| 5 | +# Builds .github/turbo-build/Dockerfile natively on x86_64 and arm64 |
| 6 | +# runners and publishes ghcr.io/phpstan/turbo-build:gnu-php{8.3,8.4,8.5} |
| 7 | +# as multi-arch manifests. The turbo-compile gnu legs in phar.yml run in |
| 8 | +# these images, so their only network dependency is a GHCR pull — no apt, |
| 9 | +# no ports.ubuntu.com, no PPA at compile time. |
| 10 | + |
| 11 | +on: |
| 12 | + workflow_dispatch: |
| 13 | + pull_request: |
| 14 | + paths: |
| 15 | + - ".github/turbo-build/**" |
| 16 | + - ".github/workflows/turbo-build-image.yml" |
| 17 | + push: |
| 18 | + branches: |
| 19 | + - "2.2.x" |
| 20 | + paths: |
| 21 | + - ".github/turbo-build/**" |
| 22 | + - ".github/workflows/turbo-build-image.yml" |
| 23 | + schedule: |
| 24 | + # weekly rebuild so PHP patch releases and security updates flow into |
| 25 | + # the baked images — the compile jobs never run apt themselves |
| 26 | + - cron: '30 2 * * 1' |
| 27 | + |
| 28 | +permissions: |
| 29 | + contents: read |
| 30 | + |
| 31 | +concurrency: |
| 32 | + group: turbo-build-image-${{ github.ref }} |
| 33 | + cancel-in-progress: false |
| 34 | + |
| 35 | +jobs: |
| 36 | + build: |
| 37 | + name: "Build image (php${{ matrix.php-version }}, ${{ matrix.platform.arch }})" |
| 38 | + if: github.repository == 'phpstan/phpstan-src' |
| 39 | + runs-on: ${{ matrix.platform.runs-on }} |
| 40 | + timeout-minutes: 30 |
| 41 | + permissions: |
| 42 | + contents: read |
| 43 | + packages: write |
| 44 | + |
| 45 | + strategy: |
| 46 | + fail-fast: false |
| 47 | + matrix: |
| 48 | + php-version: ["8.3", "8.4", "8.5"] |
| 49 | + platform: |
| 50 | + - arch: "amd64" |
| 51 | + runs-on: "ubuntu-latest" |
| 52 | + - arch: "arm64" |
| 53 | + runs-on: "ubuntu-24.04-arm" |
| 54 | + |
| 55 | + env: |
| 56 | + IMAGE: "ghcr.io/phpstan/turbo-build:gnu-php${{ matrix.php-version }}-${{ matrix.platform.arch }}" |
| 57 | + |
| 58 | + steps: |
| 59 | + - name: Harden the runner (Audit all outbound calls) |
| 60 | + uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4 |
| 61 | + with: |
| 62 | + egress-policy: audit |
| 63 | + |
| 64 | + - name: "Checkout" |
| 65 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 66 | + with: |
| 67 | + persist-credentials: false |
| 68 | + |
| 69 | + - name: "Build" |
| 70 | + run: docker build --build-arg "PHP_MINOR=${{ matrix.php-version }}" -t "$IMAGE" .github/turbo-build |
| 71 | + |
| 72 | + - name: "Smoke test (interpreter matches the matrix, toolchain present)" |
| 73 | + run: | |
| 74 | + VERSION="$(docker run --rm "$IMAGE" php -r 'echo PHP_VERSION;')" |
| 75 | + echo "image reports PHP $VERSION, expected ${{ matrix.php-version }}.*" |
| 76 | + [ "${VERSION%.*}" = "${{ matrix.php-version }}" ] |
| 77 | + docker run --rm "$IMAGE" sh -c 'php-config --version && git --version && g++ --version && make --version && curl --version' |
| 78 | +
|
| 79 | + # PR runs stop here: build + smoke validate the Dockerfile change, |
| 80 | + # only pushes to 2.2.x (and the cron/manual runs) publish. |
| 81 | + - name: "Log in to GHCR" |
| 82 | + if: github.event_name != 'pull_request' |
| 83 | + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin |
| 84 | + |
| 85 | + - name: "Push" |
| 86 | + if: github.event_name != 'pull_request' |
| 87 | + run: docker push "$IMAGE" |
| 88 | + |
| 89 | + manifest: |
| 90 | + name: "Publish multi-arch manifest (php${{ matrix.php-version }})" |
| 91 | + if: github.repository == 'phpstan/phpstan-src' && github.event_name != 'pull_request' |
| 92 | + needs: build |
| 93 | + runs-on: "ubuntu-latest" |
| 94 | + timeout-minutes: 10 |
| 95 | + permissions: |
| 96 | + packages: write |
| 97 | + |
| 98 | + strategy: |
| 99 | + matrix: |
| 100 | + php-version: ["8.3", "8.4", "8.5"] |
| 101 | + |
| 102 | + env: |
| 103 | + TAG: "ghcr.io/phpstan/turbo-build:gnu-php${{ matrix.php-version }}" |
| 104 | + |
| 105 | + steps: |
| 106 | + - name: Harden the runner (Audit all outbound calls) |
| 107 | + uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4 |
| 108 | + with: |
| 109 | + egress-policy: audit |
| 110 | + |
| 111 | + - name: "Log in to GHCR" |
| 112 | + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin |
| 113 | + |
| 114 | + - name: "Create and push the manifest" |
| 115 | + run: docker buildx imagetools create -t "$TAG" "$TAG-amd64" "$TAG-arm64" |
| 116 | + |
| 117 | + - name: "Verify both platforms are present" |
| 118 | + run: | |
| 119 | + docker buildx imagetools inspect "$TAG" | tee manifest.txt |
| 120 | + grep -q "linux/amd64" manifest.txt |
| 121 | + grep -q "linux/arm64" manifest.txt |
0 commit comments