diff --git a/.github/workflows/sdk-publish.yaml b/.github/workflows/sdk-publish.yaml index d5512f3c..3590cf14 100644 --- a/.github/workflows/sdk-publish.yaml +++ b/.github/workflows/sdk-publish.yaml @@ -185,7 +185,7 @@ jobs: NODE_AUTH_TOKEN: ${{ secrets.npm_token }} run: npm publish --access public - id: publish-event - uses: speakeasy-api/sdk-generation-action@v15 + uses: speakeasy-api/sdk-generation-action@v15.11.0 if: always() with: github_access_token: ${{ secrets.github_access_token }} diff --git a/action.yml b/action.yml index f1069d8b..b8278a95 100644 --- a/action.yml +++ b/action.yml @@ -147,7 +147,7 @@ outputs: description: "The directory the SDK target was generated to" runs: using: "docker" - image: "docker://ghcr.io/speakeasy-api/sdk-generation-action:v15" + image: "docker://ghcr.io/speakeasy-api/sdk-generation-action:v15.11.0" env: SPEAKEASY_API_KEY: ${{ inputs.speakeasy_api_key }} SPEAKEASY_SERVER_URL: ${{ inputs.speakeasy_server_url }} diff --git a/internal/actions/publishEvent.go b/internal/actions/publishEvent.go index edf52f2d..324f064a 100644 --- a/internal/actions/publishEvent.go +++ b/internal/actions/publishEvent.go @@ -14,7 +14,8 @@ import ( ) func PublishEvent() error { - if _, err := initAction(); err != nil { + g, err := initAction() + if err != nil { return err } @@ -39,6 +40,12 @@ func PublishEvent() error { version := processLockFile(*loadedCfg.LockFile, event) + if !strings.Contains(strings.ToLower(os.Getenv("GH_ACTION_RESULT")), "success") { + if err = g.SetReleaseToPublished(version); err != nil { + fmt.Println("Failed to set release to published %w", err) + } + } + var processingErr error switch os.Getenv("INPUT_REGISTRY_NAME") { case "pypi": diff --git a/internal/git/releases.go b/internal/git/releases.go index 4180d623..b2c4b0fc 100644 --- a/internal/git/releases.go +++ b/internal/git/releases.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "github.com/google/go-github/v54/github" "github.com/speakeasy-api/sdk-generation-action/internal/environment" @@ -16,6 +17,31 @@ import ( //go:embed goreleaser.yml var tfGoReleaserConfig string +func (g *Git) SetReleaseToPublished(version string) error { + if g.repo == nil { + return fmt.Errorf("repo not cloned") + } + tag := "v" + version + + release, _, err := g.client.Repositories.GetReleaseByTag(context.Background(), os.Getenv("GITHUB_REPOSITORY_OWNER"), getRepo(), tag) + if err != nil { + return fmt.Errorf("failed to get release for tag %s: %w", tag, err) + } + + if release != nil && release.ID != nil { + if release.Body != nil && !strings.Contains(*release.Body, "Publishing Completed") { + body := *release.Body + "\n\nPublishing Completed" + release.Body = &body + } + + if _, _, err = g.client.Repositories.EditRelease(context.Background(), os.Getenv("GITHUB_REPOSITORY_OWNER"), getRepo(), *release.ID, release); err != nil { + return fmt.Errorf("failed to add to release body for tag %s: %w", tag, err) + } + } + + return nil +} + func (g *Git) CreateRelease(releaseInfo releases.ReleasesInfo, outputs map[string]string) error { if g.repo == nil { return fmt.Errorf("repo not cloned") @@ -70,12 +96,14 @@ func (g *Git) CreateRelease(releaseInfo releases.ReleasesInfo, outputs map[strin }) if err != nil { if release, _, err := g.client.Repositories.GetReleaseByTag(context.Background(), os.Getenv("GITHUB_REPOSITORY_OWNER"), getRepo(), *tagName); err == nil && release != nil { - fmt.Println(fmt.Sprintf("a github release with tag %s already existing ... skipping publishing", *tagName)) - fmt.Println(fmt.Sprintf("to publish this version again delete the github tag and release")) - if _, ok := outputs[fmt.Sprintf("publish_%s", lang)]; ok { - outputs[fmt.Sprintf("publish_%s", lang)] = "false" + if release.Body != nil && strings.Contains(*release.Body, "Publishing Completed") { + fmt.Println(fmt.Sprintf("a github release with tag %s already existing ... skipping publishing", *tagName)) + fmt.Println(fmt.Sprintf("to publish this version again delete the github tag and release")) + if _, ok := outputs[fmt.Sprintf("publish_%s", lang)]; ok { + outputs[fmt.Sprintf("publish_%s", lang)] = "false" + } } - + // TODO: Consider deleting and recreating the release if we are moving forward with publishing return nil }