Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Create different release channels: public, private, and standalon
Browse files Browse the repository at this point in the history
  • Loading branch information
hozan23 committed Sep 25, 2023
1 parent 3441d6c commit 033af9c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 24 deletions.
83 changes: 59 additions & 24 deletions cmd/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ const (
ReleaseChannelExp = "experimental"
)

type ReleaseStatus string

const (
PublicRelease ReleaseStatus = "public"
PrivateRelease ReleaseStatus = "private"
StandaloneRelease ReleaseStatus = "standalone"
)

func newCmdRelease() *cobra.Command {
cmd := &cobra.Command{
Use: "release [flags]",
Expand All @@ -47,15 +55,27 @@ func newCmdRelease() *cobra.Command {
}

var revisionID string
var releaseStatus ReleaseStatus

projectDir, _ := cmd.Flags().GetString("dir")
projectID, _ := cmd.Flags().GetString("id")
releaseNotes, _ := cmd.Flags().GetString("notes")
revisionTagName, _ := cmd.Flags().GetString("rid")
useLatestRevision, _ := cmd.Flags().GetBool("confirm")
listedRelease, _ := cmd.Flags().GetBool("listed")
publicRelease, _ := cmd.Flags().GetBool("public")
privateRelease, _ := cmd.Flags().GetBool("private")
standaloneRelease, _ := cmd.Flags().GetBool("standalone")
releaseVersion, _ := cmd.Flags().GetString("version")

switch {
case publicRelease && !privateRelease:
releaseStatus = PublicRelease
case standaloneRelease:
releaseStatus = StandaloneRelease
default:
releaseStatus = PrivateRelease
}

if !cmd.Flags().Changed("id") {
projectMeta, err := runtime.GetProjectMeta(projectDir)
if err != nil {
Expand All @@ -75,7 +95,7 @@ func newCmdRelease() *cobra.Command {
// check there are no previous releases for this project
if latestRelease == nil && utils.IsOutputInteractive() {
if !cmd.Flags().Changed("confirm") {
continueReleasing, err := confirmReleasing(listedRelease)
continueReleasing, err := confirmReleasing(publicRelease)
if err != nil {
return err
}
Expand Down Expand Up @@ -124,10 +144,14 @@ func newCmdRelease() *cobra.Command {
revisionID = revision.ID
}

utils.Logger.Printf(getCreatingReleaseMsg(listedRelease, useLatestRevision))
utils.Logger.Printf(
getCreatingReleaseMsg(
releaseStatus,
useLatestRevision,
))

err = release(projectDir, projectID, revisionID, releaseVersion,
listedRelease, releaseNotes, discoveryData)
releaseStatus, releaseNotes, discoveryData)
if err != nil {
return err
}
Expand All @@ -140,7 +164,9 @@ func newCmdRelease() *cobra.Command {
cmd.Flags().StringP("id", "i", "", "project id of an existing project")
cmd.Flags().String("rid", "", "revision id for release")
cmd.Flags().StringP("version", "v", "", "version for the release")
cmd.Flags().Bool("listed", false, "listed on discovery")
cmd.Flags().Bool("public", false, "public release: listed on discovery")
cmd.Flags().Bool("standalone", false, "standalone release")
cmd.Flags().Bool("private", false, "private release")
cmd.Flags().Bool("confirm", false, "confirm to use latest revision")
cmd.Flags().StringP("notes", "n", "", "release notes")

Expand All @@ -149,11 +175,11 @@ func newCmdRelease() *cobra.Command {
return cmd
}

func confirmReleasing(listedRelease bool) (bool, error) {
func confirmReleasing(publicRelease bool) (bool, error) {
var confirmMsg string

if listedRelease {
utils.Logger.Println("Creating a listed release makes your app available on Deta Discovery for anyone to install and use.")
if publicRelease {
utils.Logger.Println("Creating a public release makes your app available on Deta Discovery for anyone to install and use.")
confirmMsg = "Are you sure you want to release this app publicly on Discovery? (y/n)"
} else {
utils.Logger.Println("Releasing makes your app available via a unique link for others to install and use.")
Expand Down Expand Up @@ -379,15 +405,27 @@ func selectRevision(projectID string, useLatestRevision bool) (*api.Revision, er
return revisionMap[tag], nil
}

func release(projectDir string, projectID string, revisionID string, releaseVersion string, listedRelease bool, releaseNotes string, discoveryData *shared.DiscoveryData) (err error) {
cr, err := utils.Client.CreateRelease(&api.CreateReleaseRequest{
RevisionID: revisionID,
AppID: projectID,
Version: releaseVersion,
ReleaseNotes: releaseNotes,
DiscoveryList: listedRelease,
Channel: ReleaseChannelExp, // always experimental release for now
})
func release(projectDir string, projectID string, revisionID string,
releaseVersion string, releaseStatus ReleaseStatus,
releaseNotes string, discoveryData *shared.DiscoveryData) (err error) {

req := &api.CreateReleaseRequest{
RevisionID: revisionID,
AppID: projectID,
Version: releaseVersion,
ReleaseNotes: releaseNotes,
Channel: ReleaseChannelExp, // always experimental release for now
}

switch releaseStatus {
case PublicRelease:
req.DiscoveryList = true
case StandaloneRelease:
req.Standalone = true
}

cr, err := utils.Client.CreateRelease(req)

if err != nil {
if errors.Is(err, auth.ErrNoAccessTokenFound) {
utils.Logger.Println(utils.LoginInfo())
Expand Down Expand Up @@ -439,7 +477,7 @@ func release(projectDir string, projectID string, revisionID string, releaseVers
utils.Logger.Println(emoji.Rocket, "Lift off -- successfully created a new release!")
utils.Logger.Println(emoji.Earth, "Your release is available globally on 5 Deta Edges")
utils.Logger.Println(emoji.PartyFace, "Anyone can install their own copy of your app.")
if listedRelease {
if releaseStatus == PublicRelease {
utils.Logger.Println(emoji.CrystalBall, "Listed on Discovery for others to find!")
}

Expand All @@ -454,14 +492,11 @@ func release(projectDir string, projectID string, revisionID string, releaseVers
return nil
}

func getCreatingReleaseMsg(listed bool, latest bool) string {
var listedInfo string
func getCreatingReleaseMsg(releaseStatus ReleaseStatus, latest bool) string {
var latestInfo string
if listed {
listedInfo = " listed"
}

if latest {
latestInfo = " with the latest revision"
}
return fmt.Sprintf("\n%s Creating a%s release%s ...\n\n", emoji.Package, listedInfo, latestInfo)
return fmt.Sprintf("\n%s Creating a %s release%s ...\n\n", emoji.Package, releaseStatus, latestInfo)
}
1 change: 1 addition & 0 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ type CreateReleaseRequest struct {
Description string `json:"description"`
Channel string `json:"channel"`
DiscoveryList bool `json:"discovery_list"`
Standalone bool `json:"standalone"`
}

type CreateReleaseResponse struct {
Expand Down

0 comments on commit 033af9c

Please sign in to comment.