@@ -205,7 +205,7 @@ jobs:
205205 | sbom-utility patch --patch-file ./configuration/patch_supplier.json --quiet --input-file - \
206206 | sbom-utility patch --patch-file ./configuration/patch_complete.json --quiet --input-file - --output-file sbom_"$VERSION".json
207207 sbom-utility validate --input-file sbom_"$VERSION".json
208- -
208+ -
209209 name : Commit SBOMs
210210 uses : stefanzweifel/git-auto-commit-action@b863ae1933cb653a53c021fe36dbb774e1fb9403 # v5
211211 with :
@@ -214,3 +214,95 @@ jobs:
214214 commit_message : " chore: generate SBOMs for release ${{ github.event.inputs.release }}"
215215 branch : " chore/sboms_release_${{ github.event.inputs.release }}"
216216 file_pattern : " sbom/sbom*.json"
217+ -
218+ name : Merge SBOM branch into main and delete branch
219+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
220+ env :
221+ VERSION : ${{ github.event.inputs.release }}
222+ with :
223+ github-token : ${{ secrets.GITHUB_TOKEN }}
224+ script : |
225+ const sbomBranch = `chore/sboms_release_${process.env.VERSION}`;
226+ const targetBranch = 'main';
227+
228+ console.log(`Merging branch ${sbomBranch} into ${targetBranch}`);
229+
230+ try {
231+ // Merge the SBOM branch into main
232+ await github.rest.repos.merge({
233+ owner: context.repo.owner,
234+ repo: context.repo.repo,
235+ base: targetBranch,
236+ head: sbomBranch,
237+ commit_message: `chore: merge SBOM files for release ${process.env.VERSION}`
238+ });
239+
240+ console.log(`Successfully merged ${sbomBranch} into ${targetBranch}`);
241+
242+ // Delete the SBOM branch after successful merge
243+ console.log(`Deleting branch ${sbomBranch}`);
244+ await github.rest.git.deleteRef({
245+ owner: context.repo.owner,
246+ repo: context.repo.repo,
247+ ref: `heads/${sbomBranch}`
248+ });
249+
250+ console.log(`Successfully deleted branch ${sbomBranch}`);
251+ } catch (error) {
252+ console.error(`Error during merge or branch deletion: ${error.message}`);
253+ core.setFailed(error.message);
254+ }
255+ -
256+ name : Add SBOMs to GitHub Release
257+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
258+ env :
259+ VERSION : ${{ github.event.inputs.release }}
260+ with :
261+ github-token : ${{ secrets.GITHUB_TOKEN }}
262+ script : |
263+ const fs = require('fs');
264+ const path = require('path');
265+ const version = process.env.VERSION;
266+ const releaseTag = `v${version}`;
267+
268+ console.log(`Adding SBOMs to GitHub release ${releaseTag}`);
269+
270+ try {
271+ // Get the release by tag
272+ const { data: release } = await github.rest.repos.getReleaseByTag({
273+ owner: context.repo.owner,
274+ repo: context.repo.repo,
275+ tag: releaseTag
276+ });
277+
278+ // SBOM files to upload
279+ const sbomFiles = [
280+ `sbom_backend_application_${version}.json`,
281+ `sbom_frontend_application_${version}.json`,
282+ `sbom_backend_container_${version}.json`,
283+ `sbom_frontend_container_${version}.json`,
284+ `sbom_${version}.json`
285+ ];
286+
287+ // Upload each SBOM file to the release
288+ for (const file of sbomFiles) {
289+ const filePath = path.join('./sbom', file);
290+
291+ console.log(`Uploading ${filePath} to release ${releaseTag}`);
292+
293+ const fileContent = fs.readFileSync(filePath);
294+
295+ await github.rest.repos.uploadReleaseAsset({
296+ owner: context.repo.owner,
297+ repo: context.repo.repo,
298+ release_id: release.id,
299+ name: file,
300+ data: fileContent
301+ });
302+
303+ console.log(`Successfully uploaded ${file} to release ${releaseTag}`);
304+ }
305+ } catch (error) {
306+ console.error(`Error adding SBOMs to release: ${error.message}`);
307+ core.setFailed(error.message);
308+ }
0 commit comments