Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add workflow to enable automatic vulnerability reports #72

Merged
merged 7 commits into from
Oct 11, 2024
Merged
Changes from 1 commit
Commits
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
78 changes: 78 additions & 0 deletions .github/workflows/report-vulnerability-in-gh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Report vulnerability issues in Github
on:
workflow_call:
inputs:
issue-title:
description: The title of the issue to be created/edited
required: true
type: string
issue-labels:
description: A comma separated list of labels
required: false
type: string
default: "bug"
image-name:
description: "Name of the oci-image as saved in Dockerhub or in the docker cache.
It consists of <rock-name>:<rock-version>."
orfeas-k marked this conversation as resolved.
Show resolved Hide resolved
required: true
type: string

jobs:
report-vulns:
name: Create or edit issues for reporting vulnerabilities
orfeas-k marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-22.04
steps:
- name: Install tools
run: |
sudo snap install gh
sudo snap install jq

- name: Generate image name
id: image-name
run: |
IMAGE_NAME=$(echo ${{ inputs.image-name }} | sed 's/\:/-/g')
orfeas-k marked this conversation as resolved.
Show resolved Hide resolved
echo "image-name=${IMAGE_NAME}" >> "$GITHUB_OUTPUT"

- name: Get issue number if exists
id: get-issue-number
run: |
export GH_TOKEN=${{ secrets.GH_TOKEN }}
EXPECTED_TITLE=$(echo "${{ inputs.issue-title }} ${{ inputs.image-name }}")
DnPlas marked this conversation as resolved.
Show resolved Hide resolved
ISSUE_NUMBER=$(gh issue list --repo $GITHUB_REPOSITORY --limit 500 --json "number,title" | jq -r --arg expected_title "$EXPECTED_TITLE" '.[] | select(.title == $expected_title) | .number')
echo "issue-number=$ISSUE_NUMBER" >> $GITHUB_OUTPUT

- name: Download report
uses: actions/download-artifact@v4
with:
name: trivy-report-${{ steps.image-name.outputs.image-name }}

- name: Issue body
id: issue-body
run: |
set -xeu
EXPECTED_TITLE=$(echo "${{ inputs.issue-title }} ${{ inputs.image-name }}")
orfeas-k marked this conversation as resolved.
Show resolved Hide resolved
echo "## $EXPECTED_TITLE" > issue.md
echo "" >> issue.md
echo "\`\`\`" >> issue.md
cat trivy-report-${{ steps.image-name.outputs.image-name }}.txt >> issue.md
echo "\`\`\`" >> issue.md
echo "" >> issue.md
echo -e "\nDetails: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> issue.md
echo "issue-body-file=issue.md" >> "$GITHUB_OUTPUT"

- name: Report failures via Github issue
run: |
export GH_TOKEN=${{ secrets.GH_TOKEN }}
EXPECTED_TITLE=$(echo "${{ inputs.issue-title }} ${{ inputs.image-name }}")
if [ -z ${{ steps.get-issue-number.outputs.issue-number }} ]; then
echo "---- Creating issue ----"
gh issue create --repo $GITHUB_REPOSITORY \
--title "$EXPECTED_TITLE" \
--label "${{ inputs.issue-labels }}" \
--body-file "${{ steps.issue-body.outputs.issue-body-file }}"
else
echo "---- Editing issue ${{ steps.get-issue-number.outputs.issue-number }}----"
gh issue edit --repo $GITHUB_REPOSITORY ${{ steps.get-issue-number.outputs.issue-number }} \
--title "$EXPECTED_TITLE" \
--body-file "${{ steps.issue-body.outputs.issue-body-file }}"
orfeas-k marked this conversation as resolved.
Show resolved Hide resolved
fi