|
| 1 | +# Workflow to upload released versions, RC or final, Black Duck Binary Analysis (BDBA) for scanning. |
| 2 | +# Uses CTF from GitHub release assets. |
| 3 | +# This workflow is triggered manually and allows to specify the OCM version to scan. |
| 4 | +# Can be used in case the BDBA upload did not work in the release workflow. |
| 5 | + |
| 6 | +name: BDBA Scan for dedicated OCM version |
| 7 | + |
| 8 | +on: |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + OCM_VERSION: |
| 12 | + description: 'The OCM version to scan (e.g., 0.22.0)' |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + |
| 16 | +permissions: |
| 17 | + actions: read |
| 18 | + contents: read |
| 19 | + |
| 20 | +jobs: |
| 21 | + upload-and-scan-ctfs: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + steps: |
| 25 | + # Checkout code from correct repository as executed in .github repo |
| 26 | + - name: Checkout code |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + repository: open-component-model/ocm |
| 30 | + ref: main |
| 31 | + |
| 32 | + # Download CTF from GH release assets |
| 33 | + - name: Download CTF |
| 34 | + run: | |
| 35 | + if [ -z "${{ github.event.inputs.OCM_VERSION }}" ]; then |
| 36 | + echo "Error: OCM_VERSION parameter is required" |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | + |
| 40 | + CTF_URL="https://github.com/open-component-model/ocm/releases/download/v${{ github.event.inputs.OCM_VERSION }}/ocm-${{ github.event.inputs.OCM_VERSION }}-ctf.tgz" |
| 41 | + echo "Downloading CTF from: $CTF_URL" |
| 42 | + |
| 43 | + mkdir -p "${{ github.workspace }}/gen" |
| 44 | + curl -L -o "${{ github.workspace }}/gen/ctf-aggregated" "$CTF_URL" |
| 45 | +
|
| 46 | + # Since OCM cli is required to download CVs from CTF, extract binary from CTF |
| 47 | + - name: Extract OCM Binary from CTF |
| 48 | + id: extract-ocm |
| 49 | + run: | |
| 50 | + ocm_binary="$(bash ./hack/get_bare_resource_from_ctf.sh \ |
| 51 | + "ocm.software/ocmcli" \ |
| 52 | + "" \ |
| 53 | + "ocmcli" \ |
| 54 | + "amd64" \ |
| 55 | + "linux" \ |
| 56 | + "application/octet-stream" \ |
| 57 | + ${{ github.workspace }}/gen/ctf-aggregated)" |
| 58 | + |
| 59 | + new_loc="${{ github.workspace }}/bin/ocm" |
| 60 | + mkdir -p "$(dirname "$new_loc")" |
| 61 | + ln -s "$ocm_binary" "$new_loc" |
| 62 | + chmod +x "$new_loc" |
| 63 | + echo "OCM binary linked to \"$new_loc\"" |
| 64 | + echo "binary=\"$new_loc\"" >> "$GITHUB_OUTPUT" |
| 65 | + |
| 66 | + # Download CVs from CTF as TAR, loop over all TARs and upload them to BDBA |
| 67 | + - name: Upload CVs from CTF from GH assets to Blackduck |
| 68 | + id: blackduck-upload-ctf |
| 69 | + run: | |
| 70 | + set -e # Exit immediately if any command fails with non-zero status |
| 71 | + echo "Download CVs from CTF (creates CommonTransportFormat-ctf root folder)" |
| 72 | + echo "Upload single CVs to BDBA" |
| 73 | + echo "Large files may take a while to upload. Please be patient." |
| 74 | + echo |
| 75 | + cd ${{ github.workspace }}/gen/ |
| 76 | + ${{ steps.extract-ocm.outputs.binary }} download cv --type tar ${{ github.workspace }}/gen/ctf-aggregated |
| 77 | + # Find all CV tar files within CommonTransportFormat-ctf |
| 78 | + find "CommonTransportFormat-${{ github.workspace }}/gen/ctf-aggregated" -type f -print0 | while IFS= read -r -d '' file; do |
| 79 | + # Extract the relative path and construct the upload name |
| 80 | + relative_path="${file#CommonTransportFormat-${{ github.workspace }}/gen/ctf-aggregated/}" |
| 81 | + upload_name="${relative_path%/*}" |
| 82 | + upload_name="${upload_name//\//-}" |
| 83 | +
|
| 84 | + # Extract the version from the filename |
| 85 | + version=$(basename "$file") |
| 86 | + version="${version%.tar}" |
| 87 | +
|
| 88 | + # Construct the API URL |
| 89 | + api_url="${{ secrets.BDBA_URL }}/api/upload/${upload_name}" |
| 90 | +
|
| 91 | + # Upload the file using curl |
| 92 | + echo "Uploading $upload_name to BDBA" |
| 93 | + curl_output=$(curl -sS -X PUT -H "Authorization: Bearer ${{ secrets.BDBA_API_TOKEN }}" -H "Group: ${{ secrets.BDBA_GROUP_ID }}" -H "Version: $version" -H "Delete-Binary: true" --data-binary "@$file" "$api_url") |
| 94 | +
|
| 95 | + # Check if upload was successful and print results |
| 96 | + if [[ $(echo "$curl_output" | jq '.meta.code') == "200" ]]; then |
| 97 | + echo "--- Upload successful ---" |
| 98 | + echo " filename: $(echo "$curl_output" | jq '.results.filename')" |
| 99 | + echo " last_updated: $(echo "$curl_output" | jq '.results.last_updated')" |
| 100 | + else |
| 101 | + echo "Upload failed with" |
| 102 | + echo "$curl_output" |
| 103 | + exit 1 |
| 104 | + fi |
| 105 | + done |
0 commit comments