Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converts the diff actions to use files to avoid hit bash command length limit #1000

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions actions/stack/diff-package-receipts/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ inputs:
current:
description: 'Path to current package receipt'
required: true

outputs:
added:
added_diff_file:
description: 'List of packages added'
removed:
required: true
removed_diff_file:
description: 'List of packages removed'
modified:
required: true
modified_diff_file:
description: 'List of packages modified'
required: true

runs:
using: 'docker'
Expand All @@ -25,3 +26,9 @@ runs:
- "${{ inputs.previous }}"
- "--current"
- "${{ inputs.current }}"
- "--added-diff-file"
- "${{ inputs.added_diff_file }}"
- "--removed-diff-file"
- "${{ inputs.removed_diff_file }}"
- "--modified-diff-file"
- "${{ inputs.modified_diff_file }}"
84 changes: 60 additions & 24 deletions actions/stack/diff-package-receipts/entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ type ModifiedCycloneDXComponent struct {

func main() {
var config struct {
CurrentPath string
PreviousPath string
CurrentPath string
PreviousPath string
AddedDiffFilePath string
RemovedDiffFilePath string
ModifiedDiffFilePath string
}

flag.StringVar(&config.PreviousPath,
Expand All @@ -43,12 +46,31 @@ func main() {
"",
"Path to current package receipt")

flag.StringVar(&config.AddedDiffFilePath,
"added-diff-file",
"",
"List of packages added")

flag.StringVar(&config.RemovedDiffFilePath,
"removed-diff-file",
"",
"List of packages removed")

flag.StringVar(&config.ModifiedDiffFilePath,
"modified-diff-file",
"",
"List of packages modified")

flag.Parse()

if config.CurrentPath == "" || config.PreviousPath == "" {
log.Fatal("Must provide current and previous paths")
}

if config.AddedDiffFilePath == "" || config.RemovedDiffFilePath == "" || config.ModifiedDiffFilePath == "" {
log.Fatal("Must provide diff file paths")
}

absolute, err := filepath.Abs(config.CurrentPath)
if err != nil {
log.Fatalf("Failed to create absolute path for %s", config.CurrentPath)
Expand All @@ -61,6 +83,24 @@ func main() {
}
config.PreviousPath = absolute

absolute, err = filepath.Abs(config.AddedDiffFilePath)
if err != nil {
log.Fatalf("Failed to create absolute path for %s", config.AddedDiffFilePath)
}
config.AddedDiffFilePath = absolute

absolute, err = filepath.Abs(config.RemovedDiffFilePath)
if err != nil {
log.Fatalf("Failed to create absolute path for %s", config.RemovedDiffFilePath)
}
config.RemovedDiffFilePath = absolute

absolute, err = filepath.Abs(config.ModifiedDiffFilePath)
if err != nil {
log.Fatalf("Failed to create absolute path for %s", config.ModifiedDiffFilePath)
}
config.ModifiedDiffFilePath = absolute

previous, err := parsePackagesFromFile(config.PreviousPath)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -99,28 +139,37 @@ func main() {
}
}

addedJSON, err := json.Marshal(added)
addedFile, err := os.OpenFile(config.AddedDiffFilePath, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
log.Fatal(err)
}
if len(added) == 0 {
addedJSON = []byte(`[]`)
defer addedFile.Close()

err = json.NewEncoder(addedFile).Encode(&added)
if err != nil {
log.Fatal(err)
}

removedJSON, err := json.Marshal(removed)
removedFile, err := os.OpenFile(config.RemovedDiffFilePath, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
log.Fatal(err)
}
if len(removed) == 0 {
removedJSON = []byte(`[]`)
defer removedFile.Close()

err = json.NewEncoder(removedFile).Encode(&removed)
if err != nil {
log.Fatal(err)
}

modifiedJSON, err := json.Marshal(modified)
modifiedFile, err := os.OpenFile(config.ModifiedDiffFilePath, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
log.Fatal(err)
}
if len(modified) == 0 {
modifiedJSON = []byte(`[]`)
defer modifiedFile.Close()

err = json.NewEncoder(modifiedFile).Encode(&modified)
if err != nil {
log.Fatal(err)
}

fmt.Println("Added packages:")
Expand All @@ -141,19 +190,6 @@ func main() {
pkg.CurrentPURL,
)
}

outputFileName, ok := os.LookupEnv("GITHUB_OUTPUT")
if !ok {
log.Fatal("GITHUB_OUTPUT is not set, see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter")
}
file, err := os.OpenFile(outputFileName, os.O_APPEND|os.O_WRONLY, 0)
if err != nil {
log.Fatal(err)
}
defer file.Close()
fmt.Fprintf(file, "added=%s\n", string(addedJSON))
fmt.Fprintf(file, "removed=%s\n", string(removedJSON))
fmt.Fprintf(file, "modified=%s\n", string(modifiedJSON))
}

func parsePackagesFromFile(path string) (map[string]CycloneDXComponent, error) {
Expand Down
12 changes: 6 additions & 6 deletions actions/stack/release-notes/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ inputs:
description: 'CVE scan report path of run image in markdown format'
required: false
build_packages_added:
description: 'JSON array of packages added "{ name: name, version: 1.2.3 }"'
description: 'Path to build packages added file'
robdimsdale marked this conversation as resolved.
Show resolved Hide resolved
required: false
build_packages_modified:
description: 'JSON array of packages modified "{ name: name, previousVersion: 1.2.3, currentVersion: 1.2.4 }"'
description: 'Path to build packages modified file'
required: false
build_packages_removed_with_force:
description: 'JSON array of packages removed with user-provided force "{ name: name, version: 1.2.3}"'
description: 'Path to build packages removed file'
required: false
run_packages_added:
description: 'JSON array of packages added "{ name: name, version: 1.2.3 }"'
description: 'Path to run packages added file'
required: false
run_packages_modified:
description: 'JSON array of packages modified "{ name: name, previousVersion: 1.2.3, currentVersion: 1.2.4 }"'
description: 'Path to run packages modified file'
required: false
run_packages_removed_with_force:
description: 'JSON array of packages removed with user-provided force "{ name: name, version: 1.2.3}"'
description: 'Path to run packages removed file'
required: false
patched_usns:
description: 'JSON array of objects "{ name: USN name, url: USN URL, description: USN description}"'
Expand Down
87 changes: 80 additions & 7 deletions actions/stack/release-notes/entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"strconv"
"text/template"
)
Expand Down Expand Up @@ -69,6 +70,42 @@ func main() {
flag.StringVar(&config.ReceiptsShowLimit, "receipts-show-limit", "", "Integer which defines the limit of whether it should show or not the receipts array of each image")
flag.Parse()

absolute, err := filepath.Abs(config.BuildPackagesAddedJSON)
if err != nil {
log.Fatalf("Failed to create absolute path for %s", config.BuildPackagesAddedJSON)
}
config.BuildPackagesAddedJSON = absolute

absolute, err = filepath.Abs(config.BuildPackagesModifiedJSON)
if err != nil {
log.Fatalf("Failed to create absolute path for %s", config.BuildPackagesModifiedJSON)
}
config.BuildPackagesModifiedJSON = absolute

absolute, err = filepath.Abs(config.BuildPackagesRemovedJSON)
if err != nil {
log.Fatalf("Failed to create absolute path for %s", config.BuildPackagesRemovedJSON)
}
config.BuildPackagesRemovedJSON = absolute

absolute, err = filepath.Abs(config.RunPackagesAddedJSON)
if err != nil {
log.Fatalf("Failed to create absolute path for %s", config.RunPackagesAddedJSON)
}
config.RunPackagesAddedJSON = absolute

absolute, err = filepath.Abs(config.RunPackagesModifiedJSON)
if err != nil {
log.Fatalf("Failed to create absolute path for %s", config.RunPackagesModifiedJSON)
}
config.RunPackagesModifiedJSON = absolute

absolute, err = filepath.Abs(config.RunPackagesRemovedJSON)
if err != nil {
log.Fatalf("Failed to create absolute path for %s", config.RunPackagesRemovedJSON)
}
config.RunPackagesRemovedJSON = absolute

var contents struct {
PatchedArray []USN
SupportsUsns bool
Expand All @@ -85,7 +122,7 @@ func main() {
ReceiptsShowLimit int
}

err := json.Unmarshal([]byte(fixEmptyArray(config.PatchedJSON)), &contents.PatchedArray)
err = json.Unmarshal([]byte(fixEmptyArray(config.PatchedJSON)), &contents.PatchedArray)
if err != nil {
log.Fatalf("failed unmarshalling patched USNs: %s", err.Error())
}
Expand All @@ -99,32 +136,68 @@ func main() {
}
}

err = json.Unmarshal([]byte(fixEmptyArray(config.BuildPackagesAddedJSON)), &contents.BuildAdded)
buildAddedFile, err := os.Open(config.BuildPackagesAddedJSON)
if err != nil {
log.Fatal(err)
}
defer buildAddedFile.Close()

err = json.NewDecoder(buildAddedFile).Decode(&contents.BuildAdded)
if err != nil {
log.Fatalf("failed unmarshalling build packages added: %s", err.Error())
}

err = json.Unmarshal([]byte(fixEmptyArray(config.BuildPackagesModifiedJSON)), &contents.BuildModified)
buildModifiedFile, err := os.Open(config.BuildPackagesModifiedJSON)
if err != nil {
log.Fatal(err)
}
defer buildModifiedFile.Close()

err = json.NewDecoder(buildModifiedFile).Decode(&contents.BuildModified)
if err != nil {
log.Fatalf("failed unmarshalling build packages modified: %s", err.Error())
}

err = json.Unmarshal([]byte(fixEmptyArray(config.BuildPackagesRemovedJSON)), &contents.BuildRemoved)
buildRemovedFile, err := os.Open(config.BuildPackagesRemovedJSON)
if err != nil {
log.Fatal(err)
}
defer buildRemovedFile.Close()

err = json.NewDecoder(buildRemovedFile).Decode(&contents.BuildRemoved)
if err != nil {
log.Fatalf("failed unmarshalling build packages removed: %s", err.Error())
}

err = json.Unmarshal([]byte(fixEmptyArray(config.RunPackagesAddedJSON)), &contents.RunAdded)
runAddedFile, err := os.Open(config.RunPackagesAddedJSON)
if err != nil {
log.Fatal(err)
}
defer runAddedFile.Close()

err = json.NewDecoder(runAddedFile).Decode(&contents.RunAdded)
if err != nil {
log.Fatalf("failed unmarshalling run packages added: %s", err.Error())
}

err = json.Unmarshal([]byte(fixEmptyArray(config.RunPackagesModifiedJSON)), &contents.RunModified)
runModifiedFile, err := os.Open(config.RunPackagesModifiedJSON)
if err != nil {
log.Fatal(err)
}
defer runModifiedFile.Close()

err = json.NewDecoder(runModifiedFile).Decode(&contents.RunModified)
if err != nil {
log.Fatalf("failed unmarshalling run packages modified: %s", err.Error())
}

err = json.Unmarshal([]byte(fixEmptyArray(config.RunPackagesRemovedJSON)), &contents.RunRemoved)
runRemovedFile, err := os.Open(config.RunPackagesRemovedJSON)
if err != nil {
log.Fatal(err)
}
defer runRemovedFile.Close()

err = json.NewDecoder(runRemovedFile).Decode(&contents.RunRemoved)
if err != nil {
log.Fatalf("failed unmarshalling run packages removed: %s", err.Error())
}
Expand Down
Loading
Loading