diff --git a/.github/workflows/sdk-publish.yaml b/.github/workflows/sdk-publish.yaml index b4965a2a..cf0e214b 100644 --- a/.github/workflows/sdk-publish.yaml +++ b/.github/workflows/sdk-publish.yaml @@ -183,6 +183,19 @@ jobs: env: NODE_AUTH_TOKEN: ${{ secrets.npm_token }} run: npm publish --access public + - id: publish-event + uses: speakeasy-api/sdk-generation-action@v15 + if: always() + with: + github_access_token: ${{ secrets.github_access_token }} + action: publish-event + speakeasy_api_key: ${{ secrets.speakeasy_api_key }} + speakeasy_server_url: ${{ inputs.speakeasy_server_url }} + target_directory: ${{ needs.release.outputs.typescript_directory }} + registry_name: "npm" + env: + GH_ACTION_RESULT: ${{ job.status }} + GH_ACTION_VERSION: "v15" - uses: ravsamhq/notify-slack-action@v2 if: always() && env.SLACK_WEBHOOK_URL != '' with: @@ -232,6 +245,16 @@ jobs: SONATYPE_PASSWORD: ${{ secrets.ossrh_password }} SONATYPE_SIGNING_KEY: ${{ secrets.java_gpg_secret_key }} SIGNING_KEY_PASSPHRASE: ${{ secrets.java_gpg_passphrase }} + - id: publish-event + uses: speakeasy-api/sdk-generation-action@v15 + if: always() + with: + github_access_token: ${{ secrets.github_access_token }} + action: publish-event + speakeasy_api_key: ${{ secrets.speakeasy_api_key }} + speakeasy_server_url: ${{ inputs.speakeasy_server_url }} + target_directory: ${{ needs.release.outputs.java_directory }} + registry_name: "sonatype" - uses: ravsamhq/notify-slack-action@v2 if: always() && env.SLACK_WEBHOOK_URL != '' with: @@ -261,6 +284,16 @@ jobs: api_token: ${{ secrets.packagist_token }} package_name: ${{ github.repository }} package_base_url: ${{ github.server_url }} + - id: publish-event + uses: speakeasy-api/sdk-generation-action@v15 + if: always() + with: + github_access_token: ${{ secrets.github_access_token }} + action: publish-event + speakeasy_api_key: ${{ secrets.speakeasy_api_key }} + speakeasy_server_url: ${{ inputs.speakeasy_server_url }} + target_directory: ${{ needs.release.outputs.php_directory }} + registry_name: "packagist" - uses: ravsamhq/notify-slack-action@v2 if: always() && env.SLACK_WEBHOOK_URL != '' with: @@ -290,6 +323,16 @@ jobs: dotnet-version: ${{ inputs.dotnet_version }} - name: Publish run: dotnet pack -o . && dotnet nuget push *.nupkg --api-key ${{ secrets.nuget_api_key }} --source https://api.nuget.org/v3/index.json + - id: publish-event + uses: speakeasy-api/sdk-generation-action@v15 + if: always() + with: + github_access_token: ${{ secrets.github_access_token }} + action: publish-event + speakeasy_api_key: ${{ secrets.speakeasy_api_key }} + speakeasy_server_url: ${{ inputs.speakeasy_server_url }} + target_directory: ${{ needs.release.outputs.csharp_directory }} + registry_name: "nuget" - uses: ravsamhq/notify-slack-action@v2 if: always() && env.SLACK_WEBHOOK_URL != '' with: @@ -329,6 +372,16 @@ jobs: speakeasy_server_url: ${{ inputs.speakeasy_server_url }} env: GITHUB_TOKEN: ${{ secrets.github_access_token }} + - id: publish-event + uses: speakeasy-api/sdk-generation-action@v15 + if: always() + with: + github_access_token: ${{ secrets.github_access_token }} + action: publish-event + speakeasy_api_key: ${{ secrets.speakeasy_api_key }} + speakeasy_server_url: ${{ inputs.speakeasy_server_url }} + target_directory: ${{ needs.release.outputs.publish_terraform }} + registry_name: "terraform" - uses: ravsamhq/notify-slack-action@v2 if: always() && env.SLACK_WEBHOOK_URL != '' with: @@ -368,6 +421,16 @@ jobs: printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials gem build *.gemspec gem push *.gem + - id: publish-event + uses: speakeasy-api/sdk-generation-action@v15 + if: always() + with: + github_access_token: ${{ secrets.github_access_token }} + action: publish-event + speakeasy_api_key: ${{ secrets.speakeasy_api_key }} + speakeasy_server_url: ${{ inputs.speakeasy_server_url }} + target_directory: ${{ needs.release.outputs.ruby_directory }} + registry_name: "gems" - uses: ravsamhq/notify-slack-action@v2 if: always() && env.SLACK_WEBHOOK_URL != '' with: diff --git a/.github/workflows/workflow-executor.yaml b/.github/workflows/workflow-executor.yaml index 59a00867..51798bd0 100644 --- a/.github/workflows/workflow-executor.yaml +++ b/.github/workflows/workflow-executor.yaml @@ -203,6 +203,16 @@ jobs: run: | python setup.py sdist bdist_wheel twine upload dist/* + - id: publish-event + uses: speakeasy-api/sdk-generation-action@v15 + if: always() + with: + github_access_token: ${{ secrets.github_access_token }} + action: publish-event + speakeasy_api_key: ${{ secrets.speakeasy_api_key }} + speakeasy_server_url: ${{ inputs.speakeasy_server_url }} + target_directory: ${{ needs.run-workflow.outputs.python_directory }} + registry_name: "pypi" - uses: ravsamhq/notify-slack-action@v2 if: always() && env.SLACK_WEBHOOK_URL != '' with: @@ -258,6 +268,16 @@ jobs: env: NODE_AUTH_TOKEN: ${{ secrets.npm_token }} run: npm publish --access public + - id: publish-event + uses: speakeasy-api/sdk-generation-action@v15 + if: always() + with: + github_access_token: ${{ secrets.github_access_token }} + action: publish-event + speakeasy_api_key: ${{ secrets.speakeasy_api_key }} + speakeasy_server_url: ${{ inputs.speakeasy_server_url }} + target_directory: ${{ needs.run-workflow.outputs.typescript_directory }} + registry_name: "npm" - uses: ravsamhq/notify-slack-action@v2 if: always() && env.SLACK_WEBHOOK_URL != '' with: @@ -329,6 +349,16 @@ jobs: SONATYPE_PASSWORD: ${{ secrets.ossrh_password }} SONATYPE_SIGNING_KEY: ${{ secrets.java_gpg_secret_key }} SIGNING_KEY_PASSPHRASE: ${{ secrets.java_gpg_passphrase }} + - id: publish-event + uses: speakeasy-api/sdk-generation-action@v15 + if: always() + with: + github_access_token: ${{ secrets.github_access_token }} + action: publish-event + speakeasy_api_key: ${{ secrets.speakeasy_api_key }} + speakeasy_server_url: ${{ inputs.speakeasy_server_url }} + target_directory: ${{ needs.run-workflow.outputs.java_directory }} + registry_name: "sonatype" - uses: ravsamhq/notify-slack-action@v2 if: always() && env.SLACK_WEBHOOK_URL != '' with: @@ -389,6 +419,16 @@ jobs: printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials gem build *.gemspec gem push *.gem + - id: publish-event + uses: speakeasy-api/sdk-generation-action@v15 + if: always() + with: + github_access_token: ${{ secrets.github_access_token }} + action: publish-event + speakeasy_api_key: ${{ secrets.speakeasy_api_key }} + speakeasy_server_url: ${{ inputs.speakeasy_server_url }} + target_directory: ${{ needs.run-workflow.outputs.ruby_directory }} + registry_name: "gems" - uses: ravsamhq/notify-slack-action@v2 if: always() && env.SLACK_WEBHOOK_URL != '' with: @@ -439,6 +479,16 @@ jobs: dotnet-version: ${{ inputs.dotnet_version }} - name: Publish run: dotnet pack -o . && dotnet nuget push *.nupkg --api-key ${{ secrets.nuget_api_key }} --source https://api.nuget.org/v3/index.json + - id: publish-event + uses: speakeasy-api/sdk-generation-action@v15 + if: always() + with: + github_access_token: ${{ secrets.github_access_token }} + action: publish-event + speakeasy_api_key: ${{ secrets.speakeasy_api_key }} + speakeasy_server_url: ${{ inputs.speakeasy_server_url }} + target_directory: ${{ needs.run-workflow.outputs.csharp_directory }} + registry_name: "nuget" - uses: ravsamhq/notify-slack-action@v2 if: always() && env.SLACK_WEBHOOK_URL != '' with: @@ -487,6 +537,16 @@ jobs: api_token: ${{ secrets.packagist_token }} package_name: ${{ github.repository }} package_base_url: ${{ github.server_url }} + - id: publish-event + uses: speakeasy-api/sdk-generation-action@v15 + if: always() + with: + github_access_token: ${{ secrets.github_access_token }} + action: publish-event + speakeasy_api_key: ${{ secrets.speakeasy_api_key }} + speakeasy_server_url: ${{ inputs.speakeasy_server_url }} + target_directory: ${{ needs.run-workflow.outputs.php_directory }} + registry_name: "packagist" - uses: ravsamhq/notify-slack-action@v2 if: always() && env.SLACK_WEBHOOK_URL != '' with: diff --git a/internal/actions/publishEvent.go b/internal/actions/publishEvent.go index 95c85852..b347d4e4 100644 --- a/internal/actions/publishEvent.go +++ b/internal/actions/publishEvent.go @@ -43,6 +43,18 @@ func PublishEvent() error { switch os.Getenv("INPUT_REGISTRY_NAME") { case "pypi": processingErr = processPyPI(loadedCfg, event, path, version) + case "npm": + processingErr = processNPM(loadedCfg, event, path, version) + case "packagist": + processingErr = processPackagist(loadedCfg, event, path) + case "nuget": + processingErr = processNuget(loadedCfg, event, path, version) + case "gems": + processingErr = processGems(loadedCfg, event, path) + case "sonatype": + processingErr = processSonatype(loadedCfg, event, path) + case "terraform": + processingErr = processTerraform(loadedCfg, event, path, version) } if processingErr != nil { @@ -56,15 +68,18 @@ func PublishEvent() error { } func processPyPI(cfg *config.Config, event *shared.CliEvent, path string, version string) error { + lang := "python" if cfg.Config == nil { - return fmt.Errorf("empty config for python language target in directory %s", path) + return fmt.Errorf("empty config for %s language target in directory %s", lang, path) } - langCfg, ok := cfg.Config.Languages["python"] + langCfg, ok := cfg.Config.Languages[lang] if !ok { - return fmt.Errorf("no python config in directory %s", path) + return fmt.Errorf("no %s config in directory %s", lang, path) } + event.GenerateTarget = &lang + var packageName string if name, ok := langCfg.Cfg["packageName"]; ok { if strName, ok := name.(string); ok { @@ -82,7 +97,209 @@ func processPyPI(cfg *config.Config, event *shared.CliEvent, path string, versio } return nil +} + +func processNPM(cfg *config.Config, event *shared.CliEvent, path string, version string) error { + lang := "typescript" + if cfg.Config == nil { + return fmt.Errorf("empty config for %s language target in directory %s", lang, path) + } + + langCfg, ok := cfg.Config.Languages[lang] + if !ok { + return fmt.Errorf("no %s config in directory %s", lang, path) + } + + event.GenerateTarget = &lang + + var packageName string + if name, ok := langCfg.Cfg["packageName"]; ok { + if strName, ok := name.(string); ok { + packageName = strName + } + } + + if packageName != "" { + event.PublishPackageName = &packageName + } + + if packageName != "" && version != "" { + publishURL := fmt.Sprintf("https://www.npmjs.com/package/%s/v/%s", packageName, version) + event.PublishPackageURL = &publishURL + } + + return nil +} + +func processPackagist(cfg *config.Config, event *shared.CliEvent, path string) error { + lang := "php" + if cfg.Config == nil { + return fmt.Errorf("empty config for %s language target in directory %s", lang, path) + } + + langCfg, ok := cfg.Config.Languages[lang] + if !ok { + return fmt.Errorf("no %s config in directory %s", lang, path) + } + + event.GenerateTarget = &lang + + var packageName string + if name, ok := langCfg.Cfg["packageName"]; ok { + if strName, ok := name.(string); ok { + packageName = strName + } + } + + if packageName != "" { + event.PublishPackageName = &packageName + } + + if packageName != "" { + publishURL := fmt.Sprintf("https://packagist.org/packages/%s", packageName) + event.PublishPackageURL = &publishURL + } + + return nil +} + +func processNuget(cfg *config.Config, event *shared.CliEvent, path string, version string) error { + lang := "csharp" + if cfg.Config == nil { + return fmt.Errorf("empty config for %s language target in directory %s", lang, path) + } + + langCfg, ok := cfg.Config.Languages[lang] + if !ok { + return fmt.Errorf("no %s config in directory %s", lang, path) + } + + event.GenerateTarget = &lang + + var packageName string + if name, ok := langCfg.Cfg["packageName"]; ok { + if strName, ok := name.(string); ok { + packageName = strName + } + } + + if packageName != "" { + event.PublishPackageName = &packageName + } + + if packageName != "" && version != "" { + publishURL := fmt.Sprintf("https://www.nuget.org/packages/%s/%s", packageName, version) + event.PublishPackageURL = &publishURL + } + + return nil +} + +func processGems(cfg *config.Config, event *shared.CliEvent, path string) error { + lang := "ruby" + if cfg.Config == nil { + return fmt.Errorf("empty config for %s language target in directory %s", lang, path) + } + + langCfg, ok := cfg.Config.Languages[lang] + if !ok { + return fmt.Errorf("no %s config in directory %s", lang, path) + } + + event.GenerateTarget = &lang + + var packageName string + if name, ok := langCfg.Cfg["packageName"]; ok { + if strName, ok := name.(string); ok { + packageName = strName + } + } + + if packageName != "" { + event.PublishPackageName = &packageName + } + + if packageName != "" { + publishURL := fmt.Sprintf("https://rubygems.org/gems/%s", packageName) + event.PublishPackageURL = &publishURL + } + + return nil +} + +func processSonatype(cfg *config.Config, event *shared.CliEvent, path string) error { + lang := "java" + if cfg.Config == nil { + return fmt.Errorf("empty config for %s language target in directory %s", lang, path) + } + + langCfg, ok := cfg.Config.Languages[lang] + if !ok { + return fmt.Errorf("no %s config in directory %s", lang, path) + } + + event.GenerateTarget = &lang + + var groupID string + if name, ok := langCfg.Cfg["groupID"]; ok { + if strName, ok := name.(string); ok { + groupID = strName + } + } + + var artifactID string + if name, ok := langCfg.Cfg["artifactID"]; ok { + if strName, ok := name.(string); ok { + artifactID = strName + } + } + + // TODO: Figure out how to better represent java published package and the publish URL + if groupID != "" && artifactID != "" { + combinedPackage := fmt.Sprintf("%s:%s", groupID, artifactID) + event.PublishPackageName = &combinedPackage + } + + return nil +} +func processTerraform(cfg *config.Config, event *shared.CliEvent, path string, version string) error { + lang := "terraform" + if cfg.Config == nil { + return fmt.Errorf("empty config for %s language target in directory %s", lang, path) + } + + langCfg, ok := cfg.Config.Languages[lang] + if !ok { + return fmt.Errorf("no %s config in directory %s", lang, path) + } + + event.GenerateTarget = &lang + + var packageName string + if name, ok := langCfg.Cfg["packageName"]; ok { + if strName, ok := name.(string); ok { + packageName = strName + } + } + + var author string + if name, ok := langCfg.Cfg["author"]; ok { + if strName, ok := name.(string); ok { + author = strName + } + } + + if packageName != "" { + event.PublishPackageName = &packageName + } + + if packageName != "" && author != "" && version != "" { + publishURL := fmt.Sprintf("https://registry.terraform.io/providers/%s/%s/%s", author, packageName, version) + event.PublishPackageURL = &publishURL + } + + return nil } func processLockFile(lockFile config.LockFile, event *shared.CliEvent) string {