Skip to content

Commit 63c2c0f

Browse files
address sourcery comment to prevent injection vulnerabilities
1 parent 7292ede commit 63c2c0f

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

.github/workflows/build-and-push.yaml

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,36 +47,48 @@ jobs:
4747
#
4848
# Print variables for debugging
4949
- name: Log reference variables
50+
env:
51+
GITHUB_REF: ${{ github.ref }}
52+
GITHUB_HEAD_REF: ${{ github.head_ref }}
53+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
54+
QUAY_RELEASE_REPO: ${{ vars.QUAY_RELEASE_REPO }}
5055
run: |
51-
echo "CONTEXT: ${{ env.BUILD_CONTEXT }}"
52-
echo "GITHUB.REF: ${{ github.ref }}"
53-
echo "GITHUB.HEAD_REF: ${{ github.head_ref }}"
54-
echo "SHA: ${{ github.event.pull_request.head.sha }}"
55-
echo "MAIN IMAGE AT: ${{ vars.QUAY_RELEASE_REPO }}:latest"
56-
echo "CI IMAGE AT: quay.io/trustyai/guardrails-detector-huggingface-runtime-ci:${{ github.event.pull_request.head.sha }}"
57-
echo "Built-In Detector CI IMAGE AT: quay.io/trustyai/guardrails-detector-built-in-ci:${{ github.event.pull_request.head.sha }}"
58-
echo "LLM Judge CI IMAGE AT: quay.io/trustyai/guardrails-detector-llm-judge-ci:${{ github.event.pull_request.head.sha }}"
56+
echo "CONTEXT: $BUILD_CONTEXT"
57+
echo "GITHUB.REF: $GITHUB_REF"
58+
echo "GITHUB.HEAD_REF: $GITHUB_HEAD_REF"
59+
echo "SHA: $PR_HEAD_SHA"
60+
echo "MAIN IMAGE AT: $QUAY_RELEASE_REPO:latest"
61+
echo "CI IMAGE AT: quay.io/trustyai/guardrails-detector-huggingface-runtime-ci:$PR_HEAD_SHA"
62+
echo "Built-In Detector CI IMAGE AT: quay.io/trustyai/guardrails-detector-built-in-ci:$PR_HEAD_SHA"
63+
echo "LLM Judge CI IMAGE AT: quay.io/trustyai/guardrails-detector-llm-judge-ci:$PR_HEAD_SHA"
5964
6065
# Set environments depending on context
6166
- name: Set CI environment
6267
if: env.BUILD_CONTEXT == 'ci'
68+
env:
69+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
6370
run: |
64-
echo "TAG=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
71+
echo "TAG=$PR_HEAD_SHA" >> $GITHUB_ENV
6572
echo "IMAGE_NAME=quay.io/trustyai/guardrails-detector-huggingface-runtime-ci" >> $GITHUB_ENV
6673
echo "BUILTIN_IMAGE_NAME=quay.io/trustyai/guardrails-detector-built-in-ci" >> $GITHUB_ENV
6774
echo "LLM_JUDGE_IMAGE_NAME=quay.io/trustyai/guardrails-detector-llm-judge-ci" >> $GITHUB_ENV
6875
- name: Set main-branch environment
6976
if: env.BUILD_CONTEXT == 'main'
77+
env:
78+
QUAY_RELEASE_REPO: ${{ vars.QUAY_RELEASE_REPO }}
7079
run: |
7180
echo "TAG=latest" >> $GITHUB_ENV
72-
echo "IMAGE_NAME=${{ vars.QUAY_RELEASE_REPO }}" >> $GITHUB_ENV
81+
echo "IMAGE_NAME=$QUAY_RELEASE_REPO" >> $GITHUB_ENV
7382
echo "BUILTIN_IMAGE_NAME=quay.io/trustyai/guardrails-detector-built-in" >> $GITHUB_ENV
7483
echo "LLM_JUDGE_IMAGE_NAME=quay.io/trustyai/guardrails-detector-llm-judge" >> $GITHUB_ENV
7584
- name: Set tag environment
7685
if: env.BUILD_CONTEXT == 'tag'
86+
env:
87+
GITHUB_REF_NAME: ${{ github.ref_name }}
88+
QUAY_RELEASE_REPO: ${{ vars.QUAY_RELEASE_REPO }}
7789
run: |
78-
echo "TAG=${{ github.ref_name }}" >> $GITHUB_ENV
79-
echo "IMAGE_NAME=${{ vars.QUAY_RELEASE_REPO }}" >> $GITHUB_ENV
90+
echo "TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV
91+
echo "IMAGE_NAME=$QUAY_RELEASE_REPO" >> $GITHUB_ENV
8092
echo "BUILTIN_IMAGE_NAME=quay.io/trustyai/guardrails-detector-built-in" >> $GITHUB_ENV
8193
echo "LLM_JUDGE_IMAGE_NAME=quay.io/trustyai/guardrails-detector-llm-judge" >> $GITHUB_ENV
8294
#
@@ -88,19 +100,22 @@ jobs:
88100
echo 'LABEL quay.expires-after=7d#' >> detectors/Dockerfile.builtIn
89101
echo 'LABEL quay.expires-after=7d#' >> detectors/Dockerfile.judge
90102
- name: Build image
91-
run: docker build -t ${{ env.IMAGE_NAME }}:$TAG -f detectors/Dockerfile.hf detectors
103+
run: docker build -t "$IMAGE_NAME:$TAG" -f detectors/Dockerfile.hf detectors
92104
- name: Log in to Quay
93-
run: docker login -u ${{ secrets.QUAY_ROBOT_USERNAME }} -p ${{ secrets.QUAY_ROBOT_SECRET }} quay.io
105+
env:
106+
QUAY_ROBOT_USERNAME: ${{ secrets.QUAY_ROBOT_USERNAME }}
107+
QUAY_ROBOT_SECRET: ${{ secrets.QUAY_ROBOT_SECRET }}
108+
run: docker login -u "$QUAY_ROBOT_USERNAME" -p "$QUAY_ROBOT_SECRET" quay.io
94109
- name: Push to Quay CI repo
95-
run: docker push ${{ env.IMAGE_NAME }}:$TAG
110+
run: docker push "$IMAGE_NAME:$TAG"
96111
- name: Build built-in detector image
97-
run: docker build -t ${{ env.BUILTIN_IMAGE_NAME }}:$TAG -f detectors/Dockerfile.builtIn detectors
112+
run: docker build -t "$BUILTIN_IMAGE_NAME:$TAG" -f detectors/Dockerfile.builtIn detectors
98113
- name: Push to Quay CI repo
99-
run: docker push ${{ env.BUILTIN_IMAGE_NAME }}:$TAG
114+
run: docker push "$BUILTIN_IMAGE_NAME:$TAG"
100115
- name: Build LLM Judge detector image
101-
run: docker build -t ${{ env.LLM_JUDGE_IMAGE_NAME }}:$TAG -f detectors/Dockerfile.judge detectors
116+
run: docker build -t "$LLM_JUDGE_IMAGE_NAME:$TAG" -f detectors/Dockerfile.judge detectors
102117
- name: Push LLM Judge image to Quay CI repo
103-
run: docker push ${{ env.LLM_JUDGE_IMAGE_NAME }}:$TAG
118+
run: docker push "$LLM_JUDGE_IMAGE_NAME:$TAG"
104119
# Leave comment
105120
- uses: peter-evans/find-comment@v3
106121
name: Find Comment
@@ -113,16 +128,18 @@ jobs:
113128
- uses: peter-evans/create-or-update-comment@v4
114129
if: env.BUILD_CONTEXT == 'ci'
115130
name: Generate/update success message comment
131+
env:
132+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
116133
with:
117134
comment-id: ${{ steps.fc.outputs.comment-id }}
118135
issue-number: ${{ github.event.pull_request.number }}
119136
edit-mode: replace
120137
body: |
121138
PR image build completed successfully!
122139
123-
📦 [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 }}`
124-
📦 [PR image](https://quay.io/trustyai/guardrails-detector-built-in-ci?tab=tags): `quay.io/trustyai/guardrails-detector-built-in-ci:${{ github.event.pull_request.head.sha }}`
125-
📦 [PR image](https://quay.io/trustyai/guardrails-detector-llm-judge-ci?tab=tags): `quay.io/trustyai/guardrails-detector-llm-judge-ci:${{ github.event.pull_request.head.sha }}`
140+
📦 [PR image](https://quay.io/repository/trustyai/guardrails-detector-huggingface-runtime-ci?tab=tags): `quay.io/trustyai/guardrails-detector-huggingface-runtime-ci:$PR_HEAD_SHA`
141+
📦 [PR image](https://quay.io/trustyai/guardrails-detector-built-in-ci?tab=tags): `quay.io/trustyai/guardrails-detector-built-in-ci:$PR_HEAD_SHA`
142+
📦 [PR image](https://quay.io/trustyai/guardrails-detector-llm-judge-ci?tab=tags): `quay.io/trustyai/guardrails-detector-llm-judge-ci:$PR_HEAD_SHA`
126143
- name: Trivy scan
127144
uses: aquasecurity/[email protected]
128145
with:

0 commit comments

Comments
 (0)