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