-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add publishing CLI events support python (#123)
* feat: add publishing CLI events * feat: update for testing * feat: update
- Loading branch information
1 parent
9b0f991
commit f86aa1a
Showing
7 changed files
with
147 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package actions | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
config "github.com/speakeasy-api/sdk-gen-config" | ||
"github.com/speakeasy-api/sdk-generation-action/internal/telemetry" | ||
"github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/shared" | ||
) | ||
|
||
func PublishEvent() error { | ||
return telemetry.Track(context.Background(), shared.InteractionTypePublish, func(ctx context.Context, event *shared.CliEvent) error { | ||
registryName := os.Getenv("INPUT_REGISTRY_NAME") | ||
if registryName != "" { | ||
event.PublishPackageRegistryName = ®istryName | ||
fmt.Println("REGISTRY NAME") | ||
fmt.Println(registryName) | ||
} | ||
|
||
workingDir, err := os.Getwd() // in publishing working dir is the SDK output directory | ||
if err != nil { | ||
return err | ||
} | ||
|
||
loadedCfg, err := config.Load(workingDir) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if loadedCfg.LockFile == nil { | ||
return fmt.Errorf("empty lock file for python language target in directory %s", workingDir) | ||
} | ||
|
||
version := processLockFile(*loadedCfg.LockFile, event) | ||
|
||
var processingErr error | ||
switch os.Getenv("INPUT_REGISTRY_NAME") { | ||
case "pypy": | ||
processingErr = processPyPI(loadedCfg, event, workingDir, version) | ||
} | ||
|
||
if processingErr != nil { | ||
return processingErr | ||
} | ||
|
||
if !strings.Contains(strings.ToLower(os.Getenv("GH_ACTION_RESULT")), "success") { | ||
return fmt.Errorf("failure in publishing: %s", os.Getenv("GH_ACTION_RESULT")) | ||
} | ||
|
||
return nil | ||
}) | ||
} | ||
|
||
func processPyPI(cfg *config.Config, event *shared.CliEvent, workingDir string, version string) error { | ||
if cfg.Config == nil { | ||
return fmt.Errorf("empty config for python language target in directory %s", workingDir) | ||
} | ||
|
||
langCfg, ok := cfg.Config.Languages["python"] | ||
if !ok { | ||
return fmt.Errorf("no python config in directory %s", workingDir) | ||
} | ||
|
||
var packageName string | ||
if name, ok := langCfg.Cfg["packageName"]; ok { | ||
if strName, ok := name.(string); ok { | ||
packageName = strName | ||
} | ||
} | ||
|
||
if packageName != "" { | ||
event.PublishPackageName = &packageName | ||
fmt.Println("PACKAGE NAME") | ||
fmt.Println(packageName) | ||
} | ||
|
||
if packageName != "" && version != "" { | ||
publishURL := fmt.Sprintf("https://pypi.org/project/%s/%s/", packageName, version) | ||
event.PublishPackageURL = &publishURL | ||
fmt.Println("PUBLISH URL") | ||
fmt.Println(publishURL) | ||
} | ||
|
||
return nil | ||
|
||
} | ||
|
||
func processLockFile(lockFile config.LockFile, event *shared.CliEvent) string { | ||
if lockFile.ID != "" { | ||
event.GenerateGenLockID = &lockFile.ID | ||
fmt.Println("Lock File ID") | ||
fmt.Println(lockFile.ID) | ||
} | ||
|
||
if lockFile.Management.ReleaseVersion != "" { | ||
event.PublishPackageVersion = &lockFile.Management.ReleaseVersion | ||
fmt.Println("RELEASE VERSION") | ||
fmt.Println(lockFile.Management.ReleaseVersion) | ||
} | ||
|
||
if lockFile.Management.SpeakeasyVersion != "" { | ||
event.SpeakeasyVersion = lockFile.Management.SpeakeasyVersion | ||
} | ||
|
||
return lockFile.Management.SpeakeasyVersion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters