Repository: diggerhq/digger
Pull request #170 (2023-04-26 01:58:12)

chore: don't post comments regarding executed workflow commands
From testing, I found that posting comments regarding every executed workflow custom command with their output would clutter the PR in general and make it less readable. Proposing to only log this content and only post comments regarding `terraform plan/apply` output content and locks being acquired/released instead by default.

For example

![image](https://user-images.githubusercontent.com/17277004/234446266-cbf37b8e-8515-4e22-b04e-c208a50cb012.png)



Patch:
diff --git a/action.yml b/action.yml
index 72773a27..1704c533 100644
--- a/action.yml
+++ b/action.yml
@@ -3,10 +3,6 @@ description: Manage terraform collaboration
 author: Digger
 
 inputs:
-  workspace:
-    description: Name of the terraform workspace
-    required: false
-    default: default
   setup-aws:
     description: Setup AWS
     required: false
@@ -163,7 +159,7 @@ runs:
       uses: actions/upload-artifact@v3
       with:
           name: ${{ steps.artifact.outputs.artifact }}
-          path: '*.tfplan'
+          path: '${{ github.workspace }}/**/*.tfplan'
           retention-days: 14
 
 branding:
diff --git a/pkg/configuration/digger_config.go b/pkg/configuration/digger_config.go
index 83bddedc..fa54583b 100644
--- a/pkg/configuration/digger_config.go
+++ b/pkg/configuration/digger_config.go
@@ -199,6 +199,15 @@ func ConvertDiggerYamlToConfig(diggerYaml *DiggerConfigYaml, workingDir string,
 		}
 	}
 
+	projectNames := make(map[string]bool)
+
+	for _, project := range diggerConfig.Projects {
+		if projectNames[project.Name] {
+			return nil, fmt.Errorf("project name '%s' is duplicated", project.Name)
+		}
+		projectNames[project.Name] = true
+	}
+
 	return &diggerConfig, nil
 }
 
diff --git a/pkg/digger/digger.go b/pkg/digger/digger.go
index b0405022..edf2fd25 100644
--- a/pkg/digger/digger.go
+++ b/pkg/digger/digger.go
@@ -375,8 +375,7 @@ func (d DiggerExecutor) Plan(prNumber int) error {
 			}
 			if step.Action == "run" {
 				stdout, stderr, err := d.commandRunner.Run(step.Value)
-				comment := "Running " + step.Value + " for **" + d.lock.LockId() + "**\n" + stdout + stderr
-				d.prManager.PublishComment(prNumber, comment)
+				log.Printf("Running %v for **%v**\n%v%v", step.Value, d.lock.LockId(), stdout, stderr)
 				if err != nil {
 					return fmt.Errorf("error running command: %v", err)
 				}
@@ -456,8 +455,7 @@ func (d DiggerExecutor) Apply(prNumber int) error {
 				}
 				if step.Action == "run" {
 					stdout, stderr, err := d.commandRunner.Run(step.Value)
-					comment := "Running " + step.Value + " for **" + d.lock.LockId() + "**\n" + stdout + stderr
-					d.prManager.PublishComment(prNumber, comment)
+					log.Printf("Running %v for **%v**\n%v%v", step.Value, d.lock.LockId(), stdout, stderr)
 					if err != nil {
 						return fmt.Errorf("error running command: %v", err)
 					}
diff --git a/pkg/utils/io.go b/pkg/utils/io.go
index 52c3cc5b..d33fe212 100644
--- a/pkg/utils/io.go
+++ b/pkg/utils/io.go
@@ -5,6 +5,7 @@ import (
 	"bytes"
 	"io"
 	"io/ioutil"
+	"strings"
 )
 
 type Zip interface {
@@ -20,12 +21,12 @@ func (z *Zipper) GetFileFromZip(zipFile string, filename string) (string, error)
 		return "", err
 	}
 	defer reader.Close()
-
 	for _, file := range reader.File {
 		if file.FileInfo().IsDir() {
 			continue
 		}
-		if file.Name == filename {
+
+		if strings.HasSuffix(file.Name, filename) {
 			rc, err := file.Open()
 			if err != nil {
 				return "", err


Test patch:
diff --git a/pkg/digger/digger_test.go b/pkg/digger/digger_test.go
index b1ba052b..f49fc58b 100644
--- a/pkg/digger/digger_test.go
+++ b/pkg/digger/digger_test.go
@@ -2,12 +2,13 @@ package digger
 
 import (
 	"digger/pkg/configuration"
-	"github.com/stretchr/testify/assert"
 	"sort"
 	"strconv"
 	"strings"
 	"testing"
 	"time"
+
+	"github.com/stretchr/testify/assert"
 )
 
 type RunInfo struct {
@@ -155,7 +156,7 @@ func TestCorrectCommandExecutionWhenApplying(t *testing.T) {
 
 	commandStrings := allCommandsInOrderWithParams(terraformExecutor, commandRunner, prManager, lock)
 
-	assert.Equal(t, []string{"DownloadLatestPlans 1", "IsMergeable 1", "Lock 1", "Init ", "Apply  plan", "LockId ", "PublishComment 1 Apply for ****\n```terraform\n\n```", "Unlock 1", "Run echo", "LockId ", "PublishComment 1 Running echo for ****\n"}, commandStrings)
+	assert.Equal(t, []string{"DownloadLatestPlans 1", "IsMergeable 1", "Lock 1", "Init ", "Apply  plan", "LockId ", "PublishComment 1 Apply for ****\n```terraform\n\n```", "Unlock 1", "Run echo", "LockId "}, commandStrings)
 }
 
 func TestCorrectCommandExecutionWhenPlanning(t *testing.T) {
@@ -196,7 +197,7 @@ func TestCorrectCommandExecutionWhenPlanning(t *testing.T) {
 
 	commandStrings := allCommandsInOrderWithParams(terraformExecutor, commandRunner, prManager, lock)
 
-	assert.Equal(t, []string{"Lock 1", "Init ", "Plan -out .tfplan", "LockId ", "PublishComment 1 Plan for ****\n```terraform\n\n```", "Run echo", "LockId ", "PublishComment 1 Running echo for ****\n"}, commandStrings)
+	assert.Equal(t, []string{"Lock 1", "Init ", "Plan -out .tfplan", "LockId ", "PublishComment 1 Plan for ****\n```terraform\n\n```", "Run echo", "LockId "}, commandStrings)
 }
 
 func allCommandsInOrderWithParams(terraformExecutor *MockTerraformExecutor, commandRunner *MockCommandRunner, prManager *MockPRManager, lock *MockProjectLock) []string {