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

Add support for Google Cloud Storage #21

Merged
merged 8 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ inputs:
description: "Container name to save the workflow logs to. Required if destination is 'blobstorage'."
blob-name:
description: "Blob name to save the workflow logs as. Required if destination is 'blobstorage'."
cloud-storage-bucket-name:
description: "Cloud Storage Bucket name to save the workflow logs to. Required if destination is 'cloudstorage'."
cloud-storage-object-name:
description: "Cloud Storage object name to save the workflow logs as. Required if destination is 'cloudstorage'."

runs:
using: "docker"
Expand All @@ -53,3 +57,5 @@ runs:
- --azure-storage-account-key=${{ inputs.azure-storage-account-key }}
- --container-name=${{ inputs.container-name }}
- --blob-name=${{ inputs.blob-name }}
- --cloud-storage-bucket-name=${{ inputs.cloud-storage-bucket-name }}
- --cloud-storage-object-name=${{ inputs.cloud-storage-object-name }}
47 changes: 37 additions & 10 deletions action_inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ var (
inputBlobName *string = flag.String(inputKeyBlobName, "", "Azure blob name")
)

// Inputs for Google Cloud Storage
var (
inputCloudStorageBucketName *string = flag.String(inputKeyCloudStorageBucketName, "", "Google Cloud Storage bucket name")
inputCloudStorageObjectName *string = flag.String(inputKeyCloudStorageObjectName, "", "Google Cloud Storage object name")
)

// S3ActionInputs contains inputs used for the `s3` destination
type S3ActionInputs struct {
awsAccessKeyID string
Expand All @@ -52,14 +58,21 @@ type BlobStorageActionInputs struct {
blobName string
}

// CloudStorageActionInputs contains inputs required for the `cloudstorage` destination
type CloudStorageActionInputs struct {
bucketName string
objectName string
}

// ActionInputs contains all the pertinent inputs for this GitHub Action. For a given destination, its corresponding
// struct field (e.g. s3Inputs for the `s3` destination) is assumed to be non-nil.
type ActionInputs struct {
repoToken string
workflowRunID int64
destination string
s3Inputs *S3ActionInputs
blobStorageInputs *BlobStorageActionInputs
repoToken string
workflowRunID int64
destination string
s3Inputs *S3ActionInputs
blobStorageInputs *BlobStorageActionInputs
cloudStorageInputs *CloudStorageActionInputs
}

// validateActionInputs validates input combinations that cannot be checked at the action-level.
Expand All @@ -84,6 +97,7 @@ func validateActionInputs() (ActionInputs, error) {
var inputFlagsToAssertNotEmpty map[string]string
var s3Inputs *S3ActionInputs
var blobStorageInputs *BlobStorageActionInputs
var cloudStorageInputs *CloudStorageActionInputs

if matchedDestination == amazonS3Destination {
log.Debug().Msg("Validating Action inputs for S3")
Expand Down Expand Up @@ -120,6 +134,18 @@ func validateActionInputs() (ActionInputs, error) {
}
}

if matchedDestination == googleCloudStorageDestination {
log.Debug().Msg("Validating Action inputs for Cloud Storage")
cloudStorageInputs = &CloudStorageActionInputs{
bucketName: *inputCloudStorageBucketName,
objectName: *inputCloudStorageObjectName,
}
inputFlagsToAssertNotEmpty = map[string]string{
inputKeyCloudStorageBucketName: *inputCloudStorageBucketName,
inputKeyCloudStorageObjectName: *inputCloudStorageObjectName,
}
}

var emptyInputs []string
for inputName, inputValue := range inputFlagsToAssertNotEmpty {
if len(inputValue) == 0 {
Expand All @@ -133,10 +159,11 @@ func validateActionInputs() (ActionInputs, error) {

log.Debug().Msg("Action input validation was successful")
return ActionInputs{
repoToken: *inputRepoToken,
workflowRunID: *inputWorkflowRunID,
destination: matchedDestination,
s3Inputs: s3Inputs,
blobStorageInputs: blobStorageInputs,
repoToken: *inputRepoToken,
workflowRunID: *inputWorkflowRunID,
destination: matchedDestination,
s3Inputs: s3Inputs,
blobStorageInputs: blobStorageInputs,
cloudStorageInputs: cloudStorageInputs,
}, nil
}
32 changes: 32 additions & 0 deletions action_inputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,38 @@ func TestValidateActionInputs(t *testing.T) {
wantResult: ActionInputs{},
wantError: fmt.Sprintf("the following inputs are required: %s", inputKeyAzureStorageAccountKey),
},
{
desc: "Cloud Storage destination success case",
shouldSucceed: true,
inputValuesByKey: map[string]string{
inputKeyDestination: "cloudstorage",
inputKeyCloudStorageBucketName: "bucket999",
inputKeyCloudStorageObjectName: "object222",
},
wantResult: ActionInputs{
repoToken: "testRepoToken",
workflowRunID: 123,
destination: "cloudstorage",
s3Inputs: nil,
blobStorageInputs: nil,
cloudStorageInputs: &CloudStorageActionInputs{
bucketName: "bucket999",
objectName: "object222",
},
},
wantError: "",
},
{
desc: "Cloud Storage destination failure case",
shouldSucceed: false,
inputValuesByKey: map[string]string{
inputKeyDestination: "cloudstorage",
inputKeyCloudStorageBucketName: "bucket999",
// inputKeyCloudStorageObjectName intentionally excluded
},
wantResult: ActionInputs{},
wantError: fmt.Sprintf("the following inputs are required: %s", inputKeyCloudStorageObjectName),
},
}

for _, tC := range testCases {
Expand Down
15 changes: 11 additions & 4 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,20 @@ const (
inputKeyBlobName string = "blob-name"
)

// Google Cloud Storage Action Inputs
const (
inputKeyCloudStorageBucketName string = "cloud-storage-bucket-name"
inputKeyCloudStorageObjectName string = "cloud-storage-object-name"
)

// Misc constants
const (
amazonS3Destination string = "s3"
azureBlobStorageDestination string = "blobstorage"
githubDefaultBaseURL string = "https://github.com"
amazonS3Destination string = "s3"
azureBlobStorageDestination string = "blobstorage"
googleCloudStorageDestination string = "cloudstorage"
githubDefaultBaseURL string = "https://github.com"
)

var (
supportedDestinations = []string{amazonS3Destination, azureBlobStorageDestination}
supportedDestinations = []string{amazonS3Destination, azureBlobStorageDestination, googleCloudStorageDestination}
)
46 changes: 36 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ module github.com/timorthi/export-workflow-logs
go 1.19

require (
cloud.google.com/go/storage v1.40.0
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.6.1
github.com/aws/aws-sdk-go-v2/config v1.18.7
github.com/aws/aws-sdk-go-v2/service/s3 v1.29.6
github.com/google/go-github/v48 v48.2.0
github.com/migueleliasweb/go-github-mock v0.0.13
github.com/rs/zerolog v1.28.0
github.com/stretchr/testify v1.7.1
golang.org/x/oauth2 v0.3.0
github.com/stretchr/testify v1.8.4
golang.org/x/oauth2 v0.18.0
)

require (
cloud.google.com/go v0.112.1 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.7 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.4 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.1 // indirect
Expand All @@ -34,18 +39,39 @@ require (
github.com/aws/aws-sdk-go-v2/service/sts v1.17.7 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-github/v41 v41.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 // indirect
golang.org/x/net v0.3.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.170.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240311132316-a219d84964c2 // indirect
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading