|
| 1 | +name: Release and Upload SBOM to Balena |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | +env: |
| 10 | + FLEET_SLUG: org3/test |
| 11 | + |
| 12 | +jobs: |
| 13 | + build-and-release: |
| 14 | + if: github.event.pull_request.merged == true |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Set up Node.js |
| 21 | + uses: actions/setup-node@v4 |
| 22 | + with: |
| 23 | + node-version: '20' |
| 24 | + cache: 'npm' |
| 25 | + |
| 26 | + - name: Install dependencies |
| 27 | + run: npm ci |
| 28 | + |
| 29 | + - name: Generate SBOM using Syft |
| 30 | + run: | |
| 31 | + # Install Syft for SBOM generation |
| 32 | + curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /tmp |
| 33 | + |
| 34 | + # Generate SBOM in multiple formats |
| 35 | + echo "Generating SBOM in SPDX JSON format..." |
| 36 | + /tmp/syft . -o spdx-json=sbom-spdx.json |
| 37 | + |
| 38 | + echo "Generating SBOM in CycloneDX JSON format..." |
| 39 | + /tmp/syft . -o cyclonedx-json=sbom-cyclonedx.json |
| 40 | + |
| 41 | + echo "Generating SBOM in Syft JSON format..." |
| 42 | + /tmp/syft . -o syft-json=sbom-syft.json |
| 43 | + |
| 44 | + # Create a tarball of all SBOMs |
| 45 | + tar -czf sboms.tar.gz sbom-*.json |
| 46 | + |
| 47 | + echo "SBOM files generated:" |
| 48 | + ls -la sbom-*.json sboms.tar.gz |
| 49 | +
|
| 50 | + - name: balena CLI Action |
| 51 | + uses: balena-io-experimental/[email protected] |
| 52 | + with: |
| 53 | + balena_token: ${{secrets.BALENA_API_TOKEN}} |
| 54 | + |
| 55 | + - name: Create Balena Release |
| 56 | + id: create-release |
| 57 | + run: | |
| 58 | + # Push to Balena and create a release |
| 59 | + echo "Creating release for fleet: ${{ env.FLEET_SLUG }}" |
| 60 | + |
| 61 | + # Build and push the release |
| 62 | + balena push ${{ env.FLEET_SLUG }} --release-tag version=${{ github.ref_name || 'latest' }} |
| 63 | + |
| 64 | + # Get the latest release ID |
| 65 | + RELEASE_ID=$(balena releases ${{ env.FLEET_SLUG }} --json | jq -r '.[0].id') |
| 66 | + echo "Release ID: $RELEASE_ID" |
| 67 | + echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT |
| 68 | + |
| 69 | +
|
| 70 | + - name: Upload All SBOM Assets |
| 71 | + uses: balena-io/upload-balena-release-asset@main |
| 72 | + with: |
| 73 | + balena-token: ${{ secrets.BALENA_API_TOKEN }} |
| 74 | + release-id: ${{ steps.create-release.outputs.release_id }} |
| 75 | + path: | |
| 76 | + sbom-spdx.json |
| 77 | + sbom-cyclonedx.json |
| 78 | + sbom-syft.json |
| 79 | + sboms.tar.gz |
0 commit comments