Skip to content
Merged
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
39 changes: 39 additions & 0 deletions dagger/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func (r *Replicated) Release(

githubToken *dagger.Secret,
) error {
// Check all required environment variables / secrets before starting work
if err := validateReleaseSecrets(ctx, githubToken, onePasswordServiceAccountProduction); err != nil {
return err
}

err := checkGitTree(ctx, source, githubToken)
if err != nil {
return errors.Wrap(err, "failed to check git tree")
Expand Down Expand Up @@ -213,6 +218,40 @@ func (r *Replicated) Release(
return nil
}

func validateReleaseSecrets(ctx context.Context, githubToken, onePasswordServiceAccountProduction *dagger.Secret) error {
var missing []string

if githubToken == nil {
missing = append(missing, "GITHUB_TOKEN")
} else {
gt, err := githubToken.Plaintext(ctx)
if err != nil {
return errors.Wrap(err, "failed to read GITHUB_TOKEN secret")
}
if strings.TrimSpace(gt) == "" {
missing = append(missing, "GITHUB_TOKEN")
}
}

if onePasswordServiceAccountProduction == nil {
missing = append(missing, "OP_SERVICE_ACCOUNT_PRODUCTION")
} else {
op, err := onePasswordServiceAccountProduction.Plaintext(ctx)
if err != nil {
return errors.Wrap(err, "failed to read OP_SERVICE_ACCOUNT_PRODUCTION secret")
}
if strings.TrimSpace(op) == "" {
missing = append(missing, "OP_SERVICE_ACCOUNT_PRODUCTION")
}
}

if len(missing) > 0 {
return fmt.Errorf("required environment variables are not set: %s", strings.Join(missing, ", "))
}

return nil
}

func getNextVersion(ctx context.Context, latestVersion string, version string) (int64, int64, int64, error) {
parsedLatestVersion, err := semver.NewVersion(latestVersion)
if err != nil {
Expand Down
Loading