|
| 1 | +# Copyright 2022 Pants project contributors. |
| 2 | +# Licensed under the Apache License, Version 2.0 (see LICENSE). |
| 3 | + |
| 4 | +# See https://www.pantsbuild.org/stable/docs/using-pants/using-pants-in-ci for tips on how to set up your CI with Pants. |
| 5 | + |
| 6 | +name: Pants |
| 7 | + |
| 8 | +on: [push, pull_request] |
| 9 | + |
| 10 | +jobs: |
| 11 | + org-check: |
| 12 | + name: Check GitHub Organization |
| 13 | + if: ${{ github.repository_owner == 'pantsbuild' }} |
| 14 | + runs-on: ubuntu-20.04 |
| 15 | + steps: |
| 16 | + - name: Noop |
| 17 | + run: "true" |
| 18 | + |
| 19 | + build: |
| 20 | + name: Perform CI Checks |
| 21 | + needs: org-check |
| 22 | + runs-on: ubuntu-20.04 |
| 23 | + strategy: |
| 24 | + matrix: |
| 25 | + python-version: [3.8] |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - uses: actions/setup-python@v5 |
| 30 | + with: |
| 31 | + python-version: ${{ matrix.python-version }} |
| 32 | + |
| 33 | + - uses: crazy-max/ghaction-setup-docker@v3 |
| 34 | + with: |
| 35 | + daemon-config: | |
| 36 | + { |
| 37 | + "features": { |
| 38 | + "containerd-snapshotter": true |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + - uses: docker/setup-buildx-action@v3 |
| 43 | + with: |
| 44 | + install: true |
| 45 | + driver: docker |
| 46 | + |
| 47 | + # Required for multi-platform builds |
| 48 | + - name: Setup QEMU |
| 49 | + uses: docker/setup-qemu-action@v3 |
| 50 | + with: |
| 51 | + platforms: linux/amd64,linux/arm64 |
| 52 | + |
| 53 | + - name: Set up environment variables for Pants (Docker) to use GHA Cache |
| 54 | + uses: actions/github-script@v7 |
| 55 | + with: |
| 56 | + script: | |
| 57 | + core.exportVariable("ACTIONS_CACHE_URL", process.env.ACTIONS_CACHE_URL || ""); |
| 58 | + core.exportVariable("ACTIONS_RUNTIME_TOKEN", process.env.ACTIONS_RUNTIME_TOKEN || ""); |
| 59 | + |
| 60 | + - uses: pantsbuild/actions/init-pants@v9 |
| 61 | + # This action bootstraps pants and manages 2-3 GHA caches. |
| 62 | + # See: github.com/pantsbuild/actions/tree/main/init-pants/ |
| 63 | + with: |
| 64 | + # v0 makes it easy to bust the cache if needed |
| 65 | + # just increase the integer to start with a fresh cache |
| 66 | + gha-cache-key: v0 |
| 67 | + # This repo has no 3rd-party requirements and no lockfiles, so we don't invalidate |
| 68 | + # the named caches on anything extra. See other example repos for better examples of |
| 69 | + # how to set up this cache. |
| 70 | + named-caches-hash: "" |
| 71 | + # If you're not using a fine-grained remote caching service (see https://www.pantsbuild.org/docs/remote-caching), |
| 72 | + # then you may also want to preserve the local Pants cache (lmdb_store). However this must invalidate for |
| 73 | + # changes to any file that can affect the build, so may not be practical in larger repos. |
| 74 | + # A remote cache service integrates with Pants's fine-grained invalidation and avoids these problems. |
| 75 | + cache-lmdb-store: "true" # defaults to 'false' |
| 76 | + # Note that named_caches and lmdb_store falls back to partial restore keys which |
| 77 | + # may give a useful partial result that will save time over completely clean state, |
| 78 | + # but will cause the cache entry to grow without bound over time. |
| 79 | + # See https://www.pantsbuild.org/stable/docs/using-pants/using-pants-in-ci for tips on how to periodically clean it up. |
| 80 | + # Alternatively you change gha-cache-key to ignore old caches. |
| 81 | + |
| 82 | + - name: Bootstrap Pants |
| 83 | + run: pants --version |
| 84 | + |
| 85 | + - name: Check Pants config files |
| 86 | + run: pants tailor --check update-build-files --check '::' |
| 87 | + |
| 88 | + - name: Lint, compile, and test |
| 89 | + run: pants lint check test '::' |
| 90 | + |
| 91 | + - name: Package / Run |
| 92 | + env: |
| 93 | + DYNAMIC_TAG: workflow |
| 94 | + run: | |
| 95 | + pants --docker-build-verbose package :: |
| 96 | + |
| 97 | + - name: Upload Pants log |
| 98 | + uses: actions/upload-artifact@v4 |
| 99 | + with: |
| 100 | + name: pants-log |
| 101 | + path: .pants.d/pants.log |
| 102 | + if: always() # We want the log even on failures. |
0 commit comments