@@ -2,92 +2,44 @@ name: Test and Lint Orchestrator
22
33on :
44 push :
5- branches : ["main"]
5+ branches : [ "main" ]
66 pull_request :
7- branches : ["main"]
7+ branches : [ "main" ]
8+ types : [opened, reopened, synchronize, ready_for_review]
89
910env :
1011 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"
12+ RUSTFLAGS : " -Dwarnings" # Makes CI fail on compilation/clippy warnings
13+ PROTOC_VERSION : " 26.0"
1414
1515jobs :
16- build :
16+ ci-checks :
1717 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-
18+ if : github.event.pull_request.draft == false
2719 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
20+ - name : " Install fmt nightly"
21+ run : rustup component add --toolchain nightly-x86_64-unknown-linux-gnu rustfmt
22+ - name : " Install protoc"
23+ run : |
24+ echo "protoc version: ${PROTOC_VERSION}"
25+ cd /tmp
26+ curl -L -O https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip
27+ sudo unzip protoc-*.zip -d /usr/local && rm protoc-*.zip
28+ protoc --version
29+ - uses : actions/checkout@v4
30+ - name : Cache Rust dependencies
31+ uses : actions/cache@v4
32+ with :
33+ path : |
34+ ~/.cargo/registry
35+ ~/.cargo/git
36+ target
37+ key : ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
38+ - name : Build
39+ run : cargo build
40+ - name : Run formatter
41+ run : cargo +nightly fmt --check --all
42+ - name : Run linter
43+ run : cargo clippy --no-deps --all-targets --all-features
44+ - name : Run tests
45+ run : cargo test
0 commit comments