|
| 1 | +name: Test and Lint Orchestrator |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + pull_request: |
| 7 | + branches: ["main"] |
| 8 | + |
| 9 | +env: |
| 10 | + CARGO_TERM_COLOR: always |
| 11 | + TEST_IMAGE_NAME: "orchestr8-tests:0" |
| 12 | + LINT_IMAGE_NAME: "orchestr8-lint:0" |
| 13 | + FMT_IMAGE_NAME: "orchestr8-fmt:0" |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + packages: write |
| 20 | + contents: read |
| 21 | + env: |
| 22 | + CACHE_TEST_IMAGE: "ghcr.io/foundation-model-stack/fms-guardrails-orchestrator:test-cache" |
| 23 | + CACHE_LINT_IMAGE: "ghcr.io/foundation-model-stack/fms-guardrails-orchestrator:lint-cache" |
| 24 | + CACHE_FMT_IMAGE: "ghcr.io/foundation-model-stack/fms-guardrails-orchestrator:fmt-cache" |
| 25 | + CACHE_REGISTRY: "ghcr.io" |
| 26 | + |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + - name: "Setup Docker Buildx" |
| 30 | + uses: docker/setup-buildx-action@v3 |
| 31 | + - name: "Log in to cache image container registry" |
| 32 | + uses: docker/login-action@v3 |
| 33 | + if: github.event_name != 'pull_request' |
| 34 | + with: |
| 35 | + registry: ${{ env.CACHE_REGISTRY }} |
| 36 | + username: ${{ github.actor }} |
| 37 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 38 | + - name: "Set build cache target" |
| 39 | + run: | |
| 40 | + # For push to `main` (PR merged), push a new cache image with all layers (cache-mode=max). |
| 41 | + # For PR builds, use GitHub action cache which isolates cached layers by PR/branch. |
| 42 | + # to optimize builds for subsequent pushes to the same PR/branch. |
| 43 | + # Do not set a cache-to image for PR builds to not overwrite the `main` cache image and |
| 44 | + # to not ping-pong cache images for two or more different PRs. |
| 45 | + # Do not push cache images for each PR or multiple branches to not exceed GitHub package |
| 46 | + # usage and traffic limitations. |
| 47 | + # UPDATE: GHA cache appears to have issues, cannot use `cache-to: gha,mode=min` |
| 48 | + # if `cache-from: reg...,mode=max` but `cache-to: gha,mode=max` takes longer than uncached |
| 49 | + # build and exhausts GHA cache size limits, so use cache `type=inline` (no external cache). |
| 50 | + if [ "${{ github.event_name }}" == "pull_request" ] |
| 51 | + then |
| 52 | + #CACHE_TO="type=gha,mode=min" |
| 53 | + CACHE_TEST_TO="type=inline" |
| 54 | + CACHE_LINT_TO="type=inline" |
| 55 | + CACHE_FMT_TO="type=inline" |
| 56 | + else |
| 57 | + CACHE_TEST_TO="type=registry,ref=${{ env.CACHE_TEST_IMAGE }},mode=max" |
| 58 | + CACHE_LINT_TO="type=registry,ref=${{ env.CACHE_LINT_IMAGE }},mode=max" |
| 59 | + CACHE_FMT_TO="type=registry,ref=${{ env.CACHE_FMT_IMAGE }},mode=max" |
| 60 | + fi |
| 61 | + echo "CACHE_TEST_TO=$CACHE_TEST_TO" >> $GITHUB_ENV |
| 62 | + echo "CACHE_LINT_TO=$CACHE_LINT_TO" >> $GITHUB_ENV |
| 63 | + echo "CACHE_FMT_TO=$CACHE_FMT_TO" >> $GITHUB_ENV |
| 64 | + - name: Test |
| 65 | + uses: docker/build-push-action@v5 |
| 66 | + with: |
| 67 | + context: . |
| 68 | + target: tests |
| 69 | + tags: ${{ env.TEST_IMAGE_NAME }} |
| 70 | + cache-from: type=registry,ref=${{ env.CACHE_TEST_IMAGE }} |
| 71 | + cache-to: ${{ env.CACHE_TEST_TO }} |
| 72 | + push: false |
| 73 | + platforms: linux/amd64 |
| 74 | + - name: Lint with clippy |
| 75 | + uses: docker/build-push-action@v5 |
| 76 | + with: |
| 77 | + context: . |
| 78 | + target: lint |
| 79 | + tags: ${{ env.LINT_IMAGE_NAME }} |
| 80 | + cache-from: type=registry,ref=${{ env.CACHE_LINT_IMAGE }} |
| 81 | + cache-to: ${{ env.CACHE_LINT_TO }} |
| 82 | + push: false |
| 83 | + platforms: linux/amd64 |
| 84 | + - name: Format |
| 85 | + uses: docker/build-push-action@v5 |
| 86 | + with: |
| 87 | + context: . |
| 88 | + target: format |
| 89 | + tags: ${{ env.FMT_IMAGE_NAME }} |
| 90 | + cache-from: type=registry,ref=${{ env.CACHE_FMT_IMAGE }} |
| 91 | + cache-to: ${{ env.CACHE_FMT_TO }} |
| 92 | + push: false |
| 93 | + platforms: linux/amd64 |
0 commit comments