-
Notifications
You must be signed in to change notification settings - Fork 5
chore: add bdba action #47
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
026abc5
add bdba action
morri-son 56ab5d3
correct step ID
morri-son 9ebe115
correct linter issues
morri-son 4c44be5
add double quotes
morri-son 72c6e0f
more quotes
morri-son 0b6223d
add quotes for ocm_binary
morri-son 99f155c
add
morri-son c5207d7
move to ocm repo
morri-son c94ae83
add action
morri-son 627d4fa
add quotes
morri-son 010f99f
correct coment
morri-son 69c5206
add comments
morri-son File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # Workflow to upload CTFs to Black Duck Binary Analysis (BDBA) for scanning. | ||
| # Located in .github repo to be shared across all repositories in the GH org. | ||
| name: BDBA Scan | ||
|
|
||
| on: | ||
| # Trigger for call from other workflows | ||
| workflow_call: | ||
| inputs: | ||
| artifact_id: | ||
| description: Identifier for the artifact to download | ||
| required: false | ||
| type: string | ||
| # Secrets have to be passed from the calling workflow | ||
| # as for security reasons secrets are not shared between workflows | ||
| secrets: | ||
| BDBA_API_TOKEN: | ||
| required: true | ||
| BDBA_URL: | ||
| required: true | ||
| BDBA_GROUP_ID: | ||
| required: true | ||
|
|
||
| permissions: | ||
| actions: read | ||
| contents: read | ||
|
|
||
| jobs: | ||
| upload-and-scan-ctfs: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| # Since workflow is called, checkout code from correct repository | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| repository: open-component-model/ocm | ||
| ref: main | ||
|
|
||
| # Download the CTF that has been uploaded from release workflow | ||
| - name: Download CTF | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| pattern: '${{ inputs.artifact_id }}' | ||
| path: ${{ github.workspace }}/gen | ||
| # Since OCM cli is required to download CVs from CTF extract binary from CTF | ||
| - name: Extract OCM Binary from CTF | ||
| id: extract-ocm | ||
| run: | | ||
| ocm_binary="$(bash ./hack/get_bare_resource_from_ctf.sh \ | ||
| "ocm.software/ocmcli" \ | ||
| "" \ | ||
| "ocmcli" \ | ||
| "amd64" \ | ||
| "linux" \ | ||
| "application/octet-stream" \ | ||
| ${{ github.workspace }}/gen/ctf-aggregated)" | ||
|
|
||
| new_loc="${{ github.workspace }}/bin/ocm" | ||
| mkdir -p "$(dirname "$new_loc")" | ||
| ln -s "$ocm_binary" "$new_loc" | ||
| chmod +x "$new_loc" | ||
| echo "OCM binary linked to \"$new_loc\"" | ||
| echo "binary=\"$new_loc\"" >> "$GITHUB_OUTPUT" | ||
|
|
||
| # Download CVs from CTF as TAR, loop over all TARs and upload them to BDBA | ||
| - name: Upload to Blackduck for CTF | ||
| id: blackduck-upload-ctf | ||
| run: | | ||
| set -e # Exit immediately if any command fails with non-zero status | ||
| echo "Download CVs from CTF (creates CommonTransportFormat-ctf root folder)" | ||
| echo "Upload single CVs to BDBA" | ||
| echo "Large files may take a while to upload. Please be patient." | ||
| echo | ||
| cd ${{ github.workspace }}/gen/ | ||
| ${{ steps.extract-ocm.outputs.binary }} download cv --type tar ${{ github.workspace }}/gen/ctf-aggregated | ||
| # Find all CV tar files within CommonTransportFormat-ctf | ||
| find "CommonTransportFormat-${{ github.workspace }}/gen/ctf-aggregated" -type f -print0 | while IFS= read -r -d '' file; do | ||
| # Extract the relative path and construct the upload name | ||
| relative_path="${file#CommonTransportFormat-${{ github.workspace }}/gen/ctf-aggregated/}" | ||
| upload_name="${relative_path%/*}" | ||
| upload_name="${upload_name//\//-}" | ||
|
|
||
| # Extract the version from the filename | ||
| version=$(basename "$file") | ||
| version="${version%.tar}" | ||
|
|
||
| # Construct the API URL | ||
| api_url="${{ secrets.BDBA_URL }}/api/upload/${upload_name}" | ||
|
|
||
| # Upload the file using curl | ||
| echo "Uploading $upload_name to BDBA" | ||
| curl_output=$(curl -sS -X PUT -H "Authorization: Bearer ${{ secrets.BDBA_API_TOKEN }}" -H "Group: ${{ secrets.BDBA_GROUP_ID }}" -H "Version: $version" --data-binary "@$file" "$api_url") | ||
|
|
||
| # Check if upload was successful and print results | ||
| if [[ $(echo "$curl_output" | jq '.meta.code') == "200" ]]; then | ||
| echo "--- Upload successful ---" | ||
| echo " filename: $(echo "$curl_output" | jq '.results.filename')" | ||
| echo " last_updated: $(echo "$curl_output" | jq '.results.last_updated')" | ||
| else | ||
| echo "Upload failed with" | ||
| echo "$curl_output" | ||
| exit 1 | ||
| fi | ||
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.