Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5880847
Add build pipeline for hf detector
RobGeada Apr 15, 2025
c0f88e6
dummy commit for action testing
RobGeada Apr 15, 2025
e620db9
Update workflow name
RobGeada Apr 15, 2025
03d1982
Update workflow name, remove prerequisite image pull
RobGeada Apr 15, 2025
15d27ef
Update workflow image name
RobGeada Apr 15, 2025
5568e5a
Merge branch 'HFBuild' of https://github.com/trustyai-explainability/…
RobGeada Apr 15, 2025
f27ef72
Update action for correct image name
RobGeada Apr 15, 2025
676d231
Merge branch 'HFBuild' of https://github.com/trustyai-explainability/…
RobGeada Apr 15, 2025
20964c5
debug
RobGeada Apr 15, 2025
c0d0df9
Merge branch 'HFBuild' of https://github.com/trustyai-explainability/…
RobGeada Apr 15, 2025
eb71bbf
Update action for correct image name
RobGeada Apr 15, 2025
72c2b58
Merge branch 'HFBuild' of https://github.com/trustyai-explainability/…
RobGeada Apr 15, 2025
dccf396
Update action for correct image name
RobGeada Apr 15, 2025
e12afce
Merge branch 'HFBuild' of https://github.com/trustyai-explainability/…
RobGeada Apr 15, 2025
1ebec00
Update action for correct image name
RobGeada Apr 15, 2025
6bac7dc
Merge branch 'HFBuild' of https://github.com/trustyai-explainability/…
RobGeada Apr 15, 2025
0e068a3
Update action for correct image name
RobGeada Apr 15, 2025
cdaf051
Merge branch 'HFBuild' of https://github.com/trustyai-explainability/…
RobGeada Apr 15, 2025
5fe8912
Update comment
RobGeada Apr 15, 2025
912c294
Merge branch 'HFBuild' of https://github.com/trustyai-explainability/…
RobGeada Apr 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions .github/workflows/build-and-push-hf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Build and Push - Huggingface Detector
on:
push:
branches:
- main
tags:
- v*
paths:
- 'detectors/huggingface/*'
- 'detectors/Dockerfile.hf'
pull_request_target:
paths:
- 'detectors/huggingface/*'
- 'detectors/Dockerfile.hf'
types: [labeled, opened, synchronize, reopened]
jobs:
# Ensure that tests pass before publishing a new image.
build-and-push-ci:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
security-events: write
steps: # Assign context variable for various action contexts (tag, main, CI)
- name: Assigning CI context
if: github.head_ref != '' && github.head_ref != 'main' && !startsWith(github.ref, 'refs/tags/v')
run: echo "BUILD_CONTEXT=ci" >> $GITHUB_ENV
- name: Assigning tag context
if: github.head_ref == '' && startsWith(github.ref, 'refs/tags/v')
run: echo "BUILD_CONTEXT=tag" >> $GITHUB_ENV
- name: Assigning main context
if: github.head_ref == '' && github.ref == 'refs/heads/main'
run: echo "BUILD_CONTEXT=main" >> $GITHUB_ENV
#
# Run checkouts
- uses: mheap/github-action-required-labels@v4
if: env.BUILD_CONTEXT == 'ci'
with:
mode: minimum
count: 1
labels: "ok-to-test, lgtm, approved"
- uses: actions/checkout@v3
if: env.BUILD_CONTEXT == 'ci'
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/checkout@v3
if: env.BUILD_CONTEXT == 'main' || env.BUILD_CONTEXT == 'tag'
#
# Print variables for debugging
- name: Log reference variables
run: |
echo "CONTEXT: ${{ env.BUILD_CONTEXT }}"
echo "GITHUB.REF: ${{ github.ref }}"
echo "GITHUB.HEAD_REF: ${{ github.head_ref }}"
echo "SHA: ${{ github.event.pull_request.head.sha }}"
echo "MAIN IMAGE AT: ${{ vars.QUAY_RELEASE_REPO }}:latest"
echo "CI IMAGE AT: quay.io/trustyai/guardrails-detector-huggingface-runtime-ci:${{ github.event.pull_request.head.sha }}"

# Set environments depending on context
- name: Set CI environment
if: env.BUILD_CONTEXT == 'ci'
run: |
echo "TAG=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
echo "IMAGE_NAME=quay.io/trustyai/guardrails-detector-huggingface-runtime-ci" >> $GITHUB_ENV
- name: Set main-branch environment
if: env.BUILD_CONTEXT == 'main'
run: |
echo "TAG=latest" >> $GITHUB_ENV
echo "IMAGE_NAME=${{ vars.QUAY_RELEASE_REPO }}" >> $GITHUB_ENV
- name: Set tag environment
if: env.BUILD_CONTEXT == 'tag'
run: |
echo "TAG=${{ github.ref_name }}" >> $GITHUB_ENV
echo "IMAGE_NAME=${{ vars.QUAY_RELEASE_REPO }}" >> $GITHUB_ENV
#
# Run docker commands
- name: Put expiry date on CI-tagged image
if: env.BUILD_CONTEXT == 'ci'
run: echo 'LABEL quay.expires-after=7d#' >> detectors/Dockerfile.hf
- name: Build image
run: docker build -t ${{ env.IMAGE_NAME }}:$TAG -f detectors/Dockerfile.hf detectors
- name: Log in to Quay
run: docker login -u ${{ secrets.QUAY_ROBOT_USERNAME }} -p ${{ secrets.QUAY_ROBOT_SECRET }} quay.io
- name: Push to Quay CI repo
run: docker push ${{ env.IMAGE_NAME }}:$TAG

# Leave comment
- uses: peter-evans/find-comment@v3
name: Find Comment
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: PR image build and manifest generation completed successfully
- uses: peter-evans/create-or-update-comment@v4
name: Generate/update success message comment
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
PR image build completed successfully!

📦 [PR image](https://quay.io/repository/trustyai/guardrails-detector-huggingface-runtime-ci?tab=tags): `quay.io/trustyai/guardrails-detector-huggingface-runtime-ci:${{ github.event.pull_request.head.sha }}`
- name: Trivy scan
uses: aquasecurity/[email protected]
with:
scan-type: 'image'
image-ref: "${{ env.IMAGE_NAME }}:${{ env.TAG }}"
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'MEDIUM,HIGH,CRITICAL'
exit-code: '0'
ignore-unfixed: false
vuln-type: 'os,library'

- name: Update Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
1 change: 1 addition & 0 deletions detectors/huggingface/dummy.abc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dummy