github.com/pdmccormick/importable-docker-buildx@v0.0.0-20240426161518-e47091289030/.github/workflows/build.yml (about) 1 name: build 2 3 concurrency: 4 group: ${{ github.workflow }}-${{ github.ref }} 5 cancel-in-progress: true 6 7 on: 8 workflow_dispatch: 9 push: 10 branches: 11 - 'master' 12 - 'v[0-9]*' 13 tags: 14 - 'v*' 15 pull_request: 16 paths-ignore: 17 - '.github/releases.json' 18 - 'README.md' 19 - 'docs/**' 20 21 env: 22 BUILDX_VERSION: "latest" 23 BUILDKIT_IMAGE: "moby/buildkit:latest" 24 REPO_SLUG: "docker/buildx-bin" 25 DESTDIR: "./bin" 26 TEST_CACHE_SCOPE: "test" 27 TESTFLAGS: "-v --parallel=6 --timeout=30m" 28 GOTESTSUM_FORMAT: "standard-verbose" 29 GO_VERSION: "1.21" 30 GOTESTSUM_VERSION: "v1.9.0" # same as one in Dockerfile 31 32 jobs: 33 test-integration: 34 runs-on: ubuntu-22.04 35 env: 36 TESTFLAGS_DOCKER: "-v --parallel=1 --timeout=30m" 37 TEST_IMAGE_BUILD: "0" 38 TEST_IMAGE_ID: "buildx-tests" 39 strategy: 40 fail-fast: false 41 matrix: 42 buildkit: 43 - master 44 - latest 45 - buildx-stable-1 46 - v0.13.1 47 - v0.12.5 48 - v0.11.6 49 worker: 50 - docker-container 51 - remote 52 pkg: 53 - ./tests 54 mode: 55 - "" 56 - experimental 57 include: 58 - worker: docker 59 pkg: ./tests 60 - worker: docker+containerd # same as docker, but with containerd snapshotter 61 pkg: ./tests 62 - worker: docker 63 pkg: ./tests 64 mode: experimental 65 - worker: docker+containerd # same as docker, but with containerd snapshotter 66 pkg: ./tests 67 mode: experimental 68 steps: 69 - 70 name: Prepare 71 run: | 72 echo "TESTREPORTS_NAME=${{ github.job }}-$(echo "${{ matrix.pkg }}-${{ matrix.buildkit }}-${{ matrix.worker }}-${{ matrix.mode }}" | tr -dc '[:alnum:]-\n\r' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV 73 if [ -n "${{ matrix.buildkit }}" ]; then 74 echo "TEST_BUILDKIT_TAG=${{ matrix.buildkit }}" >> $GITHUB_ENV 75 fi 76 testFlags="--run=//worker=$(echo "${{ matrix.worker }}" | sed 's/\+/\\+/g')$" 77 case "${{ matrix.worker }}" in 78 docker | docker+containerd) 79 echo "TESTFLAGS=${{ env.TESTFLAGS_DOCKER }} $testFlags" >> $GITHUB_ENV 80 ;; 81 *) 82 echo "TESTFLAGS=${{ env.TESTFLAGS }} $testFlags" >> $GITHUB_ENV 83 ;; 84 esac 85 if [[ "${{ matrix.worker }}" == "docker"* ]]; then 86 echo "TEST_DOCKERD=1" >> $GITHUB_ENV 87 fi 88 if [ "${{ matrix.mode }}" = "experimental" ]; then 89 echo "TEST_BUILDX_EXPERIMENTAL=1" >> $GITHUB_ENV 90 fi 91 - 92 name: Checkout 93 uses: actions/checkout@v4 94 with: 95 fetch-depth: 0 96 - 97 name: Set up QEMU 98 uses: docker/setup-qemu-action@v3 99 - 100 name: Set up Docker Buildx 101 uses: docker/setup-buildx-action@v3 102 with: 103 version: ${{ env.BUILDX_VERSION }} 104 driver-opts: image=${{ env.BUILDKIT_IMAGE }} 105 buildkitd-flags: --debug 106 - 107 name: Build test image 108 uses: docker/bake-action@v4 109 with: 110 targets: integration-test 111 set: | 112 *.output=type=docker,name=${{ env.TEST_IMAGE_ID }} 113 - 114 name: Test 115 run: | 116 ./hack/test 117 env: 118 TEST_REPORT_SUFFIX: "-${{ env.TESTREPORTS_NAME }}" 119 TESTPKGS: "${{ matrix.pkg }}" 120 - 121 name: Send to Codecov 122 if: always() 123 uses: codecov/codecov-action@v4 124 with: 125 directory: ./bin/testreports 126 flags: integration 127 token: ${{ secrets.CODECOV_TOKEN }} 128 - 129 name: Generate annotations 130 if: always() 131 uses: crazy-max/.github/.github/actions/gotest-annotations@fa6141aedf23596fb8bdcceab9cce8dadaa31bd9 132 with: 133 directory: ./bin/testreports 134 - 135 name: Upload test reports 136 if: always() 137 uses: actions/upload-artifact@v4 138 with: 139 name: test-reports-${{ env.TESTREPORTS_NAME }} 140 path: ./bin/testreports 141 142 test-unit: 143 runs-on: ${{ matrix.os }} 144 strategy: 145 fail-fast: false 146 matrix: 147 os: 148 - ubuntu-22.04 149 - macos-12 150 - windows-2022 151 env: 152 SKIP_INTEGRATION_TESTS: 1 153 steps: 154 - 155 name: Checkout 156 uses: actions/checkout@v4 157 - 158 name: Set up Go 159 uses: actions/setup-go@v5 160 with: 161 go-version: "${{ env.GO_VERSION }}" 162 - 163 name: Prepare 164 run: | 165 testreportsName=${{ github.job }}--${{ matrix.os }} 166 testreportsBaseDir=./bin/testreports 167 testreportsDir=$testreportsBaseDir/$testreportsName 168 echo "TESTREPORTS_NAME=$testreportsName" >> $GITHUB_ENV 169 echo "TESTREPORTS_BASEDIR=$testreportsBaseDir" >> $GITHUB_ENV 170 echo "TESTREPORTS_DIR=$testreportsDir" >> $GITHUB_ENV 171 mkdir -p $testreportsDir 172 shell: bash 173 - 174 name: Install gotestsum 175 run: | 176 go install gotest.tools/gotestsum@${{ env.GOTESTSUM_VERSION }} 177 - 178 name: Test 179 env: 180 TMPDIR: ${{ runner.temp }} 181 run: | 182 gotestsum \ 183 --jsonfile="${{ env.TESTREPORTS_DIR }}/go-test-report.json" \ 184 --junitfile="${{ env.TESTREPORTS_DIR }}/junit-report.xml" \ 185 --packages="./..." \ 186 -- \ 187 "-mod=vendor" \ 188 "-coverprofile" "${{ env.TESTREPORTS_DIR }}/coverage.txt" \ 189 "-covermode" "atomic" ${{ env.TESTFLAGS }} 190 shell: bash 191 - 192 name: Send to Codecov 193 if: always() 194 uses: codecov/codecov-action@v4 195 with: 196 directory: ${{ env.TESTREPORTS_DIR }} 197 env_vars: RUNNER_OS 198 flags: unit 199 token: ${{ secrets.CODECOV_TOKEN }} 200 - 201 name: Generate annotations 202 if: always() 203 uses: crazy-max/.github/.github/actions/gotest-annotations@fa6141aedf23596fb8bdcceab9cce8dadaa31bd9 204 with: 205 directory: ${{ env.TESTREPORTS_DIR }} 206 - 207 name: Upload test reports 208 if: always() 209 uses: actions/upload-artifact@v4 210 with: 211 name: test-reports-${{ env.TESTREPORTS_NAME }} 212 path: ${{ env.TESTREPORTS_BASEDIR }} 213 214 prepare-binaries: 215 runs-on: ubuntu-22.04 216 outputs: 217 matrix: ${{ steps.platforms.outputs.matrix }} 218 steps: 219 - 220 name: Checkout 221 uses: actions/checkout@v4 222 - 223 name: Create matrix 224 id: platforms 225 run: | 226 echo "matrix=$(docker buildx bake binaries-cross --print | jq -cr '.target."binaries-cross".platforms')" >>${GITHUB_OUTPUT} 227 - 228 name: Show matrix 229 run: | 230 echo ${{ steps.platforms.outputs.matrix }} 231 232 binaries: 233 runs-on: ubuntu-22.04 234 needs: 235 - prepare-binaries 236 strategy: 237 fail-fast: false 238 matrix: 239 platform: ${{ fromJson(needs.prepare-binaries.outputs.matrix) }} 240 steps: 241 - 242 name: Prepare 243 run: | 244 platform=${{ matrix.platform }} 245 echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV 246 - 247 name: Checkout 248 uses: actions/checkout@v4 249 - 250 name: Set up QEMU 251 uses: docker/setup-qemu-action@v3 252 - 253 name: Set up Docker Buildx 254 uses: docker/setup-buildx-action@v3 255 with: 256 version: ${{ env.BUILDX_VERSION }} 257 driver-opts: image=${{ env.BUILDKIT_IMAGE }} 258 buildkitd-flags: --debug 259 - 260 name: Build 261 run: | 262 make release 263 env: 264 PLATFORMS: ${{ matrix.platform }} 265 CACHE_FROM: type=gha,scope=binaries-${{ env.PLATFORM_PAIR }} 266 CACHE_TO: type=gha,scope=binaries-${{ env.PLATFORM_PAIR }},mode=max 267 - 268 name: Upload artifacts 269 uses: actions/upload-artifact@v4 270 with: 271 name: buildx-${{ env.PLATFORM_PAIR }} 272 path: ${{ env.DESTDIR }}/* 273 if-no-files-found: error 274 275 bin-image: 276 runs-on: ubuntu-22.04 277 needs: 278 - test-integration 279 - test-unit 280 if: ${{ github.event_name != 'pull_request' && github.repository == 'docker/buildx' }} 281 steps: 282 - 283 name: Checkout 284 uses: actions/checkout@v4 285 - 286 name: Set up QEMU 287 uses: docker/setup-qemu-action@v3 288 - 289 name: Set up Docker Buildx 290 uses: docker/setup-buildx-action@v3 291 with: 292 version: ${{ env.BUILDX_VERSION }} 293 driver-opts: image=${{ env.BUILDKIT_IMAGE }} 294 buildkitd-flags: --debug 295 - 296 name: Docker meta 297 id: meta 298 uses: docker/metadata-action@v5 299 with: 300 images: | 301 ${{ env.REPO_SLUG }} 302 tags: | 303 type=ref,event=branch 304 type=ref,event=pr 305 type=semver,pattern={{version}} 306 bake-target: meta-helper 307 - 308 name: Login to DockerHub 309 if: github.event_name != 'pull_request' 310 uses: docker/login-action@v3 311 with: 312 username: ${{ vars.DOCKERPUBLICBOT_USERNAME }} 313 password: ${{ secrets.DOCKERPUBLICBOT_WRITE_PAT }} 314 - 315 name: Build and push image 316 uses: docker/bake-action@v4 317 with: 318 files: | 319 ./docker-bake.hcl 320 ${{ steps.meta.outputs.bake-file }} 321 targets: image-cross 322 push: ${{ github.event_name != 'pull_request' }} 323 sbom: true 324 set: | 325 *.cache-from=type=gha,scope=bin-image 326 *.cache-to=type=gha,scope=bin-image,mode=max 327 328 release: 329 runs-on: ubuntu-22.04 330 needs: 331 - test-integration 332 - test-unit 333 - binaries 334 steps: 335 - 336 name: Checkout 337 uses: actions/checkout@v4 338 - 339 name: Download binaries 340 uses: actions/download-artifact@v4 341 with: 342 path: ${{ env.DESTDIR }} 343 pattern: buildx-* 344 merge-multiple: true 345 - 346 name: Create checksums 347 run: ./hack/hash-files 348 - 349 name: List artifacts 350 run: | 351 tree -nh ${{ env.DESTDIR }} 352 - 353 name: Check artifacts 354 run: | 355 find ${{ env.DESTDIR }} -type f -exec file -e ascii -- {} + 356 - 357 name: GitHub Release 358 if: startsWith(github.ref, 'refs/tags/v') 359 uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564 # v2.0.4 360 env: 361 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 362 with: 363 draft: true 364 files: ${{ env.DESTDIR }}/*