|
1 | | -name: Release |
| 1 | +name: Release Published |
2 | 2 | run-name: Release NRL ${{ github.event.release.name }} |
3 | 3 | permissions: |
4 | 4 | id-token: write |
5 | | - contents: read |
| 5 | + contents: write |
6 | 6 | actions: write |
7 | 7 |
|
| 8 | +env: |
| 9 | + SYFT_VERSION: "1.27.1" |
| 10 | + |
8 | 11 | on: |
9 | 12 | release: |
10 | 13 | types: [published] |
|
15 | 18 |
|
16 | 19 | jobs: |
17 | 20 | sbom: |
18 | | - name: Generate SBOM - ${{ github.ref }} |
19 | | - runs-on: ubuntu-latest |
| 21 | + name: Generate Software Bill of Materials - ${{ github.event.release.name }} |
| 22 | + runs-on: codebuild-nhsd-nrlf-ci-build-project-${{ github.run_id }}-${{ github.run_attempt }} |
20 | 23 |
|
21 | 24 | steps: |
22 | 25 | - name: Git clone - ${{ github.ref }} |
23 | 26 | uses: actions/checkout@v4 |
24 | 27 | with: |
25 | 28 | ref: ${{ github.ref }} |
| 29 | + |
| 30 | + - name: Setup environment |
| 31 | + run: | |
| 32 | + echo "${HOME}/.asdf/bin" >> $GITHUB_PATH |
| 33 | + poetry install --no-root |
| 34 | +
|
| 35 | + - name: Configure Management Credentials |
| 36 | + uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a #v4.3.1 |
| 37 | + with: |
| 38 | + aws-region: eu-west-2 |
| 39 | + role-to-assume: ${{ secrets.MGMT_ROLE_ARN }} |
| 40 | + role-session-name: github-actions-ci-release-tag-${{ github.run_id }} |
| 41 | + |
| 42 | + - name: Terraform Init |
| 43 | + run: | |
| 44 | + terraform -chdir=terraform/account-wide-infrastructure/mgmt init |
| 45 | + terraform -chdir=terraform/account-wide-infrastructure/dev init |
| 46 | + terraform -chdir=terraform/account-wide-infrastructure/test init |
| 47 | + terraform -chdir=terraform/account-wide-infrastructure/prod init |
| 48 | + terraform -chdir=terraform/backup-infrastructure/test init |
| 49 | + terraform -chdir=terraform/backup-infrastructure/prod init |
| 50 | + terraform -chdir=terraform/bastion init |
| 51 | + terraform -chdir=terraform/infrastructure init |
| 52 | +
|
| 53 | + - name: Set architecture variable |
| 54 | + id: os-arch |
| 55 | + run: | |
| 56 | + case "${{ runner.arch }}" in |
| 57 | + X64) ARCH="amd64" ;; |
| 58 | + ARM64) ARCH="arm64" ;; |
| 59 | + esac |
| 60 | + echo "arch=${ARCH}" >> $GITHUB_OUTPUT |
| 61 | +
|
| 62 | + - name: Download and setup Syft |
| 63 | + run: | |
| 64 | + DOWNLOAD_URL="https://github.com/anchore/syft/releases/download/v${{ env.SYFT_VERSION }}/syft_${{ env.SYFT_VERSION }}_linux_${{ steps.os-arch.outputs.arch }}.tar.gz" |
| 65 | + echo "Downloading: ${DOWNLOAD_URL}" |
| 66 | + curl -L -o syft.tar.gz "${DOWNLOAD_URL}" |
| 67 | + tar -xzf syft.tar.gz |
| 68 | + chmod +x syft |
| 69 | + # Add to PATH for subsequent steps |
| 70 | + echo "$(pwd)" >> $GITHUB_PATH |
| 71 | +
|
| 72 | + - name: Create SBOM |
| 73 | + run: bash scripts/sbom-create.sh |
| 74 | + |
| 75 | + - name: Upload SBOM artifact |
| 76 | + uses: actions/upload-artifact@v4 |
| 77 | + with: |
| 78 | + name: sbom-${{ github.sha }} |
| 79 | + path: sbom.spdx.json |
| 80 | + |
| 81 | + - name: Append SBOM inventory to summary |
| 82 | + if: always() |
| 83 | + shell: bash |
| 84 | + run: | |
| 85 | + cat > sbom_to_summary.jq <<'JQ' |
| 86 | + def clean: (.|tostring) | gsub("\\|"; "\\|") | gsub("\r?\n"; " "); |
| 87 | + def purl: ((.externalRefs[]? | select(.referenceType=="purl") | .referenceLocator) // ""); |
| 88 | + def license: (.licenseConcluded // .licenseDeclared // ""); |
| 89 | + def supplier: ((.supplier // "") | sub("^Person: *|^Organization: *";"")); |
| 90 | + if (has("spdxVersion") | not) then |
| 91 | + "### SBOM Inventory (SPDX)\n\nSBOM is not SPDX JSON." |
| 92 | + else |
| 93 | + .packages as $pkgs |
| 94 | + | "### SBOM Inventory (SPDX)\n\n" |
| 95 | + + "| Metric | Value |\n|---|---|\n" |
| 96 | + + "| Packages | " + ($pkgs|length|tostring) + " |\n\n" |
| 97 | + + "<details><summary>Full inventory</summary>\n\n" |
| 98 | + + "| Package | Version | Supplier | License | PURL |\n|---|---|---|---|---|\n" |
| 99 | + + ( |
| 100 | + $pkgs |
| 101 | + | map("| " |
| 102 | + + ((.name // .SPDXID) | clean) |
| 103 | + + " | " + ((.versionInfo // "") | clean) |
| 104 | + + " | " + (supplier | clean) |
| 105 | + + " | " + (license | clean) |
| 106 | + + " | " + (purl | clean) |
| 107 | + + " |") |
| 108 | + | join("\n") |
| 109 | + ) |
| 110 | + + "\n\n</details>\n" |
| 111 | + end |
| 112 | + JQ |
| 113 | + jq -r -f sbom_to_summary.jq sbom.spdx.json >> "$GITHUB_STEP_SUMMARY" |
| 114 | +
|
| 115 | + - name: Upload SBOM to release |
| 116 | + if: ${{ github.event.release.tag_name }} |
| 117 | + |
| 118 | + with: |
| 119 | + file: sbom.spdx.json |
| 120 | + asset_name: sbom-${{ github.event.release.tag_name }} |
| 121 | + tag: ${{ github.ref }} |
| 122 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments