1
+ name : Build and Push - LLM Judge Detector
2
+ on :
3
+ push :
4
+ branches :
5
+ - main
6
+ tags :
7
+ - v*
8
+ paths :
9
+ - ' detectors/llm_judge/*'
10
+ - ' detectors/Dockerfile.judge'
11
+ pull_request_target :
12
+ paths :
13
+ - ' detectors/llm_judge/*'
14
+ - ' detectors/Dockerfile.judge'
15
+ types : [labeled, opened, synchronize, reopened]
16
+ jobs :
17
+ # Ensure that tests pass before publishing a new image.
18
+ build-and-push-ci :
19
+ runs-on : ubuntu-latest
20
+ permissions :
21
+ contents : read
22
+ pull-requests : write
23
+ security-events : write
24
+ steps : # Assign context variable for various action contexts (tag, main, CI)
25
+ - name : Assigning CI context
26
+ if : github.head_ref != '' && github.head_ref != 'main' && !startsWith(github.ref, 'refs/tags/v')
27
+ run : echo "BUILD_CONTEXT=ci" >> $GITHUB_ENV
28
+ - name : Assigning tag context
29
+ if : github.head_ref == '' && startsWith(github.ref, 'refs/tags/v')
30
+ run : echo "BUILD_CONTEXT=tag" >> $GITHUB_ENV
31
+ - name : Assigning main context
32
+ if : github.head_ref == '' && github.ref == 'refs/heads/main'
33
+ run : echo "BUILD_CONTEXT=main" >> $GITHUB_ENV
34
+ #
35
+ # Run checkouts
36
+ - uses : mheap/github-action-required-labels@v4
37
+ if : env.BUILD_CONTEXT == 'ci'
38
+ with :
39
+ mode : minimum
40
+ count : 1
41
+ labels : " ok-to-test, lgtm, approved"
42
+ - uses : actions/checkout@v3
43
+ if : env.BUILD_CONTEXT == 'ci'
44
+ with :
45
+ ref : ${{ github.event.pull_request.head.sha }}
46
+ - uses : actions/checkout@v3
47
+ if : env.BUILD_CONTEXT == 'main' || env.BUILD_CONTEXT == 'tag'
48
+ #
49
+ # Print variables for debugging
50
+ - name : Log reference variables
51
+ run : |
52
+ echo "CONTEXT: ${{ env.BUILD_CONTEXT }}"
53
+ echo "GITHUB.REF: ${{ github.ref }}"
54
+ echo "GITHUB.HEAD_REF: ${{ github.head_ref }}"
55
+ echo "SHA: ${{ github.event.pull_request.head.sha }}"
56
+ echo "MAIN IMAGE AT: quay.io/trustyai/guardrails-detector-llm-judge:latest"
57
+ echo "CI IMAGE AT: quay.io/trustyai/guardrails-detector-llm-judge-ci:${{ github.event.pull_request.head.sha }}"
58
+
59
+ # Set environments depending on context
60
+ - name : Set CI environment
61
+ if : env.BUILD_CONTEXT == 'ci'
62
+ run : |
63
+ echo "TAG=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
64
+ echo "IMAGE_NAME=quay.io/trustyai/guardrails-detector-llm-judge-ci" >> $GITHUB_ENV
65
+ - name : Set main-branch environment
66
+ if : env.BUILD_CONTEXT == 'main'
67
+ run : |
68
+ echo "TAG=latest" >> $GITHUB_ENV
69
+ echo "IMAGE_NAME=quay.io/trustyai/guardrails-detector-llm-judge" >> $GITHUB_ENV
70
+ - name : Set tag environment
71
+ if : env.BUILD_CONTEXT == 'tag'
72
+ run : |
73
+ echo "TAG=${{ github.ref_name }}" >> $GITHUB_ENV
74
+ echo "IMAGE_NAME=quay.io/trustyai/guardrails-detector-llm-judge" >> $GITHUB_ENV
75
+ #
76
+ # Run docker commands
77
+ - name : Put expiry date on CI-tagged image
78
+ if : env.BUILD_CONTEXT == 'ci'
79
+ run : echo 'LABEL quay.expires-after=7d#' >> detectors/Dockerfile.judge
80
+ - name : Build image
81
+ run : docker build -t ${{ env.IMAGE_NAME }}:$TAG -f detectors/Dockerfile.judge detectors
82
+ - name : Log in to Quay
83
+ run : docker login -u ${{ secrets.QUAY_ROBOT_USERNAME }} -p ${{ secrets.QUAY_ROBOT_SECRET }} quay.io
84
+ - name : Push to Quay CI repo
85
+ run : docker push ${{ env.IMAGE_NAME }}:$TAG
86
+
87
+ # Leave comment
88
+ - uses : peter-evans/find-comment@v3
89
+ name : Find Comment
90
+ if : env.BUILD_CONTEXT == 'ci'
91
+ id : fc
92
+ with :
93
+ issue-number : ${{ github.event.pull_request.number }}
94
+ comment-author : ' github-actions[bot]'
95
+ body-includes : PR image build completed successfully
96
+ - uses : peter-evans/create-or-update-comment@v4
97
+ if : env.BUILD_CONTEXT == 'ci'
98
+ name : Generate/update success message comment
99
+ with :
100
+ comment-id : ${{ steps.fc.outputs.comment-id }}
101
+ issue-number : ${{ github.event.pull_request.number }}
102
+ edit-mode : replace
103
+ body : |
104
+ PR image build completed successfully!
105
+
106
+ 📦 [PR image](https://quay.io/repository/trustyai/guardrails-detector-llm-judge-ci?tab=tags): `quay.io/trustyai/guardrails-detector-llm-judge-ci:${{ github.event.pull_request.head.sha }}`
107
+ - name : Trivy scan
108
+ uses :
aquasecurity/[email protected]
109
+ with :
110
+ scan-type : ' image'
111
+ image-ref : " ${{ env.IMAGE_NAME }}:${{ env.TAG }}"
112
+ format : ' sarif'
113
+ output : ' trivy-results.sarif'
114
+ severity : ' MEDIUM,HIGH,CRITICAL'
115
+ exit-code : ' 0'
116
+ ignore-unfixed : false
117
+ vuln-type : ' os,library'
118
+
119
+ - name : Update Security tab
120
+ uses : github/codeql-action/upload-sarif@v3
121
+ with :
122
+ sarif_file : ' trivy-results.sarif'
0 commit comments